[FIX] sale,purchase: fix uom problem when doing product onchange for sale item or purchase items, it did not automatically set the proper UoM while chnaging the product when products UoM are in the same category
bzr revid: rha@tinyerp.com-20120622064459-d4xxyaz6rey8aou0
This commit is contained in:
@@ -705,9 +705,13 @@ class purchase_order_line(osv.osv):
|
||||
"""
|
||||
if not uom_id:
|
||||
return {'value': {'price_unit': price_unit or 0.0, 'name': name or '', 'notes': notes or'', 'product_uom' : uom_id or False}}
|
||||
return self.onchange_product_id(cr, uid, ids, pricelist_id, product_id, qty, uom_id,
|
||||
partner_id, date_order=date_order, fiscal_position_id=fiscal_position_id, date_planned=date_planned,
|
||||
name=name, price_unit=price_unit, notes=notes, context=context)
|
||||
context.update(uom_change=True)
|
||||
res = self.onchange_product_id(cr, uid, ids, pricelist_id, product_id, qty, uom_id,
|
||||
partner_id, date_order=date_order, fiscal_position_id=fiscal_position_id, date_planned=date_planned,
|
||||
name=name, price_unit=price_unit, notes=notes, context=context)
|
||||
if 'product_uom' in res['value']:
|
||||
del res['value']['product_uom']
|
||||
return res
|
||||
|
||||
def _get_date_planned(self, cr, uid, supplier_info, date_order_str, context=None):
|
||||
"""Return the datetime value to use as Schedule Date (``date_planned``) for
|
||||
@@ -764,11 +768,13 @@ class purchase_order_line(osv.osv):
|
||||
product_uom_po_id = product.uom_po_id.id
|
||||
if not uom_id:
|
||||
uom_id = product_uom_po_id
|
||||
|
||||
|
||||
if not context.get('uom_change'):
|
||||
uom_id = product.uom_id.id
|
||||
if product.uom_id.category_id.id != product_uom.browse(cr, uid, uom_id, context=context).category_id.id:
|
||||
res['warning'] = {'title': _('Warning'), 'message': _('Selected UOM does not belong to the same category as the product UOM')}
|
||||
uom_id = product_uom_po_id
|
||||
|
||||
|
||||
res['value'].update({'product_uom': uom_id})
|
||||
|
||||
# - determine product_qty and date_planned based on seller info
|
||||
|
||||
+8
-5
@@ -1197,7 +1197,7 @@ class sale_order_line(osv.osv):
|
||||
product_uom_obj = self.pool.get('product.uom')
|
||||
partner_obj = self.pool.get('res.partner')
|
||||
product_obj = self.pool.get('product.product')
|
||||
context = {'lang': lang, 'partner_id': partner_id}
|
||||
context.update(lang=lang, partner_id=partner_id)
|
||||
if partner_id:
|
||||
lang = partner_obj.browse(cr, uid, partner_id).lang
|
||||
context_partner = {'lang': lang, 'partner_id': partner_id}
|
||||
@@ -1213,12 +1213,10 @@ class sale_order_line(osv.osv):
|
||||
result = res.get('value', {})
|
||||
warning_msgs = res.get('warning') and res['warning']['message'] or ''
|
||||
product_obj = product_obj.browse(cr, uid, product, context=context)
|
||||
|
||||
|
||||
uom2 = False
|
||||
if uom:
|
||||
if uom and context.get('uom_change'):
|
||||
uom2 = product_uom_obj.browse(cr, uid, uom)
|
||||
if product_obj.uom_id.category_id.id != uom2.category_id.id:
|
||||
uom = False
|
||||
if uos:
|
||||
if product_obj.uos_id:
|
||||
uos2 = product_uom_obj.browse(cr, uid, uos)
|
||||
@@ -1252,6 +1250,10 @@ class sale_order_line(osv.osv):
|
||||
[('category_id', '=', product_obj.uom_id.category_id.id)],
|
||||
'product_uos':
|
||||
[('category_id', '=', uos_category_id)]}
|
||||
|
||||
if not context.get('uom_change'):
|
||||
res['value'].update(product_uom=product_obj.uom_id.id)
|
||||
uom = product_obj.uom_id.id
|
||||
|
||||
elif uos and not uom: # only happens if uom is False
|
||||
result['product_uom'] = product_obj.uom_id and product_obj.uom_id.id
|
||||
@@ -1309,6 +1311,7 @@ class sale_order_line(osv.osv):
|
||||
lang=False, update_tax=True, date_order=False, context=None):
|
||||
context = context or {}
|
||||
lang = lang or ('lang' in context and context['lang'])
|
||||
context.update(uom_change=True)
|
||||
res = self.product_id_change(cursor, user, ids, pricelist, product,
|
||||
qty=qty, uom=uom, qty_uos=qty_uos, uos=uos, name=name,
|
||||
partner_id=partner_id, lang=lang, update_tax=update_tax,
|
||||
|
||||
Reference in New Issue
Block a user