[IMP] stock: onchange on inv. line serial number
On Inventory Adjustment lines view, when you set serial number for a tracked product, its quantity is automatically set on 1. Task #2025397 closes odoo/odoo#34301 Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
This commit is contained in:
@@ -352,6 +352,7 @@ class InventoryLine(models.Model):
|
||||
|
||||
@api.onchange('product_id', 'location_id', 'product_uom_id', 'prod_lot_id', 'partner_id', 'package_id')
|
||||
def _onchange_quantity_context(self):
|
||||
product_qty = False
|
||||
if self.product_id:
|
||||
self.product_uom_id = self.product_id.uom_id
|
||||
if self.product_id and self.location_id and self.product_id.uom_id.category_id == self.product_uom_id.category_id: # TDE FIXME: last part added because crash
|
||||
@@ -365,9 +366,18 @@ class InventoryLine(models.Model):
|
||||
)
|
||||
else:
|
||||
theoretical_qty = 0
|
||||
# We update `product_qty` only if it equals to `theoretical_qty` to
|
||||
# avoid to reset quantity when user manually set it.
|
||||
if self.product_qty == self.theoretical_qty:
|
||||
# Sanity check on the lot.
|
||||
if self.prod_lot_id:
|
||||
if self.product_id.tracking == 'none' or self.product_id != self.prod_lot_id.product_id:
|
||||
self.prod_lot_id = False
|
||||
|
||||
if self.prod_lot_id and self.product_id.tracking == 'serial':
|
||||
# We force `product_qty` to 1 for SN tracked product because it's
|
||||
# the only relevant value aside 0 for this kind of product.
|
||||
self.product_qty = 1
|
||||
elif self.product_id and float_compare(self.product_qty, self.theoretical_qty, precision_rounding=self.product_uom_id.rounding) == 0:
|
||||
# We update `product_qty` only if it equals to `theoretical_qty` to
|
||||
# avoid to reset quantity when user manually set it.
|
||||
self.product_qty = theoretical_qty
|
||||
self.theoretical_qty = theoretical_qty
|
||||
|
||||
|
||||
Reference in New Issue
Block a user