From 305051eafccbf752b115c2e5fb4feaf2b8bed731 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberto=20Mart=C3=ADnez?= Date: Mon, 19 Feb 2024 17:29:45 +0100 Subject: [PATCH 1/4] [15.0][FIX]account_commission: Settlement on reversed moves --- account_commission/README.rst | 6 +- account_commission/models/account_move.py | 2 +- account_commission/models/commission.py | 2 +- account_commission/readme/CONFIGURE.rst | 4 +- .../static/description/index.html | 7 +- .../tests/test_account_commission.py | 143 ++++++++++++++++++ 6 files changed, 157 insertions(+), 7 deletions(-) diff --git a/account_commission/README.rst b/account_commission/README.rst index 637fb1856..1812e9d7b 100644 --- a/account_commission/README.rst +++ b/account_commission/README.rst @@ -7,7 +7,7 @@ Account commissions !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:68f1a6945b770a30a14a0891c944d8d205676022c1fe5ff33968ab47fa9a2b22 + !! source digest: sha256:2870408c1c2aa0c64c0f8c4660ea6b857375d8fd7e87970232b90368b913305c !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png @@ -47,7 +47,9 @@ For selecting invoice status in commissions: #. Edit or create a new record to select the invoice status for settling the commissions. * **Invoice Based**: Commissions are settled when the invoice is issued. - * **Payment Based**: Commissions are settled when the invoice is paid. + * **Payment Based**: Commissions are settled when the invoice is paid or refunded. + Note that when refunding an invoice, the corresponding reversed commission will + be settled as well, resulting in a 0 net commission between both operations. Usage ===== diff --git a/account_commission/models/account_move.py b/account_commission/models/account_move.py index 30b118bc7..faea90f7e 100644 --- a/account_commission/models/account_move.py +++ b/account_commission/models/account_move.py @@ -255,5 +255,5 @@ def _skip_settlement(self): self.ensure_one() return ( self.commission_id.invoice_state == "paid" - and self.invoice_id.payment_state not in ["in_payment", "paid"] + and self.invoice_id.payment_state not in ["in_payment", "paid", "reversed"] ) or self.invoice_id.state != "posted" diff --git a/account_commission/models/commission.py b/account_commission/models/commission.py index 5367c96db..964bf63bb 100644 --- a/account_commission/models/commission.py +++ b/account_commission/models/commission.py @@ -12,5 +12,5 @@ class Commission(models.Model): default="open", help="Select the invoice status for settling the commissions:\n" "* 'Invoice Based': Commissions are settled when the invoice is issued.\n" - "* 'Payment Based': Commissions are settled when the invoice is paid.", + "* 'Payment Based': Commissions are settled when the invoice is paid (or refunded).", ) diff --git a/account_commission/readme/CONFIGURE.rst b/account_commission/readme/CONFIGURE.rst index 78d97059d..04e0739b6 100644 --- a/account_commission/readme/CONFIGURE.rst +++ b/account_commission/readme/CONFIGURE.rst @@ -3,4 +3,6 @@ For selecting invoice status in commissions: #. Edit or create a new record to select the invoice status for settling the commissions. * **Invoice Based**: Commissions are settled when the invoice is issued. - * **Payment Based**: Commissions are settled when the invoice is paid. + * **Payment Based**: Commissions are settled when the invoice is paid or refunded. + Note that when refunding an invoice, the corresponding reversed commission will + be settled as well, resulting in a 0 net commission between both operations. diff --git a/account_commission/static/description/index.html b/account_commission/static/description/index.html index 9802f1f30..40ade244c 100644 --- a/account_commission/static/description/index.html +++ b/account_commission/static/description/index.html @@ -1,3 +1,4 @@ + @@ -366,7 +367,7 @@

Account commissions

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:68f1a6945b770a30a14a0891c944d8d205676022c1fe5ff33968ab47fa9a2b22 +!! source digest: sha256:2870408c1c2aa0c64c0f8c4660ea6b857375d8fd7e87970232b90368b913305c !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Beta License: AGPL-3 OCA/commission Translate me on Weblate Try me on Runboat

This module adds the function to calculate commissions in invoices (account moves).

@@ -392,7 +393,9 @@

Configuration

  1. Edit or create a new record to select the invoice status for settling the commissions.
    • Invoice Based: Commissions are settled when the invoice is issued.
    • -
    • Payment Based: Commissions are settled when the invoice is paid.
    • +
    • Payment Based: Commissions are settled when the invoice is paid or refunded. +Note that when refunding an invoice, the corresponding reversed commission will +be settled as well, resulting in a 0 net commission between both operations.
