From f634d05b7d689a16a4625b75344c5c152763ec71 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Tue, 24 Jan 2012 13:31:04 +0100 Subject: [PATCH] [IMP] purchase: simplify a bit method onchange_product_id bzr revid: rco@openerp.com-20120124123104-l1tgpcnnthyrsn9k --- addons/purchase/purchase.py | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index 908720eccd1..e91071a8e3f 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -715,13 +715,12 @@ class purchase_order_line(osv.osv): """ onchange handler of product_id. """ - res = {} if context is None: 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: - return {'value': res_value} + return res product_product = self.pool.get('product.product') 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 context_partner = {'lang': lang, 'partner_id': partner_id} 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 - domain = {'product_uom':[('category_id','=',product.uom_id.category_id.id)]} - res.update({'domain': domain}) + res['domain'] = {'product_uom': [('category_id','=',product.uom_id.category_id.id)]} # - check that uom and product uom belong to the same category 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 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 - res_value.update({'product_uom': uom_id}) + res['value'].update({'product_uom': uom_id}) # - determine product_qty and date_planned based on seller info 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): seller_delay = supplierinfo.delay 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) 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 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 price = product_pricelist.price_get(cr, uid, [pricelist_id], - product.id, qty or 1.0, partner_id, { - 'uom': uom_id, - 'date': date_order, - })[pricelist_id] + product.id, qty or 1.0, partner_id, {'uom': uom_id, 'date': date_order})[pricelist_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 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 product_id_change = onchange_product_id