[IMP] improve preceding fix a little + use real context guard
bzr revid: xal@openerp.com-20121002161436-kyhuh9l8jdlbduzm
This commit is contained in:
@@ -703,9 +703,11 @@ class purchase_order_line(osv.osv):
|
||||
"""
|
||||
onchange handler of product_uom.
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
context = dict(context, uom_change=True)
|
||||
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}}
|
||||
context.update(uom_change=True)
|
||||
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)
|
||||
@@ -763,15 +765,13 @@ class purchase_order_line(osv.osv):
|
||||
|
||||
# - check that uom and product uom belong to the same category
|
||||
product_uom_po_id = product.uom_po_id.id
|
||||
if not uom_id:
|
||||
if not uom_id or not context.get('uom_change'):
|
||||
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
|
||||
|
||||
+12
-11
@@ -1189,7 +1189,8 @@ class sale_order_line(osv.osv):
|
||||
def product_id_change(self, cr, uid, ids, pricelist, product, qty=0,
|
||||
uom=False, qty_uos=0, uos=False, name='', partner_id=False,
|
||||
lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False, context=None):
|
||||
context = context or {}
|
||||
if context is None:
|
||||
context = {}
|
||||
lang = lang or context.get('lang',False)
|
||||
if not partner_id:
|
||||
raise osv.except_osv(_('No Customer Defined !'), _('You have to select a customer in the sales form !\nPlease set one customer before choosing a product.'))
|
||||
@@ -1197,7 +1198,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.update(lang=lang, partner_id=partner_id)
|
||||
context = dict(context, 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,10 +1214,13 @@ 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 and context.get('uom_change'):
|
||||
if uom:
|
||||
uom2 = product_uom_obj.browse(cr, uid, uom)
|
||||
if product_obj.uom_id.category_id.id != uom2.category_id.id or not context.get('uom_change',False):
|
||||
uom = False
|
||||
uom2 = False
|
||||
if uos:
|
||||
if product_obj.uos_id:
|
||||
uos2 = product_uom_obj.browse(cr, uid, uos)
|
||||
@@ -1250,10 +1254,6 @@ 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,9 +1309,10 @@ class sale_order_line(osv.osv):
|
||||
def product_uom_change(self, cursor, user, ids, pricelist, product, qty=0,
|
||||
uom=False, qty_uos=0, uos=False, name='', partner_id=False,
|
||||
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)
|
||||
if context is None:
|
||||
context = {}
|
||||
lang = lang or context.get('lang',False)
|
||||
context = dict(context, 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