Skip to content

Commit

Permalink
[IMP] Recompute amount currency with payment date
Browse files Browse the repository at this point in the history
  • Loading branch information
yibudak committed Dec 29, 2023
1 parent ead5cfd commit ce47ad2
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions account_check/models/account_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
##############################################################################
from odoo import fields, models, _, api
from odoo.exceptions import UserError, ValidationError
from odoo.tools import float_is_zero
import logging

_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -673,3 +674,51 @@ def prepare_new_operation_move_values(
"line_ids": [(0, False, debit_line_vals), (0, False, credit_line_vals)],
}
return move_vals

@api.multi
def _recompute_operations_amount_currency(self):
"""
Recompute the amount in currency of the company of the check due
"""
for rec in self:
due_date = rec.payment_date
today = fields.Date.today()
if today > due_date:
last_valid_date = due_date
else:
last_valid_date = today
for op in rec.operation_ids.sudo().filtered(lambda o: o.origin):
if op.origin._name == "account.payment":
move_lines = op.origin.move_line_ids
# partner_id = op.origin.partner_id
else: # Account.move
# partner_id = op.origin.partner_id
move_lines = op.origin.line_ids

# if partner_id.partner_currency_id == rec.company_currency_id:
# continue

# If operation is reconciled, we don't recompute
# if move_lines.filtered(lambda m: m.full_reconcile_id):
# continue

for ml in move_lines.filtered(
lambda m: m.account_id.currency_id
and m.account_id.currency_id != rec.company_currency_id
and not m.full_reconcile_id
):
amount = ml.debit or ml.credit
sign = 1 if ml.debit else -1
amount_currency = rec.company_currency_id._convert(
amount,
ml.account_id.currency_id,
rec.company_id,
last_valid_date,
)
# We need to use Administrator account because of
# odoo-server/addons/account/models/account_move.py:1342
ml.sudo(2).write(
{
"amount_currency": sign * amount_currency,
}
)

0 comments on commit ce47ad2

Please sign in to comment.