[FIX] stock: `product_qty` field is not recomputed at record creation.
In the new API, 'product_qty' is correctely recomputed at record creation. opw:629650
This commit is contained in:
parent
bff042d652
commit
a1da6c2132
|
@ -24,6 +24,7 @@ from dateutil import relativedelta
|
|||
import json
|
||||
import time
|
||||
|
||||
from openerp import models, fields as new_fields, api
|
||||
from openerp.osv import fields, osv
|
||||
from openerp.tools.float_utils import float_compare, float_round
|
||||
from openerp.tools.translate import _
|
||||
|
@ -1590,7 +1591,7 @@ class stock_production_lot(osv.osv):
|
|||
# Move
|
||||
# ----------------------------------------------------
|
||||
|
||||
class stock_move(osv.osv):
|
||||
class stock_move(models.Model):
|
||||
_name = "stock.move"
|
||||
_description = "Stock Move"
|
||||
_order = 'date_expected desc, id'
|
||||
|
@ -1611,12 +1612,11 @@ class stock_move(osv.osv):
|
|||
res.append((line.id, name))
|
||||
return res
|
||||
|
||||
def _quantity_normalize(self, cr, uid, ids, name, args, context=None):
|
||||
@api.depends('product_id', 'product_uom_qty', 'product_uom', 'product_id.uom_id')
|
||||
def _quantity_normalize(self):
|
||||
uom_obj = self.pool.get('product.uom')
|
||||
res = {}
|
||||
for m in self.browse(cr, uid, ids, context=context):
|
||||
res[m.id] = uom_obj._compute_qty_obj(cr, uid, m.product_uom, m.product_uom_qty, m.product_id.uom_id, context=context)
|
||||
return res
|
||||
for m in self:
|
||||
m.product_qty = uom_obj._compute_qty_obj(self.env.cr, self.env.uid, m.product_uom, m.product_uom_qty, m.product_id.uom_id, context=self.env.context)
|
||||
|
||||
def _get_remaining_qty(self, cr, uid, ids, field_name, args, context=None):
|
||||
uom_obj = self.pool.get('product.uom')
|
||||
|
@ -1700,11 +1700,6 @@ class stock_move(osv.osv):
|
|||
res += [x.id for x in picking.move_lines]
|
||||
return res
|
||||
|
||||
def _get_moves_from_prod(self, cr, uid, ids, context=None):
|
||||
if ids:
|
||||
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
|
||||
|
@ -1713,6 +1708,9 @@ class stock_move(osv.osv):
|
|||
"""
|
||||
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`.'))
|
||||
|
||||
product_qty = new_fields.Float(compute='_quantity_normalize', inverse='_set_product_qty', digits=0, store=True, string='Quantity',
|
||||
help='Quantity in the default UoM of the product')
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('Description', required=True, select=True),
|
||||
'priority': fields.selection(procurement.PROCUREMENT_PRIORITIES, 'Priority'),
|
||||
|
@ -1720,8 +1718,6 @@ 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, fnct_inv=_set_product_qty, type='float', digits=0, store=True, string='Quantity',
|
||||
help='Quantity in the default UoM of the product'),
|
||||
'product_uom_qty': fields.float('Quantity', digits_compute=dp.get_precision('Product Unit of Measure'),
|
||||
required=True, states={'done': [('readonly', True)]},
|
||||
help="This is the quantity of products from an inventory "
|
||||
|
|
Loading…
Reference in New Issue