Skip to content

Commit

Permalink
[14.0][MIG] - stock_auto_move
Browse files Browse the repository at this point in the history
  • Loading branch information
sbejaoui committed Jun 10, 2021
1 parent 9f8b58c commit adeec2f
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 40 deletions.
2 changes: 1 addition & 1 deletion stock_auto_move/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{
"name": "Automatic Move Processing",
"version": "13.0.1.0.0",
"version": "14.0.1.0.0",
"author": "NDP Systèmes, ACSONE SA/NV, Odoo Community Association (OCA)",
"category": "Warehouse",
"development_status": "Production/Stable",
Expand Down
26 changes: 12 additions & 14 deletions stock_auto_move/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@ def _auto_assign_quantities(self):
move.quantity_done = move.reserved_availability

def _action_assign(self):
res = super(StockMove, self)._action_assign()
res = super()._action_assign()
# Transfer all pickings which have an auto move assigned
moves = self.filtered(
lambda m: m.state in ("assigned", "partially_available") and m.auto_move
)
moves._auto_assign_quantities()
# In case of no backorder on the first move and cancel propagation
# we need to propagate cancel_backorder to action_done
moves._action_done(
cancel_backorder=self.env.context.get("cancel_backorder", False)
)
# We need to create backorder if there are mixed moves (auto and manual)
moves.mapped("picking_id")._create_backorder()

if moves:
moves._auto_assign_quantities()
# In case of no backorder on the first move and cancel propagation
# we need to propagate cancel_backorder to action_done
moves._action_done(
cancel_backorder=self.env.context.get("cancel_backorder", False)
)
# We need to create backorder if there are mixed moves (auto and manual)
moves.mapped("picking_id")._create_backorder()
return res

@api.model
def _get_auto_moves_by_pickings(self, auto_moves):
""" Group moves by picking.
"""Group moves by picking.
@param auto_moves: stock.move data set
@return dict dict of moves grouped by pickings
{stock.picking(id): stock.move(id1, id2, id3 ...), ...}
Expand All @@ -56,6 +56,4 @@ def _change_procurement_group(self):

def _action_confirm(self, merge=True, merge_into=False):
self._change_procurement_group()
return super(StockMove, self)._action_confirm(
merge=merge, merge_into=merge_into
)
return super()._action_confirm(merge=merge, merge_into=merge_into)
1 change: 1 addition & 0 deletions stock_auto_move/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* Nicolas Piganeau <[email protected]>
* Cédric Pigeon <[email protected]>
* Denis Roussel <[email protected]>
* Souheil Bejaoui <[email protected]>
59 changes: 35 additions & 24 deletions stock_auto_move/tests/test_stock_auto_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,24 @@ def test_20_procurement_auto_move(self):
)
moves_after = self.move_obj.search([]) - moves_before
self.assertEqual(
moves_after.rule_id.id, self.ref("stock_auto_move.stock_rule_a_to_b"),
moves_after.rule_id.id,
self.ref("stock_auto_move.stock_rule_a_to_b"),
)

self.assertTrue(moves_after.auto_move)
self.assertEqual(moves_after.state, "confirmed")
self.assertEquals(moves_after.group_id, self.auto_group)
self.assertEqual(moves_after.group_id, self.auto_group)

