Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP] procurement_auto_create_group: create a procurement.group for each stock.picking instead of each stock.move #2207

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 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,12 @@ 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.group_id
if not group:
group = self._get_auto_procurement_group(move_to_copy.product_id)
move_to_copy.picking_id.move_ids.write({"group_id": group.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.",
)
Loading