[FIX] stock: no uom rounding for DO availability & reservation

Instead of rounding the availability and reversation
of a delivery order line to the current UOM rounding,
we round to the generic Product of measure precision.

This is to have the real availability, even for a unit
of measure that normally cannot be split.

For instance, for a product for which the default
uom is 'Unit(s)', but for a specific delivery order
you deliver 1 'Dozens' of this product,
if you have 6 Units available, it will now display
that 0.500 'Dozens' is available and reserved, which
is what is actually happening.

Before, it displayed that 1 dozens was available, even
if only 6 units were available, on the 12 needed.

opw-643312
This commit is contained in:
Denis Ledoux 2015-08-07 15:17:55 +02:00
parent 5a53d7d8b9
commit 6ebbbdbae9
1 changed files with 5 additions and 2 deletions

View File

@ -1684,12 +1684,14 @@ class stock_move(osv.osv):
settings_obj = self.pool.get('stock.config.settings')
uom_obj = self.pool.get('product.uom')
res = dict.fromkeys(ids, '')
precision = self.pool['decimal.precision'].precision_get(cr, uid, 'Product Unit of Measure')
for move in self.browse(cr, uid, ids, context=context):
if move.state in ('draft', 'done', 'cancel') or move.location_id.usage != 'internal':
res[move.id] = '' # 'not applicable' or 'n/a' could work too
continue
total_available = min(move.product_qty, move.reserved_availability + move.availability)
total_available = uom_obj._compute_qty_obj(cr, uid, move.product_id.uom_id, total_available, move.product_uom, context=context)
total_available = uom_obj._compute_qty_obj(cr, uid, move.product_id.uom_id, total_available, move.product_uom, round=False, context=context)
total_available = float_round(total_available, precision_digits=precision)
info = str(total_available)
#look in the settings if we need to display the UoM name or not
config_ids = settings_obj.search(cr, uid, [], limit=1, order='id DESC', context=context)
@ -1700,7 +1702,8 @@ class stock_move(osv.osv):
if move.reserved_availability:
if move.reserved_availability != total_available:
#some of the available quantity is assigned and some are available but not reserved
reserved_available = uom_obj._compute_qty_obj(cr, uid, move.product_id.uom_id, move.reserved_availability, move.product_uom, context=context)
reserved_available = uom_obj._compute_qty_obj(cr, uid, move.product_id.uom_id, move.reserved_availability, move.product_uom, round=False, context=context)
reserved_available = float_round(reserved_available, precision_digits=precision)
info += _(' (%s reserved)') % str(reserved_available)
else:
#all available quantity is assigned