Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dc-oerp committed Jan 8, 2025
1 parent e19888f commit 05f4ff8
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 142 deletions.
74 changes: 64 additions & 10 deletions account_payment_widget_amount/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Copyright 2024 OERP Canada <https://www.oerp.ca>

from odoo import api, models
from odoo.tools import float_compare


class AccountMove(models.Model):
Expand All @@ -24,15 +25,68 @@ class AccountMoveLine(models.Model):
_inherit = "account.move.line"

@api.model
def _prepare_reconciliation_single_partial(
self, debit_values, credit_values, shadowed_aml_values=None
):
# update paid amount from front end
def _prepare_reconciliation_amls(self, values_list, shadowed_aml_values=None):
am_model = self.env["account.move"]
aml_model = self.env["account.move.line"]
partials = super()._prepare_reconciliation_amls(
values_list=values_list, shadowed_aml_values=shadowed_aml_values
)
if self.env.context.get("paid_amount", 0.0):
total_paid = self.env.context.get("paid_amount", 0.0)
credit_values["amount_residual"] = credit_values[
"amount_residual_currency"
] = total_paid
return super()._prepare_reconciliation_single_partial(
debit_values, credit_values, shadowed_aml_values=shadowed_aml_values
)
current_am = am_model.browse(self.env.context.get("move_id"))
current_aml = aml_model.browse(self.env.context.get("line_id"))
decimal_places = current_am.company_id.currency_id.decimal_places
if current_am.currency_id.id != current_am.company_currency_id.id:
total_paid = current_am.currency_id._convert(
total_paid,
current_aml.currency_id,
current_am.company_id,
current_aml.date,
)
for partial in partials[0]:
partial_values = partial.get("partial_values")
debit_line = self.browse(partial_values.get("debit_move_id"))
credit_line = self.browse(partial_values.get("credit_move_id"))
different_currency = (
debit_line.currency_id.id != credit_line.currency_id.id
)
to_apply = (
min(total_paid, partial_values.get("amount", 0.0))
if partial_values
else 0.0
)
partial_values.update(
{
"amount": to_apply,
}
)
if different_currency:
credit_currency = credit_line.company_currency_id
debit_currency = debit_line.company_currency_id
partial_values.update(
{
"debit_amount_currency": credit_currency._convert(
to_apply,
debit_line.currency_id,
credit_line.company_id,
credit_line.date,
),
"credit_amount_currency": debit_currency._convert(
to_apply,
credit_line.currency_id,
debit_line.company_id,
debit_line.date,
),
}
)
else:
partial_values.update(
{
"debit_amount_currency": to_apply,
"credit_amount_currency": to_apply,
}
)
total_paid -= to_apply
if float_compare(total_paid, 0.0, precision_digits=decimal_places) <= 0:
break
return partials
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ patch(AccountPaymentField.prototype, {
position: localization.direction === "rtl" ? "bottom" : "left",
}
);
// Exit the loop once the match is found
break;
}
}
Expand All @@ -56,7 +55,7 @@ patch(AccountPaymentField.prototype, {
var payment_amount =
parseFloat(document.getElementById("paid_amount").value) || 0.0;
var context = {
paid_amount: -payment_amount,
paid_amount: payment_amount,
};
await this.orm.call(
"account.move",
Expand Down
Loading

0 comments on commit 05f4ff8

Please sign in to comment.