Skip to content

Commit

Permalink
[IMP] procurement_auto_create_group: create a procurement.group for e…
Browse files Browse the repository at this point in the history
…ach stock.picking instead of each stock.move
  • Loading branch information
ACheung-FactorLibre committed Nov 28, 2024
1 parent 54c9af4 commit abcc090
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
6 changes: 5 additions & 1 deletion procurement_auto_create_group/models/stock_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ def _get_auto_procurement_group(self, product):
def _push_prepare_move_copy_values(self, move_to_copy, new_date):
new_move_vals = super()._push_prepare_move_copy_values(move_to_copy, new_date)
if self.auto_create_group:
group = self._get_auto_procurement_group(move_to_copy.product_id)
# Get the same procurement group as the original move if it exists
# so that the new move is part of the same group as the original move
group = move_to_copy.picking_id.move_ids.mapped("move_dest_ids").group_id
if not group:
group = self._get_auto_procurement_group(move_to_copy.product_id)
new_move_vals["group_id"] = group.id
return new_move_vals

Expand Down
68 changes: 68 additions & 0 deletions procurement_auto_create_group/tests/test_auto_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ def setUpClass(cls):
"route_ids": [(6, 0, [push_route_auto.id])],
}
)
cls.prod_auto_push_2 = cls.product_obj.create(
{
"name": "Test Product 5",
"type": "product",
"route_ids": [(6, 0, [push_route_auto.id])],
}
)
cls.prod_no_auto_push = cls.product_obj.create(
{
"name": "Test Product 4",
Expand Down Expand Up @@ -168,6 +175,24 @@ def _push_trigger(cls, product):
picking.move_ids.write({"quantity_done": 1.0})
picking.button_validate()

def _add_move_to_picking(self, picking, product):
move = self.move_obj.create(
{
"name": "Test move",
"product_id": product.id,
"date_deadline": "2099-06-01 18:00:00",
"date": "2099-06-01 18:00:00",
"product_uom": product.uom_id.id,
"product_uom_qty": 1.0,
"location_id": self.supplier_location.id,
"location_dest_id": self.location.id,
"picking_id": picking.id,
}
)
picking.action_confirm()
move.write({"quantity_done": 1.0})
picking._action_done()

def test_01_pull_push_no_auto_create_group(self):
"""Test auto creation of group."""
move = self.move_obj.search(
Expand Down Expand Up @@ -245,3 +270,46 @@ def test_05_push_auto_create_group(self):
)
self.assertTrue(move)
self.assertTrue(move.group_id, "Procurement Group not assigned.")

def test_06_auto_create_same_procurement_group_per_picking(self):
"""Test auto creation of group for same procurement group per picking."""
first_move = self.move_obj.search(
[
("product_id", "=", self.prod_auto_push.id),
("location_dest_id", "=", self.loc_components.id),
]
)
self.assertFalse(first_move)

picking = self.picking_obj.create(
{
"picking_type_id": self.env.ref("stock.picking_type_in").id,
"location_id": self.supplier_location.id,
"location_dest_id": self.location.id,
"move_ids": [],
}
)

self._add_move_to_picking(picking, self.prod_auto_push)
second_move = self.move_obj.search(
[
("product_id", "=", self.prod_auto_push.id),
("location_dest_id", "=", self.loc_components.id),
]
)
self.assertTrue(second_move)
self.assertTrue(second_move.group_id, "Procurement Group not assigned.")

self._add_move_to_picking(picking, self.prod_auto_push_2)
third_move = self.move_obj.search(
[
("product_id", "=", self.prod_auto_push_2.id),
("location_dest_id", "=", self.loc_components.id),
]
)
self.assertTrue(third_move)
self.assertEqual(
third_move.move_dest_ids.group_id,
second_move.move_dest_ids.group_id,
"Procurement Group should be the same for the same picking.",
)

0 comments on commit abcc090

Please sign in to comment.