From 4a814282ebdfb779c2aa005fb3f29956cd1f0d23 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Thu, 8 May 2014 12:41:22 +0200 Subject: [PATCH] [REF] stock: raising an error if we try to set the product_qty field on stock.move instead of the product_uom_qty, to detect programming errors and warn that the semantic of this field changed bzr revid: qdp-launchpad@openerp.com-20140508104122-rt8ze9iir8i5q60q --- addons/stock/stock.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 36f34c3ec72..774985ed3ac 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -1581,6 +1581,14 @@ class stock_move(osv.osv): return self.pool.get('stock.move').search(cr, uid, [('product_id', 'in', ids)], context=context) return [] + def _set_product_qty(self, cr, uid, id, field, value, arg, context=None): + """ The meaning of product_qty field changed lately and is now a functional field computing the quantity + in the default product UoM. This code has been added to raise an error if a write is made given a value + for `product_qty`, where the same write should set the `product_uom_qty` field instead, in order to + detect errors. + """ + raise osv.except_osv(_('Programming Error!'), _('The requested operation cannot be processed because of a programming error setting the `product_qty` field instead of the `product_uom_qty`.')) + _columns = { 'name': fields.char('Description', required=True, select=True), 'priority': fields.selection([('0', 'Not urgent'), ('1', 'Urgent')], 'Priority'), @@ -1588,7 +1596,7 @@ class stock_move(osv.osv): 'date': fields.datetime('Date', required=True, select=True, help="Move date: scheduled date until move is done, then date of actual move processing", states={'done': [('readonly', True)]}), 'date_expected': fields.datetime('Expected Date', states={'done': [('readonly', True)]}, required=True, select=True, help="Scheduled date for the processing of this move"), 'product_id': fields.many2one('product.product', 'Product', required=True, select=True, domain=[('type', '<>', 'service')], states={'done': [('readonly', True)]}), - 'product_qty': fields.function(_quantity_normalize, type='float', store={ + 'product_qty': fields.function(_quantity_normalize, fnct_inv=_set_product_qty, _type='float', store={ 'stock.move': (lambda self, cr, uid, ids, ctx: ids, ['product_id', 'product_uom_qty', 'product_uom'], 20), 'product.product': (_get_moves_from_prod, ['uom_id'], 20), }, string='Quantity',