-
-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] procurement_mto_analytic: Migration to 16.0
- Loading branch information
1 parent
3b7d974
commit 9ffe1c1
Showing
8 changed files
with
78 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,39 @@ | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
import json | ||
|
||
from odoo import models | ||
|
||
|
||
class StockRule(models.Model): | ||
_inherit = "stock.rule" | ||
|
||
def _find_matching_analytic_distribution_record(self, analytic_distribution): | ||
# Prepare the JSONB structure as a string for the SQL query | ||
analytic_distribution_str = json.dumps(analytic_distribution) | ||
# Use a parameterized query for safety | ||
query = """ | ||
SELECT id FROM purchase_order_line | ||
WHERE analytic_distribution::jsonb = %s::jsonb; | ||
""" | ||
self.env.cr.execute(query, (analytic_distribution_str,)) | ||
result = self.env.cr.fetchall() | ||
# Extract IDs from the result | ||
matching_po_line = [res[0] for res in result] | ||
return matching_po_line | ||
|
||
def _make_po_get_domain(self, company_id, values, partner): | ||
res = super()._make_po_get_domain(company_id, values, partner) | ||
res += ( | ||
( | ||
"order_line.account_analytic_id", | ||
"=", | ||
values.get("account_analytic_id", False), | ||
), | ||
) | ||
return res | ||
domain = super()._make_po_get_domain(company_id, values, partner) | ||
if values.get("analytic_distribution"): | ||
# Fetch matching record IDs based on dynamic analytic_distribution | ||
matching_po_line = self._find_matching_analytic_distribution_record( | ||
values["analytic_distribution"] | ||
) | ||
if matching_po_line: | ||
domain += (("order_line", "in", tuple(matching_po_line)),) | ||
else: | ||
# To create new PO | ||
domain += (("order_line", "=", 0000000),) | ||
else: | ||
domain += (("order_line.analytic_distribution", "=", False),) | ||
return domain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters