Compare quantity as absolute value and enforce positive quantities

issue7159
review44041002
This commit is contained in:
Cédric Krier committed 2018-02-28 18:58:09 +01:00
1 parent 82782cdcad
commit b15f58579d
2 files changed
+8 -2

No files matched your search

+6 -2
View File
@@ -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)
+2
View File
@@ -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():