Skip to content

Commit

Permalink
[IMP] add currency support for purchase_budget_oca_validation
Browse files Browse the repository at this point in the history
  • Loading branch information
cvinh committed Nov 17, 2022
1 parent 8be6e35 commit 9edce21
Showing 1 changed file with 51 additions and 5 deletions.
56 changes: 51 additions & 5 deletions purchase_budget_oca_validation/models/crossovered_budget_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class CrossoveredBudgetLines(models.Model):

def _compute_committ_uncommitt_amount(self):
purchase_line_obj = self.env["purchase.order.line"]
company_currency = self.company_id.currency_id
for budget_line in self:
commit_domain = [
("date_order", ">=", budget_line.date_from),
Expand All @@ -40,15 +41,35 @@ def _compute_committ_uncommitt_amount(self):
if budget_line.crossovered_budget_id.amount_include_tax:
budget_line.committed_amount = -sum(
[
line.price_unit * (line.product_qty - line.qty_invoiced)
+ line.price_tax
line.currency_id._convert(
line.price_unit,
company_currency,
self.company_id,
line.date_order,
round=False,
)
* (line.product_qty - line.qty_invoiced)
+ line.currency_id._convert(
line.price_tax,
company_currency,
self.company_id,
line.date_order,
round=False,
)
for line in po_lines_commimt
]
)
else:
budget_line.committed_amount = -sum(
[
line.price_unit * (line.product_qty - line.qty_invoiced)
line.currency_id._convert(
line.price_unit,
company_currency,
self.company_id,
line.date_order,
round=False,
)
* (line.product_qty - line.qty_invoiced)
for line in po_lines_commimt
]
)
Expand All @@ -74,11 +95,36 @@ def _compute_committ_uncommitt_amount(self):
po_lines_uncommit = purchase_line_obj.search(uncommit_domain)
if budget_line.crossovered_budget_id.amount_include_tax:
budget_line.uncommitted_amount = -sum(
[line.price_subtotal + line.price_tax for line in po_lines_uncommit]
[
line.currency_id._convert(
line.price_subtotal,
company_currency,
self.company_id,
line.date_order,
round=False,
)
+ line.currency_id._convert(
line.price_tax,
company_currency,
self.company_id,
line.date_order,
round=False,
)
for line in po_lines_uncommit
]
)
else:
budget_line.uncommitted_amount = -sum(
[line.price_subtotal for line in po_lines_uncommit]
[
line.currency_id._convert(
line.price_subtotal,
company_currency,
self.company_id,
line.date_order,
round=False,
)
for line in po_lines_uncommit
]
)

def _compute_over_budget(self):
Expand Down

0 comments on commit 9edce21

Please sign in to comment.