18
18
# You should have received a copy of the GNU Affero General Public License
19
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
##############################################################################
21
########################################################################
22
22
from datetime import datetime
23
23
from dateutil.relativedelta import relativedelta
25
25
from openerp import netsvc
27
from openerp.osv import fields,osv
27
from openerp.osv import fields, osv
28
28
from openerp.tools.translate import _
29
29
import openerp.addons.decimal_precision as dp
31
32
class purchase_requisition_line(osv.Model):
32
33
_inherit = "purchase.requisition.line"
35
36
'name': fields.text('Description', required=True),
36
'account_analytic_id': fields.many2one('account.analytic.account', 'Analytic Account', help='This field is used to assign the selected analytic account to the line of the purchase order'),
37
'account_analytic_id': fields.many2one(
38
'account.analytic.account', 'Analytic Account',
39
help='This field is used to assign the selected'\
40
' analytic account to the line of the purchase order'),
39
def onchange_product_id(self, cr, uid, ids, product_id, \
40
product_uom_id, context=None):
43
def onchange_product_id(self, cr, uid, ids, product_id,
44
product_uom_id, context=None):
41
45
product_obj = self.pool.get('product.product')
42
46
res = {'value': {'name': ''}}
44
product_name = product_obj.name_get(cr, uid, product_id, context=context)
45
dummy, name = product_name and product_name[0] or (False, False)
47
product = product_obj.browse(cr, uid, product_id, context=context)
48
product_name = product_obj.name_get(
49
cr, uid, product_id, context=context)
50
dummy, name = product_name and product_name[0] or (False,
53
product = product_obj.browse(cr, uid, product_id,
48
55
if product.description_purchase:
49
56
name += '\n' + product.description_purchase
50
57
res['value'].update({'name': name})
67
75
purchase_order_line = self.pool.get('purchase.order.line')
68
76
res_partner = self.pool.get('res.partner')
69
77
fiscal_position = self.pool.get('account.fiscal.position')
70
supplier = res_partner.browse(cr, uid, partner_id, context=context)
71
supplier_pricelist = supplier.property_product_pricelist_purchase or False
78
supplier = res_partner.browse(cr, uid, partner_id,
81
supplier.property_product_pricelist_purchase or False
73
83
for requisition in self.browse(cr, uid, ids, context=context):
74
if supplier.id in filter(lambda x: x, [rfq.state <> 'cancel' and rfq.partner_id.id or None for rfq in requisition.purchase_ids]):
75
raise osv.except_osv(_('Warning!'), _('You have already one %s purchase order for this partner, you must cancel this purchase order to create a new quotation.') % rfq.state)
84
if supplier.id in filter(lambda x: x,
85
[rfq.state <> 'cancel' and rfq.partner_id.id or None\
86
for rfq in requisition.purchase_ids]):
88
_('Warning!'), _('You have already one %s purchase'\
89
' order for this partner, you must cancel this'\
90
' purchase order to create a new quotation.') %\
76
92
location_id = requisition.warehouse_id.lot_input_id.id
77
93
purchase_id = purchase_order.create(cr, uid, {
78
'origin': requisition.name,
79
'partner_id': supplier.id,
80
'pricelist_id': supplier_pricelist.id,
81
'location_id': location_id,
82
'company_id': requisition.company_id.id,
83
'fiscal_position': supplier.property_account_position and supplier.property_account_position.id or False,
84
'requisition_id':requisition.id,
85
'notes':requisition.description,
86
'warehouse_id':requisition.warehouse_id.id ,
94
'origin': requisition.name,
95
'partner_id': supplier.id,
96
'pricelist_id': supplier_pricelist.id,
97
'location_id': location_id,
98
'company_id': requisition.company_id.id,
99
'fiscal_position': supplier.property_account_position\
100
and supplier.property_account_position.id or False,
101
'requisition_id': requisition.id,
102
'notes': requisition.description,
103
'warehouse_id': requisition.warehouse_id.id,
88
105
res[requisition.id] = purchase_id
89
106
for line in requisition.line_ids:
90
107
product = line.product_id
91
seller_price, qty, default_uom_po_id, date_planned = self._seller_details(cr, uid, line, supplier, context=context)
108
seller_price, qty, default_uom_po_id, date_planned =\
109
self._seller_details(cr, uid, line, supplier,
92
111
taxes_ids = product.supplier_taxes_id
93
taxes = fiscal_position.map_tax(cr, uid, supplier.property_account_position, taxes_ids)
112
taxes = fiscal_position.map_tax(
113
cr, uid, supplier.property_account_position,
94
115
purchase_order_line.create(cr, uid, {
95
116
'order_id': purchase_id,
117
# start custom change
97
118
#'name': product.partner_ref,
98
119
'name': line.name,
100
121
'product_qty': qty,
101
122
'product_id': product.id,
102
123
'product_uom': default_uom_po_id,
103
124
'price_unit': seller_price,
104
125
'date_planned': date_planned,
105
126
'taxes_id': [(6, 0, taxes)],
106
'account_analytic_id': line.account_analytic_id and line.account_analytic_id.id or False,
127
'account_analytic_id': line.account_analytic_id\
128
and line.account_analytic_id.id or False,
107
129
}, context=context)
131
requisition_user = self.browse(
132
cr, uid, res.keys()[0], context=context).user_id
133
purchase_order_obj = self.pool.get('purchase.order')
134
purchase_order_obj.write(
135
cr, uid, res[res.keys()[0]],
136
{'rfq_user_id': requisition_user.id})
140
class purchase_order(osv.Model):
141
_inherit = "purchase.order"
144
'rfq_user_id': fields.many2one('res.users', 'Requisitor'),