diff --git a/account_commission/tests/test_account_commission.py b/account_commission/tests/test_account_commission.py index 14ab83f91..96588464a 100644 --- a/account_commission/tests/test_account_commission.py +++ b/account_commission/tests/test_account_commission.py @@ -497,3 +497,146 @@ def test_multi_currency(self): ] ) self.assertEqual(2, len(settlements)) + + def test_invoice_parcial_refund(self): + commission = self.commission_net_paid + agent = self.agent_monthly + today = fields.Date.today() + # Create an invoice + invoice = self._create_invoice(agent, commission, today, currency=None) + invoice.action_post() + # Register payment for invoice + payment_journal = self.env["account.journal"].search( + [("type", "=", "cash"), ("company_id", "=", invoice.company_id.id)], + limit=1, + ) + register_payments = ( + self.env["account.payment.register"] + .with_context(active_ids=invoice.id, active_model="account.move") + .create({"journal_id": payment_journal.id}) + ) + register_payments.action_create_payments() + # Make a parcial refund for the invoice + move_reversal = ( + self.env["account.move.reversal"] + .with_context(active_model="account.move", active_ids=invoice.id) + .create( + { + "reason": "no reason", + "refund_method": "refund", + "journal_id": invoice.journal_id.id, + } + ) + ) + refund = self.env["account.move"].browse( + move_reversal.reverse_moves()["res_id"] + ) + refund.write( + { + "invoice_line_ids": [ + ( + 1, + refund.invoice_line_ids[:1].id, + {"price_unit": refund.invoice_line_ids[:1].price_unit - 2}, + ) + ] + } + ) + refund.action_post() + # Register payment for the refund + register_payments = ( + self.env["account.payment.register"] + .with_context(active_ids=refund.id, active_model="account.move") + .create({"journal_id": payment_journal.id}) + ) + register_payments.action_create_payments() + # check settlement creation. The commission must be (5 - 3) * 0.1 = 0.4 + self._settle_agent_invoice(agent, 1) + settlements = self.settle_model.search([("agent_id", "=", agent.id)]) + self.assertEqual(2, len(settlements.line_ids)) + self.assertEqual(0.4, sum(settlements.mapped("total"))) + + def test_invoice_full_refund(self): + commission = self.commission_net_paid + agent = self.agent_monthly + today = fields.Date.today() + # Create an invoice and refund it + invoice = self._create_invoice(agent, commission, today, currency=None) + invoice.action_post() + move_reversal = ( + self.env["account.move.reversal"] + .with_context(active_model="account.move", active_ids=invoice.id) + .create( + { + "reason": "no reason", + "refund_method": "cancel", + "journal_id": invoice.journal_id.id, + } + ) + ) + move_reversal.reverse_moves() + # check settlement creation. The commission must be: (5 - 5) * 0.1 = 0 + self._settle_agent_invoice(agent, 1) + settlements = self.settle_model.search( + [ + ("agent_id", "=", agent.id), + ] + ) + self.assertEqual(2, len(settlements.line_ids)) + self.assertEqual(0, sum(settlements.mapped("total"))) + + def test_invoice_modify_refund(self): + commission = self.commission_net_paid + agent = self.agent_monthly + today = fields.Date.today() + # Create an invoice + invoice = self._create_invoice(agent, commission, today, currency=None) + invoice.action_post() + # Create a full refund and a new invoice + move_reversal = ( + self.env["account.move.reversal"] + .with_context(active_model="account.move", active_ids=invoice.id) + .create( + { + "reason": "no reason", + "refund_method": "modify", + "journal_id": invoice.journal_id.id, + } + ) + ) + invoice2 = self.env["account.move"].browse( + move_reversal.reverse_moves()["res_id"] + ) + invoice2.write( + { + "invoice_line_ids": [ + ( + 1, + invoice2.invoice_line_ids[:1].id, + {"price_unit": invoice2.invoice_line_ids[:1].price_unit - 2}, + ) + ] + } + ) + invoice2.action_post() + # Register payment for the new invoice + payment_journal = self.env["account.journal"].search( + [("type", "=", "cash"), ("company_id", "=", invoice.company_id.id)], + limit=1, + ) + register_payments = ( + self.env["account.payment.register"] + .with_context(active_ids=invoice2.id, active_model="account.move") + .create({"journal_id": payment_journal.id}) + ) + register_payments.action_create_payments() + + # check settlement creation. The commission must be (5 - 5 + 3) * 0.1 = 0.6 + self._settle_agent_invoice(agent, 1) + settlements = self.settle_model.search( + [ + ("agent_id", "=", agent.id), + ] + ) + self.assertEqual(3, len(settlements.line_ids)) + self.assertEqual(0.6, sum(settlements.mapped("total"))) From 9dbd188a5afa8d8b463f46f19f22d5e143bc4538 Mon Sep 17 00:00:00 2001 From: oca-ci Date: Mon, 26 Feb 2024 18:18:07 +0000 Subject: [PATCH 2/4] [UPD] Update account_commission.pot --- account_commission/i18n/account_commission.pot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_commission/i18n/account_commission.pot b/account_commission/i18n/account_commission.pot index 5a4732518..725fcd9f6 100644 --- a/account_commission/i18n/account_commission.pot +++ b/account_commission/i18n/account_commission.pot @@ -424,7 +424,7 @@ msgstr "" msgid "" "Select the invoice status for settling the commissions:\n" "* 'Invoice Based': Commissions are settled when the invoice is issued.\n" -"* 'Payment Based': Commissions are settled when the invoice is paid." +"* 'Payment Based': Commissions are settled when the invoice is paid (or refunded)." msgstr "" #. module: account_commission From e0f7dfe79ca98ca288de1281f4f5162b335ac785 Mon Sep 17 00:00:00 2001 From: OCA-git-bot Date: Mon, 26 Feb 2024 18:22:30 +0000 Subject: [PATCH 3/4] [BOT] post-merge updates --- README.md | 2 +- account_commission/README.rst | 2 +- account_commission/__manifest__.py | 2 +- account_commission/static/description/index.html | 3 +-- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index bcbd48163..2c1539e34 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Available addons ---------------- addon | version | maintainers | summary --- | --- | --- | --- -[account_commission](account_commission/) | 15.0.3.2.0 | [![pedrobaeza](https://github.com/pedrobaeza.png?size=30px)](https://github.com/pedrobaeza) | Account commissions +[account_commission](account_commission/) | 15.0.3.2.1 | [![pedrobaeza](https://github.com/pedrobaeza.png?size=30px)](https://github.com/pedrobaeza) | Account commissions [commission](commission/) | 15.0.3.1.0 | [![pedrobaeza](https://github.com/pedrobaeza.png?size=30px)](https://github.com/pedrobaeza) | Commissions [commission_formula](commission_formula/) | 15.0.1.0.0 | | Commissions computed by formulas [hr_commission](hr_commission/) | 15.0.1.0.1 | | HR commissions diff --git a/account_commission/README.rst b/account_commission/README.rst index 1812e9d7b..5a2124691 100644 --- a/account_commission/README.rst +++ b/account_commission/README.rst @@ -7,7 +7,7 @@ Account commissions !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:2870408c1c2aa0c64c0f8c4660ea6b857375d8fd7e87970232b90368b913305c + !! source digest: sha256:2d1fc36a01e43ea64154a3aa40ad9f4284ad401f2e3ee88114020157480a49e7 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png diff --git a/account_commission/__manifest__.py b/account_commission/__manifest__.py index 120bdc4b2..189f2a05c 100644 --- a/account_commission/__manifest__.py +++ b/account_commission/__manifest__.py @@ -3,7 +3,7 @@ # Copyright 2014-2022 Tecnativa - Pedro M. Baeza { "name": "Account commissions", - "version": "15.0.3.2.0", + "version": "15.0.3.2.1", "author": "Tecnativa, Odoo Community Association (OCA)", "category": "Sales Management", "license": "AGPL-3", diff --git a/account_commission/static/description/index.html b/account_commission/static/description/index.html index 40ade244c..c3a6624b8 100644 --- a/account_commission/static/description/index.html +++ b/account_commission/static/description/index.html @@ -1,4 +1,3 @@ - @@ -367,7 +366,7 @@

