Skip to content

Commit

Permalink
[MIG] account_payment_widget_amount: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dc-oerp committed Jul 25, 2024
1 parent 3c57814 commit 22dc423
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 114 deletions.
10 changes: 2 additions & 8 deletions account_payment_widget_amount/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Authors
-------

* ForgeFlow S.L.
* OERP Canada

Contributors
------------
Expand All @@ -81,6 +82,7 @@ Contributors
- Jordi Ballester Alomar <jordi.ballester@eforgeflow.com>
- Christopher Ormaza <chris.ormaza@eforgeflow.com>
- Dhara Solanki <dhara.solanki@initos.com>
- Daryl Chen <dc@oerp.ca>

Maintainers
-----------
Expand All @@ -95,14 +97,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-ChrisOForgeFlow| image:: https://github.com/ChrisOForgeFlow.png?size=40px
:target: https://github.com/ChrisOForgeFlow
:alt: ChrisOForgeFlow

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-ChrisOForgeFlow|

This module is part of the `OCA/account-payment <https://github.com/OCA/account-payment/tree/17.0/account_payment_widget_amount>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions account_payment_widget_amount/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models
6 changes: 3 additions & 3 deletions account_payment_widget_amount/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Copyright 2019-2021 ForgeFlow S.L.
# Copyright 2024 OERP Canada <https://www.oerp.ca>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Account Payment Widget Amount",
"summary": "Extends the payment widget to be able to choose the payment " "amount",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"category": "Account-payment",
"website": "https://github.com/OCA/account-payment",
"author": "ForgeFlow S.L., Odoo Community Association (OCA)",
"author": "ForgeFlow S.L., OERP Canada, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": ["account"],
"data": [],
"maintainers": ["ChrisOForgeFlow"],
"assets": {
"web.assets_backend": [
"account_payment_widget_amount/static/src/xml/account_payment.xml",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Project-Id-Version: Odoo Server 17.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
Expand Down
2 changes: 2 additions & 0 deletions account_payment_widget_amount/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import account_move_line
70 changes: 12 additions & 58 deletions account_payment_widget_amount/models/account_move_line.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2018-2021 ForgeFlow S.L.
# 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 @@ -17,68 +17,22 @@ def js_assign_outstanding_line(self, line_id):
line_id=line_id,
),
).js_assign_outstanding_line(line_id)
return super(AccountMove, self).js_assign_outstanding_line(line_id)
return super().js_assign_outstanding_line(line_id)

Check warning on line 20 in account_payment_widget_amount/models/account_move_line.py

View check run for this annotation

Codecov / codecov/patch

account_payment_widget_amount/models/account_move_line.py#L20

Added line #L20 was not covered by tests


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(AccountMoveLine, self)._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,
}
)
if different_currency:
partial.update(
{
"debit_amount_currency": credit_line.company_currency_id._convert(
to_apply,
debit_line.currency_id,
credit_line.company_id,
credit_line.date,
),
"credit_amount_currency": debit_line.company_currency_id._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
)
1 change: 1 addition & 0 deletions account_payment_widget_amount/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
- Jordi Ballester Alomar \<<jordi.ballester@eforgeflow.com>\>
- Christopher Ormaza \<<chris.ormaza@eforgeflow.com>\>
- Dhara Solanki \<<dhara.solanki@initos.com>\>
- Daryl Chen \<<dc@oerp.ca>\>
4 changes: 2 additions & 2 deletions account_payment_widget_amount/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ <h1><a class="toc-backref" href="#toc-entry-3">Credits</a></h1>
<h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
<ul class="simple">
<li>ForgeFlow S.L.</li>
<li>OERP Canada</li>
</ul>
</div>
<div class="section" id="contributors">
Expand All @@ -422,6 +423,7 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<li>Jordi Ballester Alomar &lt;<a class="reference external" href="mailto:jordi.ballester&#64;eforgeflow.com">jordi.ballester&#64;eforgeflow.com</a>&gt;</li>
<li>Christopher Ormaza &lt;<a class="reference external" href="mailto:chris.ormaza&#64;eforgeflow.com">chris.ormaza&#64;eforgeflow.com</a>&gt;</li>
<li>Dhara Solanki &lt;<a class="reference external" href="mailto:dhara.solanki&#64;initos.com">dhara.solanki&#64;initos.com</a>&gt;</li>
<li>Daryl Chen &lt;<a class="reference external" href="mailto:dc&#64;oerp.ca">dc&#64;oerp.ca</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand All @@ -433,8 +435,6 @@ <h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/ChrisOForgeFlow"><img alt="ChrisOForgeFlow" src="https://github.com/ChrisOForgeFlow.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/account-payment/tree/17.0/account_payment_widget_amount">OCA/account-payment</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,54 +1,70 @@
/** @odoo-module **/

import {_t} from "@web/core/l10n/translation";
import {AccountPaymentField} from "@account/components/account_payment_field/account_payment_field";
import {patch} from "@web/core/utils/patch";
import {localization} from "@web/core/l10n/localization";
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",
}
);
break; // Exit the loop once the match is found
}
});
}
},
async _onOutstandingCreditAssign(ev) {
var self = this;
var id = parseInt($(ev.target).data("id"));
var move_id = parseInt($(ev.target).data("move_id"));
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
2 changes: 2 additions & 0 deletions account_payment_widget_amount/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import test_account_payment_widget_amount
Loading

0 comments on commit 22dc423

Please sign in to comment.