diff --git a/CHANGELOG b/CHANGELOG index ebd6e98bfc..4f9afac0b8 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Make order point's minimal quantity required + Version 5.2.0 - 2019-05-06 * Bug fixes (see mercurial logs for details) diff --git a/order_point.py b/order_point.py index 906454bae1..b6c7f582bc 100644 --- a/order_point.py +++ b/order_point.py @@ -71,11 +71,15 @@ class OrderPoint(ModelSQL, ModelView): 'Type', select=True, required=True) min_quantity = fields.Float('Minimal Quantity', digits=(16, Eval('unit_digits', 2)), + states={ + # required for purchase and production types + 'required': Eval('type') != 'internal', + }, domain=['OR', ('min_quantity', '=', None), ('min_quantity', '<=', Eval('target_quantity', 0)), ], - depends=['unit_digits', 'target_quantity']) + depends=['unit_digits', 'target_quantity', 'type']) target_quantity = fields.Float('Target Quantity', required=True, digits=(16, Eval('unit_digits', 2)), domain=[ diff --git a/tests/scenario_stock_supply_purchase_request.rst b/tests/scenario_stock_supply_purchase_request.rst index c266c2631b..f82f81946f 100644 --- a/tests/scenario_stock_supply_purchase_request.rst +++ b/tests/scenario_stock_supply_purchase_request.rst @@ -162,6 +162,63 @@ There is now a draft purchase request:: >>> pr.quantity 1.0 +Create an order point with negative minimal quantity:: + + >>> set_user(stock_admin_user) + >>> OrderPoint = Model.get('stock.order_point') + >>> order_point = OrderPoint() + >>> order_point.type = 'purchase' + >>> order_point.product = product + >>> order_point.warehouse_location = warehouse_loc + >>> order_point.min_quantity = -1 + >>> order_point.target_quantity = 10 + >>> order_point.save() + +Create production request:: + + >>> create_pr = Wizard('stock.supply') + >>> create_pr.execute('create_') + +There is no more production request:: + + >>> set_user(purchase_user) + >>> PurchaseRequest.find([]) + [] + +Set a postive minimal quantity on order point create purchase request:: + + >>> set_user(stock_admin_user) + >>> order_point.min_quantity = 5 + >>> order_point.save() + >>> create_pr = Wizard('stock.supply') + >>> create_pr.execute('create_') + +There is now a draft purchase request:: + + >>> set_user(purchase_user) + >>> pr, = PurchaseRequest.find([('state', '=', 'draft')]) + >>> pr.product == product + True + >>> pr.quantity + 11.0 + +Using zero as minimal quantity on order point also creates purchase request:: + + >>> set_user(stock_admin_user) + >>> order_point.min_quantity = 0 + >>> order_point.save() + >>> create_pr = Wizard('stock.supply') + >>> create_pr.execute('create_') + +There is now a draft purchase request:: + + >>> set_user(purchase_user) + >>> pr, = PurchaseRequest.find([('state', '=', 'draft')]) + >>> pr.product == product + True + >>> pr.quantity + 11.0 + Re-run with purchased request:: >>> create_purchase = Wizard('purchase.request.create_purchase', [pr]) diff --git a/tests/test_stock_supply.py b/tests/test_stock_supply.py index fd8c5cc38c..a4a7e7686a 100644 --- a/tests/test_stock_supply.py +++ b/tests/test_stock_supply.py @@ -148,6 +148,7 @@ class StockSupplyTestCase(ModuleTestCase): 'product': product.id, 'type': 'purchase', 'warehouse_location': warehouse.id, + 'min_quantity': 0.0, 'target_quantity': 5.0, }])