Skip to content

Commit

Permalink
[FIX] domain carry forward
Browse files Browse the repository at this point in the history
  • Loading branch information
Saran440 committed Jul 30, 2024
1 parent b22a8b1 commit b5cc2f5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
20 changes: 19 additions & 1 deletion budget_control_purchase/models/account_move_line.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Copyright 2020 Ecosoft Co., Ltd. (http://ecosoft.co.th)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models
import json
from odoo import models, _
from odoo.exceptions import UserError


class AccountMoveLine(models.Model):
Expand Down Expand Up @@ -49,6 +51,21 @@ def uncommit_purchase_budget(self):
qty = ml._get_qty_commit(purchase_line)
if qty <= 0 and not ml._check_skip_negative_qty():
continue
# Check analytic distribution, Not allow to change analytic distribution is not depend on PO
purchase_analytic = purchase_line[purchase_line._budget_analytic_field]
# Add analytic_distribution from forward_commit
if purchase_line.fwd_analytic_distribution:
for analytic_id, aa_percent in purchase_line.fwd_analytic_distribution.items():
purchase_analytic[analytic_id] = aa_percent

ml_analytic_ids = [x for x in ml.analytic_distribution]
purchase_analytic_ids = [x for x in purchase_analytic]
if any(aa not in purchase_analytic_ids for aa in ml_analytic_ids):
raise UserError(_(
"Analytic distribution mismatch. "
"Please align with the original purchase order."
))

# Only case reverse and want to return_amount_commit
context = {}
if move_type == "in_invoice" and ml.return_amount_commit:
Expand Down Expand Up @@ -78,6 +95,7 @@ def uncommit_purchase_budget(self):
context["product_qty"] = qty
purchase_line.with_context(**context).commit_budget(
reverse=move_type == "in_invoice",
analytic_distribution=ml.analytic_distribution,
move_line_id=ml.id,
date=ml.date_commit,
)
13 changes: 4 additions & 9 deletions budget_control_purchase/models/budget_commit_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,11 @@ def _get_document_number(self, doc):
return f"{doc.order_id._name},{doc.order_id.id}"
return super()._get_document_number(doc)

def _get_commit_docline(self, res_model):
def _get_base_domain_extension(self, res_model):
"""For module extension"""
if res_model == "purchase.order.line":
domain = self._get_base_domain()
domain.extend(
[
("state", "!=", "cancel"),
]
)
return self.env[res_model].search(domain)
return super()._get_commit_docline(res_model)
return " AND a.state != 'cancel'"
return super()._get_base_domain_extension(res_model)


class BudgetCommitForwardLine(models.Model):
Expand Down
3 changes: 2 additions & 1 deletion budget_control_purchase/models/purchase.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ def _init_docline_budget_vals(self, budget_vals, analytic_id):
self.ensure_one()
# Use product qty from context, if not, use line product_qty
product_qty = self.env.context.get("product_qty") or self.product_qty
percent_analytic = self[self._budget_analytic_field].get(str(analytic_id))
# If not analytic_id, use 100% of the line
percent_analytic = self[self._budget_analytic_field].get(str(analytic_id)) or 100
budget_vals["amount_currency"] = (
self.price_unit * product_qty * percent_analytic / 100
)
Expand Down

0 comments on commit b5cc2f5

Please sign in to comment.