summaryrefslogtreecommitdiff
path: root/addons/stock/tests
diff options
context:
space:
mode:
authorTiffany Chang (tic) <tic@odoo.com>2020-08-20 10:53:38 +0000
committerTiffany Chang (tic) <tic@odoo.com>2020-09-09 07:15:25 +0000
commit2688cd1bae489b1dec8862f4de727ac20514844c (patch)
tree100df8853bbd5e5664eedb4187936bbeede4ddad /addons/stock/tests
parentf0da27e7eb474e6db4cd999306c420804aaa6f9b (diff)
[IMP] mrp(_subcontracting), stock: MO reserve and replenish automatically
This commit does 3 things: 1. When 'action_confirm' is triggered in a manufacturing order, any 'move_raw_ids' (components) that are unable to be fully reserved when `action_assign` is triggered will be checked for an automatic reordering rule (RR). If a rule exists it will be auto-triggered. This includes subcontractor manufacturing orders. Relevant test updated to match this. 2. When a MO is completed, auto check if there are corresponding confirmed stock moves that can be populated by the completed products and trigger their 'action_assign' to reserve the completed products. 3. If a new move line is added to an already confirmed MO, then do same auto-RR check/trigger. (note will occur for pickings without extra code since `stock_picking.action_confirm` is triggered again in this case.) This reuses similar logic as odoo/odoo#52433 from task 2244230. Originally this was done in the `action_assign`, but has been moved to `action_confirm` so as to imitate the now archived MTO process with RR. Overlapping logic has been moved into stock_move for easier reusability. Note that this now means editing existing moves' `product_uom_qty` (i.e. Demand) will not have a flow to auto-trigger their RR. Subcontracting test updated to match + new mrp test added for this new feature. closes odoo/odoo#57174 Task: 2322496 Signed-off-by: Arnold Moyaux <amoyaux@users.noreply.github.com>
Diffstat (limited to 'addons/stock/tests')
-rw-r--r--addons/stock/tests/test_proc_rule.py39
1 files changed, 37 insertions, 2 deletions
diff --git a/addons/stock/tests/test_proc_rule.py b/addons/stock/tests/test_proc_rule.py
index f9885a5a992..8e4b2999aac 100644
--- a/addons/stock/tests/test_proc_rule.py
+++ b/addons/stock/tests/test_proc_rule.py
@@ -149,14 +149,20 @@ class TestProcRule(TransactionCase):
self.assertEqual(receipt_move.product_uom_qty, 17.0)
def test_reordering_rule_2(self):
- """Test when not enough product to assign picking, automatically run
- reordering rule.
+ """Test when there is not enough product to assign a picking => automatically run
+ reordering rule (RR). Add extra product to already confirmed picking => automatically
+ run another RR
"""
self.productA = self.env['product.product'].create({
'name': 'Desk Combination',
'type': 'product',
})
+ self.productB = self.env['product.product'].create({
+ 'name': 'Desk Decoration',
+ 'type': 'product',
+ })
+
warehouse = self.env['stock.warehouse'].search([], limit=1)
orderpoint_form = Form(self.env['stock.warehouse.orderpoint'])
orderpoint_form.product_id = self.productA
@@ -165,6 +171,14 @@ class TestProcRule(TransactionCase):
orderpoint_form.product_max_qty = 5.0
orderpoint = orderpoint_form.save()
+ self.env['stock.warehouse.orderpoint'].create({
+ 'name': 'ProductB RR',
+ 'location_id': warehouse.lot_stock_id.id,
+ 'product_id': self.productB.id,
+ 'product_min_qty': 0,
+ 'product_max_qty': 5,
+ })
+
self.env['stock.rule'].create({
'name': 'Rule Supplier',
'route_id': warehouse.reception_route_id.id,
@@ -197,10 +211,31 @@ class TestProcRule(TransactionCase):
('product_id', '=', self.productA.id),
('location_id', '=', self.env.ref('stock.stock_location_suppliers').id)
])
+
self.assertTrue(receipt_move)
self.assertEqual(receipt_move.date.date(), date.today())
self.assertEqual(receipt_move.product_uom_qty, 17.0)
+ delivery_picking.write({'move_lines': [(0, 0, {
+ 'name': 'Extra Move',
+ 'product_id': self.productB.id,
+ 'product_uom': self.uom_unit.id,
+ 'product_uom_qty': 5.0,
+ 'location_id': warehouse.lot_stock_id.id,
+ 'location_dest_id': self.ref('stock.stock_location_customers'),
+ 'picking_id': delivery_picking.id,
+ 'additional': True
+ })]})
+
+ receipt_move2 = self.env['stock.move'].search([
+ ('product_id', '=', self.productB.id),
+ ('location_id', '=', self.env.ref('stock.stock_location_suppliers').id)
+ ])
+
+ self.assertTrue(receipt_move2)
+ self.assertEqual(receipt_move2.date.date(), date.today())
+ self.assertEqual(receipt_move2.product_uom_qty, 10.0)
+
class TestProcRuleLoad(TransactionCase):
def setUp(cls):