Skip to content

Commit 23a38cf

Browse files
[FIX] mrp_multi_level : Fix MRP wizard logic for action selection, quantity reset, and missing company/currency data
1 parent a0b56e2 commit 23a38cf

File tree

7 files changed

+697
-25
lines changed

7 files changed

+697
-25
lines changed

mrp_multi_level/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
from . import stock_rule
1010
from . import mrp_production
1111
from . import stock_quant
12+
from . import procurement_group
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from odoo import api, models
2+
3+
4+
class ProcurementGroup(models.Model):
5+
_inherit = "procurement.group"
6+
7+
@api.model
8+
def _get_rule(self, product_id, location_id, values):
9+
"""Override to respect mrp_action from MRP Multi Level wizard."""
10+
mrp_action = values.get("mrp_action")
11+
if mrp_action and mrp_action not in ("none", False):
12+
company = values.get("company_id", self.env.company)
13+
if hasattr(company, "id"):
14+
company_id = company.id
15+
else:
16+
company_id = company
17+
rule = self.env["stock.rule"].search(
18+
[
19+
("action", "=", mrp_action),
20+
("location_dest_id", "=", location_id.id),
21+
("company_id", "in", [company_id, False]),
22+
],
23+
order="sequence",
24+
limit=1,
25+
)
26+
if not rule:
27+
warehouse = values.get("warehouse_id")
28+
if warehouse:
29+
warehouse_id = (
30+
warehouse.id if hasattr(warehouse, "id") else warehouse
31+
)
32+
rule = self.env["stock.rule"].search(
33+
[
34+
("action", "=", mrp_action),
35+
("warehouse_id", "=", warehouse_id),
36+
("company_id", "in", [company_id, False]),
37+
],
38+
order="sequence",
39+
limit=1,
40+
)
41+
if rule:
42+
return rule
43+
return super()._get_rule(product_id, location_id, values)

mrp_multi_level/models/stock_rule.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,31 @@
77
class StockRule(models.Model):
88
_inherit = "stock.rule"
99

10+
def _make_po_get_domain(self, company_id, values, partner):
11+
domain = super()._make_po_get_domain(company_id, values, partner)
12+
if isinstance(domain, list):
13+
domain = tuple(domain)
14+
currency_id = values.get("currency_id")
15+
if currency_id:
16+
domain = tuple(domain) + (("currency_id", "=", currency_id),)
17+
return domain
18+
19+
def _prepare_purchase_order(self, company_id, origins, values):
20+
res = super()._prepare_purchase_order(company_id, origins, values)
21+
22+
currency_id = False
23+
if isinstance(values, dict):
24+
currency_id = values.get("currency_id")
25+
elif isinstance(values, (list, tuple)):
26+
for v in values:
27+
if isinstance(v, dict) and v.get("currency_id"):
28+
currency_id = v.get("currency_id")
29+
break
30+
31+
if currency_id:
32+
res["currency_id"] = currency_id
33+
return res
34+
1035
def _prepare_mo_vals(
1136
self,
1237
product_id,

0 commit comments

Comments
 (0)