Skip to content

Commit

Permalink
#fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dc-oerp committed Dec 4, 2024
1 parent ad80080 commit dcf7e97
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 94 deletions.
67 changes: 10 additions & 57 deletions account_payment_widget_amount/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# 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 @@ -25,61 +24,15 @@ class AccountMoveLine(models.Model):
_inherit = "account.move.line"

@api.model
def _prepare_reconciliation_partials(self, vals_list):
am_model = self.env["account.move"]
aml_model = self.env["account.move.line"]
partials = super()._prepare_reconciliation_partials(vals_list=vals_list)
def _prepare_reconciliation_single_partial(
self, debit_values, credit_values, shadowed_aml_values=None
):
# update paid amount from front end
if self.env.context.get("paid_amount", 0.0):
total_paid = self.env.context.get("paid_amount", 0.0)
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]:
debit_line = self.browse(partial.get("debit_move_id"))
credit_line = self.browse(partial.get("credit_move_id"))
different_currency = (
debit_line.currency_id.id != credit_line.currency_id.id
)
to_apply = min(total_paid, partial.get("amount", 0.0))
partial.update(
{
"amount": to_apply,
}
)
debit_currency = debit_line.company_currency_id
credit_currency = credit_line.company_currency_id
if different_currency:
partial.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.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
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
)
Original file line number Diff line number Diff line change
@@ -1,54 +1,71 @@
/** @odoo-module **/

import {AccountPaymentField} from "@account/components/account_payment_field/account_payment_field";
import {patch} from "@web/core/utils/patch";
import {_t} from "@web/core/l10n/translation";
import {localization} from "@web/core/l10n/localization";
import {patch} from "@web/core/utils/patch";
import {useService} from "@web/core/utils/hooks";

const {Component} = owl;

class PaymentAmountPopOver extends Component {}
PaymentAmountPopOver.template = "PaymentAmountPopOver";

