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][FW] procurement_auto_create_group: partial ports of #1821 #2157

Merged
Merged
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
11 changes: 2 additions & 9 deletions procurement_auto_create_group/models/procurement_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ def _get_rule(self, product_id, location_id, values):
rule = super()._get_rule(product_id, location_id, values)
# If there isn't a date planned in the values it means that this
# method has been called outside of a procurement process.
if (
rule
and not values.get("group_id")
and rule.auto_create_group
and values.get("date_planned")
):
group_data = rule._prepare_auto_procurement_group_data()
group = self.env["procurement.group"].create(group_data)
values["group_id"] = group
if rule and rule.auto_create_group and values.get("date_planned"):
values["group_id"] = rule._get_auto_procurement_group(product_id)
return rule
9 changes: 6 additions & 3 deletions procurement_auto_create_group/models/stock_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ def _onchange_group_propagation_option(self):
if self.group_propagation_option != "propagate":
self.auto_create_group = False

def _get_auto_procurement_group(self, product):
group_data = self._prepare_auto_procurement_group_data(product)
return self.env["procurement.group"].create(group_data)

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_data = self._prepare_auto_procurement_group_data()
group = self.env["procurement.group"].create(group_data)
group = self._get_auto_procurement_group(move_to_copy.product_id)
new_move_vals["group_id"] = group.id
return new_move_vals

def _prepare_auto_procurement_group_data(self):
def _prepare_auto_procurement_group_data(self, product):
Copy link
Contributor Author

@sebalix sebalix Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any override of this method will break once merged.
In OCA, it is only overridden in procurement_auto_create_group_carrier and procurement_auto_create_group_by_product which are not yet available on 16.0.

name = self.env["ir.sequence"].next_by_code("procurement.group") or False
if not name:
raise UserError(_("No sequence defined for procurement group."))
Expand Down
18 changes: 12 additions & 6 deletions procurement_auto_create_group/tests/test_auto_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def setUpClass(cls):

# Create rules and routes:
pull_push_route_auto = cls.route_obj.create({"name": "Auto Create Group"})
cls.rule_1 = cls.rule_obj.create(
cls.pull_push_rule_auto = cls.rule_obj.create(
{
"name": "rule with autocreate",
"route_id": pull_push_route_auto.id,
Expand Down Expand Up @@ -56,7 +56,7 @@ def setUpClass(cls):
}
)
push_route_auto = cls.route_obj.create({"name": "Auto Create Group"})
cls.rule_1 = cls.rule_obj.create(
cls.push_rule_auto = cls.rule_obj.create(
{
"name": "route_auto",
"location_src_id": cls.location.id,
Expand Down Expand Up @@ -116,9 +116,13 @@ def setUpClass(cls):
}
)

cls.group = cls.group_obj.create({"name": "SO0001"})

@classmethod
def _procure(cls, product):
values = {}
values = {
"group_id": cls.group,
}
cls.group_obj.run(
[
cls.env["procurement.group"].Procurement(
Expand Down Expand Up @@ -175,8 +179,10 @@ def test_01_pull_push_no_auto_create_group(self):
[("product_id", "=", self.prod_no_auto_pull_push.id)]
)
self.assertTrue(move)
self.assertFalse(
move.group_id, "Procurement Group should not have been assigned."
self.assertEqual(
move.group_id,
self.group,
"Procurement Group should not have been assigned.",
)

def test_02_pull_push_auto_create_group(self):
Expand All @@ -194,7 +200,7 @@ def test_02_pull_push_auto_create_group(self):

def test_03_onchange_method(self):
"""Test onchange method for stock rule."""
proc_rule = self.rule_1
proc_rule = self.push_rule_auto
self.assertTrue(proc_rule.auto_create_group)
proc_rule.write({"group_propagation_option": "none"})
proc_rule._onchange_group_propagation_option()
Expand Down
Loading