diff --git a/stock_no_negative/__manifest__.py b/stock_no_negative/__manifest__.py index 8466227a052..3ad5505d598 100644 --- a/stock_no_negative/__manifest__.py +++ b/stock_no_negative/__manifest__.py @@ -6,7 +6,7 @@ { 'name': 'Stock Disallow Negative', - 'version': '10.0.1.0.2', + 'version': '10.0.1.0.0', 'category': 'Inventory, Logistic, Storage', 'license': 'AGPL-3', 'summary': 'Disallow negative stock levels by default', diff --git a/stock_no_negative/models/stock_quant.py b/stock_no_negative/models/stock_quant.py index 2227080172a..61b416ec7f8 100644 --- a/stock_no_negative/models/stock_quant.py +++ b/stock_no_negative/models/stock_quant.py @@ -5,7 +5,7 @@ from odoo import models, api, _ from odoo.exceptions import ValidationError -from odoo.tools import float_compare +from odoo.tools import config, float_compare class StockQuant(models.Model): @@ -16,9 +16,14 @@ class StockQuant(models.Model): def check_negative_qty(self): p = self.env['decimal.precision'].precision_get( 'Product Unit of Measure') + check_negative_qty = ( + config['test_enable'] and self.env.context.get( + 'test_stock_no_negative')) or ( + 'test_enable' not in config.options) + if not check_negative_qty: + return for quant in self: - if ( - float_compare(quant.qty, 0, precision_digits=p) == -1 and + if (float_compare(quant.qty, 0, precision_digits=p) == -1 and quant.product_id.type == 'product' and not quant.product_id.allow_negative_stock and not quant.product_id.categ_id.allow_negative_stock): diff --git a/stock_no_negative/tests/test_stock_no_negative.py b/stock_no_negative/tests/test_stock_no_negative.py index ee0602f2a74..3d2d676bcd7 100644 --- a/stock_no_negative/tests/test_stock_no_negative.py +++ b/stock_no_negative/tests/test_stock_no_negative.py @@ -70,7 +70,8 @@ def test_check_constrains(self): self.stock_immediate_transfer = self.env['stock.immediate.transfer'].\ create({'pick_id': self.stock_picking.id}) with self.assertRaises(ValidationError): - self.stock_immediate_transfer.process() + self.stock_immediate_transfer.with_context( + test_stock_no_negative=True).process() def test_true_allow_negative_stock(self): """Assert that negative stock levels are allowed when @@ -82,7 +83,8 @@ def test_true_allow_negative_stock(self): self.stock_picking.do_new_transfer() self.stock_immediate_transfer = self.env['stock.immediate.transfer'].\ create({'pick_id': self.stock_picking.id}) - self.stock_immediate_transfer.process() + self.stock_immediate_transfer.with_context( + test_stock_no_negative=True).process() quant = self.env['stock.quant'].search([('product_id', '=', self.product.id), ('location_id', '=',