From b15f58579d4e63f309e07f79a6a6a34c67f5b0fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 28 Feb 2018 18:58:09 +0100 Subject: [PATCH] Compare quantity as absolute value and enforce positive quantities issue7159 review44041002 --- product.py | 8 ++++++-- tests/test_purchase.py | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/product.py b/product.py index caea2ee4e7..85ca795f38 100644 --- a/product.py +++ b/product.py @@ -334,7 +334,11 @@ class ProductSupplierPrice( __name__ = 'purchase.product_supplier.price' product_supplier = fields.Many2One('purchase.product_supplier', 'Supplier', required=True, ondelete='CASCADE') - quantity = fields.Float('Quantity', required=True, help='Minimal quantity') + quantity = fields.Float( + "Quantity", + required=True, + domain=[('quantity', '>=', 0)], + help='Minimal quantity') unit_price = fields.Numeric('Unit Price', required=True, digits=price_digits) @@ -367,6 +371,6 @@ class ProductSupplierPrice( Uom = pool.get('product.uom') test_quantity = Uom.compute_qty( self.product_supplier.uom, self.quantity, uom) - if test_quantity > quantity: + if test_quantity > abs(quantity): return False return super(ProductSupplierPrice, self).match(pattern) diff --git a/tests/test_purchase.py b/tests/test_purchase.py index f1efba8820..493897ecd8 100644 --- a/tests/test_purchase.py +++ b/tests/test_purchase.py @@ -101,6 +101,8 @@ class PurchaseTestCase(ModuleTestCase): self.assertEqual(prices, {product.id: Decimal(3000)}) prices = Product.get_purchase_price([product], quantity=3) self.assertEqual(prices, {product.id: Decimal(2500)}) + prices = Product.get_purchase_price([product], quantity=-4) + self.assertEqual(prices, {product.id: Decimal(2500)}) def suite():