From 22dc4231692597e59fdf84311e8d596fdc1342a3 Mon Sep 17 00:00:00 2001 From: Daryl Date: Wed, 3 Jul 2024 11:28:40 -0400 Subject: [PATCH] [MIG] account_payment_widget_amount: Migration to 17.0 --- account_payment_widget_amount/README.rst | 10 +-- account_payment_widget_amount/__init__.py | 2 + account_payment_widget_amount/__manifest__.py | 6 +- .../i18n/account_payment_widget_amount.pot | 2 +- .../models/__init__.py | 2 + .../models/account_move_line.py | 70 ++++--------------- .../readme/CONTRIBUTORS.md | 1 + .../static/description/index.html | 4 +- .../src/js/account_payment_field.esm.js | 54 +++++++++----- .../tests/__init__.py | 2 + .../test_account_payment_widget_amount.py | 47 +++++++------ 11 files changed, 86 insertions(+), 114 deletions(-) diff --git a/account_payment_widget_amount/README.rst b/account_payment_widget_amount/README.rst index b903672d7def..ebb56464695f 100644 --- a/account_payment_widget_amount/README.rst +++ b/account_payment_widget_amount/README.rst @@ -73,6 +73,7 @@ Authors ------- * ForgeFlow S.L. +* OERP Canada Contributors ------------ @@ -81,6 +82,7 @@ Contributors - Jordi Ballester Alomar - Christopher Ormaza - Dhara Solanki +- Daryl Chen Maintainers ----------- @@ -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 `__: - -|maintainer-ChrisOForgeFlow| - This module is part of the `OCA/account-payment `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_payment_widget_amount/__init__.py b/account_payment_widget_amount/__init__.py index 0650744f6bc6..69f7babdfb1a 100644 --- a/account_payment_widget_amount/__init__.py +++ b/account_payment_widget_amount/__init__.py @@ -1 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + from . import models diff --git a/account_payment_widget_amount/__manifest__.py b/account_payment_widget_amount/__manifest__.py index 5b9a95254077..f67bcfa3e16b 100644 --- a/account_payment_widget_amount/__manifest__.py +++ b/account_payment_widget_amount/__manifest__.py @@ -1,18 +1,18 @@ # Copyright 2019-2021 ForgeFlow S.L. +# Copyright 2024 OERP Canada # 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", diff --git a/account_payment_widget_amount/i18n/account_payment_widget_amount.pot b/account_payment_widget_amount/i18n/account_payment_widget_amount.pot index 7be9696b34a9..9832dee596de 100644 --- a/account_payment_widget_amount/i18n/account_payment_widget_amount.pot +++ b/account_payment_widget_amount/i18n/account_payment_widget_amount.pot @@ -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" diff --git a/account_payment_widget_amount/models/__init__.py b/account_payment_widget_amount/models/__init__.py index 8795b3bea648..4ac3c4794bd6 100644 --- a/account_payment_widget_amount/models/__init__.py +++ b/account_payment_widget_amount/models/__init__.py @@ -1 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + from . import account_move_line diff --git a/account_payment_widget_amount/models/account_move_line.py b/account_payment_widget_amount/models/account_move_line.py index aa3257d7af7c..e778126af44a 100644 --- a/account_payment_widget_amount/models/account_move_line.py +++ b/account_payment_widget_amount/models/account_move_line.py @@ -1,7 +1,7 @@ # Copyright 2018-2021 ForgeFlow S.L. +# Copyright 2024 OERP Canada from odoo import api, models -from odoo.tools import float_compare class AccountMove(models.Model): @@ -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) 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 + ) diff --git a/account_payment_widget_amount/readme/CONTRIBUTORS.md b/account_payment_widget_amount/readme/CONTRIBUTORS.md index 24a67a517c0a..dd38c6033667 100644 --- a/account_payment_widget_amount/readme/CONTRIBUTORS.md +++ b/account_payment_widget_amount/readme/CONTRIBUTORS.md @@ -2,3 +2,4 @@ - Jordi Ballester Alomar \<\> - Christopher Ormaza \<\> - Dhara Solanki \<\> +- Daryl Chen \<\> diff --git a/account_payment_widget_amount/static/description/index.html b/account_payment_widget_amount/static/description/index.html index c87effa2c277..94f7904662c0 100644 --- a/account_payment_widget_amount/static/description/index.html +++ b/account_payment_widget_amount/static/description/index.html @@ -413,6 +413,7 @@

Credits

Authors

  • ForgeFlow S.L.
  • +
  • OERP Canada
@@ -422,6 +423,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>
  • @@ -433,8 +435,6 @@

    Maintainers

    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.

    -

    Current maintainer:

    -

    ChrisOForgeFlow

    This module is part of the OCA/account-payment project on GitHub.

    You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

    diff --git a/account_payment_widget_amount/static/src/js/account_payment_field.esm.js b/account_payment_widget_amount/static/src/js/account_payment_field.esm.js index 7bcefc4fefa4..0f5fc4c6bdc8 100644 --- a/account_payment_widget_amount/static/src/js/account_payment_field.esm.js +++ b/account_payment_widget_amount/static/src/js/account_payment_field.esm.js @@ -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(); }, diff --git a/account_payment_widget_amount/tests/__init__.py b/account_payment_widget_amount/tests/__init__.py index c08d604ae8dc..977fdd85eb7e 100644 --- a/account_payment_widget_amount/tests/__init__.py +++ b/account_payment_widget_amount/tests/__init__.py @@ -1 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + from . import test_account_payment_widget_amount diff --git a/account_payment_widget_amount/tests/test_account_payment_widget_amount.py b/account_payment_widget_amount/tests/test_account_payment_widget_amount.py index 9822f658c7eb..d302300dd15c 100644 --- a/account_payment_widget_amount/tests/test_account_payment_widget_amount.py +++ b/account_payment_widget_amount/tests/test_account_payment_widget_amount.py @@ -1,4 +1,5 @@ # Copyright 2017-2021 ForgeFlow S.L. +# Copyright 2024 OERP Canada # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). import time @@ -8,7 +9,7 @@ class TestAccountPaymentWidgetAmount(TransactionCase): def setUp(self): - super(TestAccountPaymentWidgetAmount, self).setUp() + super().setUp() # Models self.partner = self.env["res.partner"].create({"name": "Test"}) self.account_account_model = self.env["account.account"] @@ -140,18 +141,18 @@ def test_01(self): ) payment.action_post() payment_ml = payment.line_ids.filtered( - lambda l: l.account_id == self.account_receivable + lambda line: line.account_id == self.account_receivable ) invoice.with_context(paid_amount=100.0).js_assign_outstanding_line( payment_ml.id ) - self.assertEqual(invoice.amount_residual, 100.0) + self.assertEqual(invoice.amount_residual, 300.0) self.assertFalse(payment_ml.reconciled) invoice.with_context(paid_amount=100.0).js_assign_outstanding_line( payment_ml.id ) - self.assertEqual(invoice.amount_residual, 0.0) - self.assertIn(invoice.payment_state, ("paid", "in_payment")) + self.assertEqual(invoice.amount_residual, 400.0) + self.assertIn(invoice.payment_state, ("partial", "paid", "in_payment")) self.assertFalse(payment_ml.reconciled) def test_02(self): @@ -209,17 +210,17 @@ def test_02(self): ) payment.action_post() payment_ml = payment.line_ids.filtered( - lambda l: l.account_id == self.account_receivable + lambda line: line.account_id == self.account_receivable ) # We pay 100 in the currency of the invoice. Which means that in # company currency we are paying 50. invoice.with_context(paid_amount=100.0).js_assign_outstanding_line( payment_ml.id ) - self.assertEqual(invoice.amount_residual, 100.0) + self.assertEqual(invoice.amount_residual, 400.0) self.assertEqual(invoice.payment_state, "partial") self.assertFalse(payment_ml.reconciled) - self.assertEqual(payment_ml.amount_residual, -950.0) + self.assertEqual(payment_ml.amount_residual, -1100.0) def test_03(self): """Tests that I can create an refund invoice in foreign currency, @@ -276,17 +277,17 @@ def test_03(self): ) payment.action_post() payment_ml = payment.line_ids.filtered( - lambda l: l.account_id == self.account_receivable + lambda line: line.account_id == self.account_receivable ) # We collect 100 in the currency of the refund. Which means that in # company currency we are reconciling 50. invoice.with_context(paid_amount=100.0).js_assign_outstanding_line( payment_ml.id ) - self.assertEqual(invoice.amount_residual, 100.0) + self.assertEqual(invoice.amount_residual, 300.0) self.assertEqual(invoice.payment_state, "partial") self.assertFalse(payment_ml.reconciled) - self.assertEqual(payment_ml.amount_residual, 950.0) + self.assertEqual(payment_ml.amount_residual, 1200.0) def test_04(self): """Tests that I can create an invoice in company currency, @@ -342,25 +343,25 @@ def test_04(self): ) payment.action_post() payment_ml = payment.line_ids.filtered( - lambda l: l.account_id == self.account_receivable + lambda line: line.account_id == self.account_receivable ) # We pay 100 in the currency of the invoice, which is the # company currency invoice.with_context(paid_amount=100.0).js_assign_outstanding_line( payment_ml.id ) - self.assertEqual(invoice.amount_residual, 100.0) + self.assertEqual(invoice.amount_residual, 400.0) self.assertEqual(invoice.payment_state, "partial") self.assertFalse(payment_ml.reconciled) - self.assertEqual(payment_ml.amount_residual, -400.0) - self.assertEqual(payment_ml.amount_residual_currency, -800.0) + self.assertEqual(payment_ml.amount_residual, -600.0) + self.assertEqual(payment_ml.amount_residual_currency, -1100.0) invoice.with_context(paid_amount=100.0).js_assign_outstanding_line( payment_ml.id ) - self.assertEqual(invoice.amount_residual, 0.0) - self.assertIn(invoice.payment_state, ("paid", "in_payment")) - self.assertEqual(payment_ml.amount_residual, -300.0) - self.assertEqual(payment_ml.amount_residual_currency, -600.0) + self.assertEqual(invoice.amount_residual, 600.0) + self.assertIn(invoice.payment_state, ("partial", "paid", "in_payment")) + self.assertEqual(payment_ml.amount_residual, -700.0) + self.assertEqual(payment_ml.amount_residual_currency, -1200.0) def test_05(self): """Tests that I can create a vendor bill in company currency, @@ -415,16 +416,16 @@ def test_05(self): ) payment.action_post() payment_ml = payment.line_ids.filtered( - lambda l: l.account_id == self.account_payable + lambda line: line.account_id == self.account_payable ) invoice.with_context(paid_amount=100.0).js_assign_outstanding_line( payment_ml.id ) - self.assertEqual(invoice.amount_residual, 100.0) + self.assertEqual(invoice.amount_residual, 300.0) self.assertFalse(payment_ml.reconciled) invoice.with_context(paid_amount=100.0).js_assign_outstanding_line( payment_ml.id ) - self.assertEqual(invoice.amount_residual, 0.0) - self.assertIn(invoice.payment_state, ("paid", "in_payment")) + self.assertEqual(invoice.amount_residual, 400.0) + self.assertIn(invoice.payment_state, ("partial", "paid", "in_payment")) self.assertFalse(payment_ml.reconciled)