def test_30_push_rule_auto(self):
"""Checks that push rule with auto set leads to an auto_move."""
self.product_a1232.route_ids = [(4, self.ref("stock_auto_move.test_route"))]
self.env["stock.quant"].create(
{
"product_id": self.product_a1232.id,
"location_id": self.location_shelf.id,
"quantity": 10,
}
)
move3 = self.move_obj.create(
{
"name": "Supply source location for test",
Expand Down Expand Up @@ -188,7 +196,7 @@ def test_40_chained_auto_move(self):
self.assertTrue(picking.move_line_ids)
self.assertEqual(len(picking.move_line_ids), 1)
picking.move_line_ids.qty_done = 2
picking.action_done()
picking._action_done()
self.assertTrue(move1.move_dest_ids)

self.assertTrue(move1.move_dest_ids.auto_move)
Expand Down Expand Up @@ -242,7 +250,7 @@ def test_50_partial_chained_auto_move(self):
self.assertEqual(len(picking.move_line_ids), 1)
picking.move_line_ids.qty_done = 1
picking.move_line_ids.product_uom_qty = 1
picking.action_done()
picking._action_done()

# As move_dest_ids include backorders
self.assertEqual(len(move1.move_dest_ids), 2)
Expand All @@ -264,12 +272,12 @@ def test_50_partial_chained_auto_move(self):
self.assertEqual(len(back_order), 1)

back_order.move_line_ids.qty_done = 1
back_order.action_done()
back_order._action_done()

move2 = back_order.move_lines
self.assertEqual(len(move2.move_dest_ids), 2)

self.assertEquals(move2.move_dest_ids.mapped("auto_move"), [True, True])
self.assertEqual(move2.move_dest_ids.mapped("auto_move"), [True, True])
self.assertEqual(move2.move_dest_ids.mapped("state"), ["done", "done"])

def test_60_partial_chained_auto_move(self):
Expand Down Expand Up @@ -344,7 +352,7 @@ def test_60_partial_chained_auto_move(self):
move2.move_line_ids.qty_done = 1
move2.move_line_ids.product_uom_qty = 1

picking.action_done()
picking._action_done()

second_step_back_order = self.env["stock.picking"].search(
[("backorder_id", "=", second_step_picking.id)]
Expand Down Expand Up @@ -387,12 +395,13 @@ def test_70_procurement_auto_move_keep_group(self):
)
moves_after = self.move_obj.search([]) - moves_before
self.assertEqual(
moves_after.rule_id.id, self.ref("stock_auto_move.stock_rule_a_to_b"),
moves_after.rule_id.id,
self.ref("stock_auto_move.stock_rule_a_to_b"),
)

self.assertTrue(moves_after.auto_move)
self.assertEqual(moves_after.state, "confirmed")
self.assertEquals(moves_after.group_id, group_manual)
self.assertEqual(moves_after.group_id, group_manual)

def test_80_chained_auto_move_uom(self):
"""
Expand Down Expand Up @@ -441,7 +450,7 @@ def test_80_chained_auto_move_uom(self):
self.assertTrue(picking.move_line_ids)
self.assertEqual(len(picking.move_line_ids), 1)
picking.move_line_ids.qty_done = 2
picking.action_done()
picking._action_done()
self.assertTrue(move1.move_dest_ids)

self.assertTrue(move1.move_dest_ids.auto_move)
Expand Down Expand Up @@ -520,10 +529,12 @@ def test_90_partial_chained_auto_move_no_backorder(self):
move2.move_line_ids.product_uom_qty = 1

res = picking.button_validate()
self.assertDictContainsSubset(
{"res_model": "stock.backorder.confirmation"}, res,
self.assertEqual(res.get("res_model"), "stock.backorder.confirmation")
wizard = (
self.env["stock.backorder.confirmation"]
.with_context(**res.get("context", {}))
.create({})
)
wizard = self.env["stock.backorder.confirmation"].browse(res["res_id"])
wizard.process_cancel_backorder()

second_step_back_order = self.env["stock.picking"].search(
Expand All @@ -532,10 +543,10 @@ def test_90_partial_chained_auto_move_no_backorder(self):

self.assertFalse(second_step_back_order)

self.assertEquals("done", move1.move_dest_ids.state)
self.assertEquals("done", move2.move_dest_ids.state)
self.assertEquals(2.0, move1.move_dest_ids.quantity_done)
self.assertEquals(1.0, move2.move_dest_ids.quantity_done)
self.assertEqual("done", move1.move_dest_ids.state)
self.assertEqual("done", move2.move_dest_ids.state)
self.assertEqual(2.0, move1.move_dest_ids.quantity_done)
self.assertEqual(1.0, move2.move_dest_ids.quantity_done)

def test_100_partial_chained_auto_move_mixed_no_backorder(self):
"""
Expand Down Expand Up @@ -633,10 +644,12 @@ def test_100_partial_chained_auto_move_mixed_no_backorder(self):
move2.move_line_ids.product_uom_qty = 5

res = picking.button_validate()
self.assertDictContainsSubset(
{"res_model": "stock.backorder.confirmation"}, res,
self.assertEqual(res.get("res_model"), "stock.backorder.confirmation")
wizard = (
self.env["stock.backorder.confirmation"]
.with_context(**res.get("context", {}))
.create({})
)
wizard = self.env["stock.backorder.confirmation"].browse(res["res_id"])
wizard.process_cancel_backorder()

# We need to ensure that all moves are done or cancelled in the
Expand All @@ -656,7 +669,5 @@ def test_100_partial_chained_auto_move_mixed_no_backorder(self):
# If https://github.com/odoo/odoo/pull/66124 is integrated,
# this should become assigned as remaining quantity should be cancelled
# and quantities should be 5.0
self.assertEquals(
"partially_available", second_step_back_order.move_lines.state
)
self.assertEquals(10.0, second_step_back_order.move_lines.product_uom_qty)
self.assertEqual("partially_available", second_step_back_order.move_lines.state)
self.assertEqual(10.0, second_step_back_order.move_lines.product_uom_qty)
2 changes: 1 addition & 1 deletion stock_auto_move/views/stock_move.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<field name="inherit_id" ref="stock.view_move_form" />
<field name="priority" eval="16" />
<field name="arch" type="xml">
<field name="date_expected" position="after">
<field name="date" position="after">
<field name="auto_move" />
</field>
</field>
Expand Down

0 comments on commit adeec2f

Please sign in to comment.