From 3a696defc8dcdae1e25b80be993d6376d2a0d007 Mon Sep 17 00:00:00 2001 From: "ksa (Open ERP)" Date: Thu, 11 Nov 2010 18:11:24 +0530 Subject: [PATCH] [FIX]:lp-504353 conversion of UOM with different categories bzr revid: ksa@tinyerp.co.in-20101111124124-w9ua73s06mxp0ld3 --- addons/product/product.py | 11 ++++++++--- addons/stock/product.py | 11 ++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/addons/product/product.py b/addons/product/product.py index b43f40b1cbc..5e3834b6f56 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -24,7 +24,7 @@ import decimal_precision as dp import math from _common import rounding -import re +import re from tools.translate import _ def is_pair(x): @@ -106,9 +106,14 @@ class product_uom(osv.osv): from_unit, to_unit = uoms[-1], uoms[0] return self._compute_qty_obj(cr, uid, from_unit, qty, to_unit) - def _compute_qty_obj(self, cr, uid, from_unit, qty, to_unit, context={}): + def _compute_qty_obj(self, cr, uid, from_unit, qty, to_unit, context=None): + if context is None: + context = {} if from_unit.category_id.id <> to_unit.category_id.id: - return qty + if context.get('raise-exception', True): + raise osv.except_osv(_('Error !'), _('Conversion from Product UoM m to Default UoM PCE is not possible as they both belong to different Category!.')) + else: + return qty amount = qty / from_unit.factor if to_unit: amount = rounding(amount * to_unit.factor, to_unit.rounding) diff --git a/addons/stock/product.py b/addons/stock/product.py index ddb582f4a3c..67c6d7c8448 100644 --- a/addons/stock/product.py +++ b/addons/stock/product.py @@ -241,12 +241,12 @@ class product_product(osv.osv): where.append(tuple([to_date])) elif from_date: date_str = "date>=%s" - date_values = [from_date] + date_values = [from_date] elif to_date: date_str = "date<=%s" date_values = [to_date] - + # TODO: perhaps merge in one query. if date_values: where.append(tuple(date_values)) @@ -282,13 +282,14 @@ class product_product(osv.osv): uoms = uom_obj.browse(cr, uid, list(set(uoms)), context=context) for o in uoms: uoms_o[o.id] = o + ctx = {'raise-exception': False} #TOCHECK: before change uom of product, stock move line are in old uom. for amount, prod_id, prod_uom in results: amount = uom_obj._compute_qty_obj(cr, uid, uoms_o[prod_uom], amount, - uoms_o[context.get('uom', False) or product2uom[prod_id]]) + uoms_o[context.get('uom', False) or product2uom[prod_id]], context=ctx) res[prod_id] += amount for amount, prod_id, prod_uom in results2: amount = uom_obj._compute_qty_obj(cr, uid, uoms_o[prod_uom], amount, - uoms_o[context.get('uom', False) or product2uom[prod_id]]) + uoms_o[context.get('uom', False) or product2uom[prod_id]], context=ctx) res[prod_id] -= amount return res @@ -328,7 +329,7 @@ class product_product(osv.osv): 'track_outgoing': fields.boolean('Track Outgoing Lots', help="Forces to specify a Production Lot for all moves containing this product and going to a Customer Location"), 'location_id': fields.dummy(string='Stock Location', relation='stock.location', type='many2one'), 'valuation':fields.selection([('manual_periodic', 'Periodical (manual)'), - ('real_time','Real Time (automated)'),], 'Inventory Valuation', + ('real_time','Real Time (automated)'),], 'Inventory Valuation', help="If real-time valuation is enabled for a product, the system will automatically write journal entries corresponding to stock moves." \ "The inventory variation account set on the product category will represent the current inventory value, and the stock input and stock output account will hold the counterpart moves for incoming and outgoing products." , required=True),