[IMP] purchase: simplify a bit method onchange_product_id
bzr revid: rco@openerp.com-20120124123104-l1tgpcnnthyrsn9k
This commit is contained in:
parent
cdabe44260
commit
f634d05b7d
|
@ -715,13 +715,12 @@ class purchase_order_line(osv.osv):
|
||||||
"""
|
"""
|
||||||
onchange handler of product_id.
|
onchange handler of product_id.
|
||||||
"""
|
"""
|
||||||
res = {}
|
|
||||||
if context is None:
|
if context is None:
|
||||||
context = {}
|
context = {}
|
||||||
|
|
||||||
res_value = {'price_unit': price_unit or 0.0, 'name': name or '', 'notes': notes or'', 'product_uom' : uom_id or False}
|
res = {'value': {'price_unit': price_unit or 0.0, 'name': name or '', 'notes': notes or '', 'product_uom' : uom_id or False}}
|
||||||
if not product_id:
|
if not product_id:
|
||||||
return {'value': res_value}
|
return res
|
||||||
|
|
||||||
product_product = self.pool.get('product.product')
|
product_product = self.pool.get('product.product')
|
||||||
product_uom = self.pool.get('product.uom')
|
product_uom = self.pool.get('product.uom')
|
||||||
|
@ -741,11 +740,10 @@ class purchase_order_line(osv.osv):
|
||||||
lang = res_partner.browse(cr, uid, partner_id).lang
|
lang = res_partner.browse(cr, uid, partner_id).lang
|
||||||
context_partner = {'lang': lang, 'partner_id': partner_id}
|
context_partner = {'lang': lang, 'partner_id': partner_id}
|
||||||
product = product_product.browse(cr, uid, product_id, context=context_partner)
|
product = product_product.browse(cr, uid, product_id, context=context_partner)
|
||||||
res_value.update({'name': product.name, 'notes': notes or product.description_purchase})
|
res['value'].update({'name': product.name, 'notes': notes or product.description_purchase})
|
||||||
|
|
||||||
# - set a domain on product_uom
|
# - set a domain on product_uom
|
||||||
domain = {'product_uom':[('category_id','=',product.uom_id.category_id.id)]}
|
res['domain'] = {'product_uom': [('category_id','=',product.uom_id.category_id.id)]}
|
||||||
res.update({'domain': domain})
|
|
||||||
|
|
||||||
# - check that uom and product uom belong to the same category
|
# - check that uom and product uom belong to the same category
|
||||||
product_uom_po_id = product.uom_po_id.id
|
product_uom_po_id = product.uom_po_id.id
|
||||||
|
@ -753,10 +751,10 @@ class purchase_order_line(osv.osv):
|
||||||
uom_id = product_uom_po_id
|
uom_id = product_uom_po_id
|
||||||
|
|
||||||
if product.uom_id.category_id.id != product_uom.browse(cr, uid, uom_id, context=context).category_id.id:
|
if product.uom_id.category_id.id != product_uom.browse(cr, uid, uom_id, context=context).category_id.id:
|
||||||
res.update({'warning': {'title': _('Warning'), 'message': _('Selected UOM does not have same category of default UOM')}})
|
res['warning'] = {'title': _('Warning'), 'message': _('Selected UOM does not belong to the same category as the product UOM')}
|
||||||
uom_id = product_uom_po_id
|
uom_id = product_uom_po_id
|
||||||
|
|
||||||
res_value.update({'product_uom': uom_id})
|
res['value'].update({'product_uom': uom_id})
|
||||||
|
|
||||||
# - determine product_qty and date_planned based on seller info
|
# - determine product_qty and date_planned based on seller info
|
||||||
if not date_order:
|
if not date_order:
|
||||||
|
@ -768,29 +766,24 @@ class purchase_order_line(osv.osv):
|
||||||
for supplierinfo in product_supplierinfo.browse(cr, uid, supplierinfo_ids, context=context):
|
for supplierinfo in product_supplierinfo.browse(cr, uid, supplierinfo_ids, context=context):
|
||||||
seller_delay = supplierinfo.delay
|
seller_delay = supplierinfo.delay
|
||||||
if supplierinfo.product_uom.id != uom_id:
|
if supplierinfo.product_uom.id != uom_id:
|
||||||
res.update({'warning': {'title': _('Warning'), 'message': _('The selected supplier only sells this product by %s') % supplierinfo.product_uom.name }})
|
res['warning'] = {'title': _('Warning'), 'message': _('The selected supplier only sells this product by %s') % supplierinfo.product_uom.name }
|
||||||
min_qty = product_uom._compute_qty(cr, uid, supplierinfo.product_uom.id, supplierinfo.min_qty, to_uom_id=uom_id)
|
min_qty = product_uom._compute_qty(cr, uid, supplierinfo.product_uom.id, supplierinfo.min_qty, to_uom_id=uom_id)
|
||||||
if qty < min_qty: # If the supplier quantity is greater than entered from user, set minimal.
|
if qty < min_qty: # If the supplier quantity is greater than entered from user, set minimal.
|
||||||
res.update({'warning': {'title': _('Warning'), 'message': _('The selected supplier has a minimal quantity set to %s %s, you should not purchase less.') % (supplierinfo.min_qty, supplierinfo.product_uom.name)}})
|
res['warning'] = {'title': _('Warning'), 'message': _('The selected supplier has a minimal quantity set to %s %s, you should not purchase less.') % (supplierinfo.min_qty, supplierinfo.product_uom.name)}
|
||||||
qty = min_qty
|
qty = min_qty
|
||||||
|
|
||||||
dt = (datetime.strptime(date_order, '%Y-%m-%d') + relativedelta(days=int(seller_delay) or 0.0)).strftime('%Y-%m-%d %H:%M:%S')
|
dt = (datetime.strptime(date_order, '%Y-%m-%d') + relativedelta(days=int(seller_delay) or 0.0)).strftime('%Y-%m-%d %H:%M:%S')
|
||||||
res_value.update({'date_planned': date_planned or dt, 'product_qty': qty})
|
res['value'].update({'date_planned': date_planned or dt, 'product_qty': qty})
|
||||||
|
|
||||||
# - determine price_unit and taxes_id
|
# - determine price_unit and taxes_id
|
||||||
price = product_pricelist.price_get(cr, uid, [pricelist_id],
|
price = product_pricelist.price_get(cr, uid, [pricelist_id],
|
||||||
product.id, qty or 1.0, partner_id, {
|
product.id, qty or 1.0, partner_id, {'uom': uom_id, 'date': date_order})[pricelist_id]
|
||||||
'uom': uom_id,
|
|
||||||
'date': date_order,
|
|
||||||
})[pricelist_id]
|
|
||||||
|
|
||||||
taxes = account_tax.browse(cr, uid, map(lambda x: x.id, product.supplier_taxes_id))
|
taxes = account_tax.browse(cr, uid, map(lambda x: x.id, product.supplier_taxes_id))
|
||||||
fpos = fiscal_position_id and account_fiscal_position.browse(cr, uid, fiscal_position_id, context=context) or False
|
fpos = fiscal_position_id and account_fiscal_position.browse(cr, uid, fiscal_position_id, context=context) or False
|
||||||
taxes_ids = account_fiscal_position.map_tax(cr, uid, fpos, taxes)
|
taxes_ids = account_fiscal_position.map_tax(cr, uid, fpos, taxes)
|
||||||
res_value.update({'price_unit': price, 'taxes_id': taxes_ids})
|
res['value'].update({'price_unit': price, 'taxes_id': taxes_ids})
|
||||||
|
|
||||||
|
|
||||||
res.update({'value': res_value})
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
product_id_change = onchange_product_id
|
product_id_change = onchange_product_id
|
||||||
|
|
Loading…
Reference in New Issue