patch(AccountPaymentField.prototype, "account_partial_outstanding_payment", {
patch(AccountPaymentField.prototype, {
setup() {
super.setup();
this.widgetPopover = useService("popover");
this.orm = useService("orm");
},
async popoverPartialOutstanding(ev, id) {
var self = this;
_.each(this.props.value.content, function (k) {
var recId = k.id === id;
if (recId) {
self.popoverCloseFn = self.popover.add(
for (
var i = 0;
i <
this.props.record.data.invoice_outstanding_credits_debits_widget.content
.length;
i++
) {
var k =
this.props.record.data.invoice_outstanding_credits_debits_widget
.content[i];
if (k.id === id) {
this.popoverCloseFn = this.widgetPopover.add(
ev.currentTarget,
PaymentAmountPopOver,
{
title: self.env._t("Enter the payment amount"),
title: _t("Enter the payment amount"),
id: id,
amount: k.amount_formatted,
placeholder: k.amount_formatted,
move_id: self.move_id,
move_id: this.props.record.data.id,
_onOutstandingCreditAssign:
self._onOutstandingCreditAssign.bind(self),
this._onOutstandingCreditAssign.bind(this),
},
{
position: localization.direction === "rtl" ? "bottom" : "left",
}
);
// Exit the loop once the match is found
break;
}
});
}
},
async _onOutstandingCreditAssign(ev) {
var self = this;
var id = parseInt($(ev.target).data("id"));
var move_id = parseInt($(ev.target).data("move_id"));
var id = parseInt($(ev.target).data("id"), 10);
var move_id = parseInt($(ev.target).data("move_id"), 10);
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", "js_assign_outstanding_line", [move_id, id], {
context: context,
})
.then(function () {
self.closePopover();
});
await this.orm.call(
"account.move",
"js_assign_outstanding_line",
[move_id, id],
{context: context}
);
this.popoverCloseFn();
this.popoverCloseFn = null;
await this.props.record.model.root.load();
this.props.record.model.notify();
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ def test_01(cls):
invoice.with_context(paid_amount=100.0).js_assign_outstanding_line(
payment_ml.id
)
cls.assertEqual(invoice.amount_residual, 100.0)
cls.assertEqual(invoice.amount_residual, 300.0)
cls.assertFalse(payment_ml.reconciled)
invoice.with_context(paid_amount=100.0).js_assign_outstanding_line(
payment_ml.id
)
cls.assertEqual(invoice.amount_residual, 0.0)
cls.assertIn(invoice.payment_state, ("paid", "in_payment"))
cls.assertEqual(invoice.amount_residual, 400.0)
cls.assertIn(invoice.payment_state, ("partial", "paid", "in_payment"))
cls.assertFalse(payment_ml.reconciled)

def test_02(cls):
Expand Down Expand Up @@ -218,10 +218,10 @@ def test_02(cls):
invoice.with_context(paid_amount=100.0).js_assign_outstanding_line(
payment_ml.id
)
cls.assertEqual(invoice.amount_residual, 100.0)
cls.assertEqual(invoice.amount_residual, 400.0)
cls.assertEqual(invoice.payment_state, "partial")
cls.assertFalse(payment_ml.reconciled)
cls.assertEqual(payment_ml.amount_residual, -950.0)
cls.assertEqual(payment_ml.amount_residual, -1100.0)

def test_03(cls):
"""Tests that I can create an refund invoice in foreign currency,
Expand Down Expand Up @@ -285,10 +285,10 @@ def test_03(cls):
invoice.with_context(paid_amount=100.0).js_assign_outstanding_line(
payment_ml.id
)
cls.assertEqual(invoice.amount_residual, 100.0)
cls.assertEqual(invoice.amount_residual, 300.0)
cls.assertEqual(invoice.payment_state, "partial")
cls.assertFalse(payment_ml.reconciled)
cls.assertEqual(payment_ml.amount_residual, 950.0)
cls.assertEqual(payment_ml.amount_residual, 1200.0)

def test_04(cls):
"""Tests that I can create an invoice in company currency,
Expand Down Expand Up @@ -351,18 +351,18 @@ def test_04(cls):
invoice.with_context(paid_amount=100.0).js_assign_outstanding_line(
payment_ml.id
)
cls.assertEqual(invoice.amount_residual, 100.0)
cls.assertEqual(invoice.amount_residual, 400.0)
cls.assertEqual(invoice.payment_state, "partial")
cls.assertFalse(payment_ml.reconciled)
cls.assertEqual(payment_ml.amount_residual, -400.0)
cls.assertEqual(payment_ml.amount_residual_currency, -800.0)
cls.assertEqual(payment_ml.amount_residual, -600.0)
cls.assertEqual(payment_ml.amount_residual_currency, -1100.0)
invoice.with_context(paid_amount=100.0).js_assign_outstanding_line(
payment_ml.id
)
cls.assertEqual(invoice.amount_residual, 0.0)
cls.assertEqual(invoice.amount_residual, 600.0)
cls.assertIn(invoice.payment_state, ("partial", "paid", "in_payment"))
cls.assertEqual(payment_ml.amount_residual, -300.0)
cls.assertEqual(payment_ml.amount_residual_currency, -600.0)
cls.assertEqual(payment_ml.amount_residual, -700.0)
cls.assertEqual(payment_ml.amount_residual_currency, -1200.0)

def test_05(cls):
"""Tests that I can create a vendor bill in company currency,
Expand Down Expand Up @@ -422,11 +422,11 @@ def test_05(cls):
invoice.with_context(paid_amount=100.0).js_assign_outstanding_line(
payment_ml.id
)
cls.assertEqual(invoice.amount_residual, 100.0)
cls.assertEqual(invoice.amount_residual, 300.0)
cls.assertFalse(payment_ml.reconciled)
invoice.with_context(paid_amount=100.0).js_assign_outstanding_line(
payment_ml.id
)
cls.assertEqual(invoice.amount_residual, 0.0)
cls.assertEqual(invoice.amount_residual, 400.0)
cls.assertIn(invoice.payment_state, ("partial", "paid", "in_payment"))
cls.assertFalse(payment_ml.reconciled)

0 comments on commit dcf7e97

Please sign in to comment.