Account commissions

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:2870408c1c2aa0c64c0f8c4660ea6b857375d8fd7e87970232b90368b913305c +!! source digest: sha256:2d1fc36a01e43ea64154a3aa40ad9f4284ad401f2e3ee88114020157480a49e7 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Beta License: AGPL-3 OCA/commission Translate me on Weblate Try me on Runboat

This module adds the function to calculate commissions in invoices (account moves).

From 8be2d7dfb587cf6dd477bc583d003b996823e7e9 Mon Sep 17 00:00:00 2001 From: Weblate Date: Mon, 26 Feb 2024 18:22:44 +0000 Subject: [PATCH 4/4] Update translation files Updated by "Update PO files to match POT (msgmerge)" hook in Weblate. Translation: commission-15.0/commission-15.0-account_commission Translate-URL: https://translation.odoo-community.org/projects/commission-15-0/commission-15-0-account_commission/ --- account_commission/i18n/es.po | 3 ++- account_commission/i18n/ja.po | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/account_commission/i18n/es.po b/account_commission/i18n/es.po index 8417b2fde..ba981087a 100644 --- a/account_commission/i18n/es.po +++ b/account_commission/i18n/es.po @@ -428,7 +428,8 @@ msgstr "Facturas de Venta" msgid "" "Select the invoice status for settling the commissions:\n" "* 'Invoice Based': Commissions are settled when the invoice is issued.\n" -"* 'Payment Based': Commissions are settled when the invoice is paid." +"* 'Payment Based': Commissions are settled when the invoice is paid (or " +"refunded)." msgstr "" #. module: account_commission diff --git a/account_commission/i18n/ja.po b/account_commission/i18n/ja.po index 29d1bc5ea..09e9bc3f8 100644 --- a/account_commission/i18n/ja.po +++ b/account_commission/i18n/ja.po @@ -427,7 +427,8 @@ msgstr "販売請求書" msgid "" "Select the invoice status for settling the commissions:\n" "* 'Invoice Based': Commissions are settled when the invoice is issued.\n" -"* 'Payment Based': Commissions are settled when the invoice is paid." +"* 'Payment Based': Commissions are settled when the invoice is paid (or " +"refunded)." msgstr "" #. module: account_commission