From 274dd3bf503e1b612179db92e410b336bfaecfb4 Mon Sep 17 00:00:00 2001 From: "Tiffany Chang (tic)" Date: Mon, 26 Oct 2020 12:26:11 +0000 Subject: [PATCH] [IMP] stock: improve SN quant restriction This commit makes it so the quantity of a SN in a location is now restricted between -1 < quantity < 1 (previously it was only quantity < 1). This change provides stronger protection against a duplicated SN (e.g. a quantity of -2 means that the SN was somehow moved from that location twice). This restriction was also relaxed to not include location.usage='inventory' because this could prevent the user from fixing a duplicated SN (since they were prevented from creating a quantity of 2+ in an Inventory Loss location). closes odoo/odoo#59834 Task: 2336455 Related: odoo/upgrade#1839 Related: odoo/enterprise#14667 Signed-off-by: Arnold Moyaux --- addons/stock/models/stock_quant.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/stock/models/stock_quant.py b/addons/stock/models/stock_quant.py index 4b27fff15e1..7b9b5932700 100644 --- a/addons/stock/models/stock_quant.py +++ b/addons/stock/models/stock_quant.py @@ -239,7 +239,8 @@ class StockQuant(models.Model): @api.constrains('quantity') def check_quantity(self): for quant in self: - if float_compare(quant.quantity, 1, precision_rounding=quant.product_uom_id.rounding) > 0 and quant.lot_id and quant.product_id.tracking == 'serial': + if quant.location_id.usage != 'inventory' and quant.lot_id and quant.product_id.tracking == 'serial' \ + and float_compare(abs(quant.quantity), 1, precision_rounding=quant.product_uom_id.rounding) > 0: raise ValidationError(_('The serial number has already been assigned: \n Product: %s, Serial Number: %s') % (quant.product_id.display_name, quant.lot_id.name)) @api.constrains('location_id')