diff --git a/l10n_it_riba_sale_commission/README.rst b/l10n_it_riba_sale_commission/README.rst index 0c014e890f58..f2a601c8a9fc 100644 --- a/l10n_it_riba_sale_commission/README.rst +++ b/l10n_it_riba_sale_commission/README.rst @@ -69,6 +69,24 @@ way no agent commissions are generated. .. contents:: :local: +Configuration +============= + +**Italiano** + +Quando lo "Stato fattura" del tipo di provvigione è "Basato su data +pagamento", la provvigione verrà liquidata in base alla data di scadenza +della RiBa. Se per una fattura invece si vuole invece usare la data del +pagamento, nella fattura disabilitare "Usare data scadenza RiBa per le +commissioni". + +**English** + +When the "Invoice Status" of the commission type is "Payment Date +Based", the commission will be settled based on the RiBa due date. If +you want to use the payment date instead, disable "Use RiBa due date for +commissions" in the invoice. + Bug Tracker =========== diff --git a/l10n_it_riba_sale_commission/models/account_move.py b/l10n_it_riba_sale_commission/models/account_move.py index 412fc4fe81bf..907595fbe87c 100644 --- a/l10n_it_riba_sale_commission/models/account_move.py +++ b/l10n_it_riba_sale_commission/models/account_move.py @@ -9,6 +9,12 @@ class AccountMove(models.Model): _inherit = "account.move" no_commission = fields.Boolean(string="Without commissions") + l10n_it_riba_commission_use_due_date = fields.Boolean( + string="Use RiBa due date for commission", + help="When commission is set for invoice status 'Payment Date Based', " + "use the corresponding RiBa's due date instead of the payment date.", + default=True, + ) def _get_reconciled_invoices_partials(self): """ @@ -62,3 +68,17 @@ def _skip_future_payments(self, date_payment_to): if dates: return date_payment_to < max(dates) return super()._skip_future_payments(date_payment_to) + + def _get_commission_settlement_date(self): + commission_settlement_date = super()._get_commission_settlement_date() + if ( + self.commission_id.invoice_state == "paid_date" + and self.invoice_id.l10n_it_riba_commission_use_due_date + ): + # Assume that the invoice will be paid when all the RiBas are due + riba_lines = self.object_id.move_id.line_ids.slip_line_ids + commission_settlement_date = max( + riba_lines.riba_line_id.mapped("due_date"), + default=date.min, + ) + return commission_settlement_date diff --git a/l10n_it_riba_sale_commission/readme/CONFIGURE.md b/l10n_it_riba_sale_commission/readme/CONFIGURE.md new file mode 100644 index 000000000000..7b8151603512 --- /dev/null +++ b/l10n_it_riba_sale_commission/readme/CONFIGURE.md @@ -0,0 +1,9 @@ +**Italiano** + +Quando lo "Stato fattura" del tipo di provvigione è "Basato su data pagamento", la provvigione verrà liquidata in base alla data di scadenza della RiBa. +Se per una fattura invece si vuole invece usare la data del pagamento, nella fattura disabilitare "Usare data scadenza RiBa per le commissioni". + +**English** + +When the "Invoice Status" of the commission type is "Payment Date Based", the commission will be settled based on the RiBa due date. +If you want to use the payment date instead, disable "Use RiBa due date for commissions" in the invoice. diff --git a/l10n_it_riba_sale_commission/static/description/index.html b/l10n_it_riba_sale_commission/static/description/index.html index d16bbcb362d8..2cee35e43c6a 100644 --- a/l10n_it_riba_sale_commission/static/description/index.html +++ b/l10n_it_riba_sale_commission/static/description/index.html @@ -8,10 +8,11 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ +:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. +Despite the name, some widely supported CSS2 features are used. See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to customize this style sheet. @@ -274,7 +275,7 @@ margin-left: 2em ; margin-right: 2em } -pre.code .ln { color: grey; } /* line numbers */ +pre.code .ln { color: gray; } /* line numbers */ pre.code, code { background-color: #eeeeee } pre.code .comment, code .comment { color: #5C6576 } pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } @@ -300,7 +301,7 @@ span.pre { white-space: pre } -span.problematic { +span.problematic, pre.problematic { color: red } span.section-subtitle { @@ -401,17 +402,32 @@

ITA - Integrazione tra RiBa e provvigioni su vendite

Table of contents

+
+

Configuration

+

Italiano

+

Quando lo “Stato fattura” del tipo di provvigione è “Basato su data +pagamento”, la provvigione verrà liquidata in base alla data di scadenza +della RiBa. Se per una fattura invece si vuole invece usare la data del +pagamento, nella fattura disabilitare “Usare data scadenza RiBa per le +commissioni”.

+

English

+

When the “Invoice Status” of the commission type is “Payment Date +Based”, the commission will be settled based on the RiBa due date. If +you want to use the payment date instead, disable “Use RiBa due date for +commissions” in the invoice.

+
-

Bug Tracker

+

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed @@ -419,23 +435,25 @@

Bug Tracker

Do not contact contributors directly about support or help with technical issues.

-

Credits

+

Credits

-

Authors

+

Authors

-

Contributors

+

Contributors

-

Maintainers

+

Maintainers

This module is maintained by the OCA.

-Odoo Community Association + +Odoo Community Association +

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.

diff --git a/l10n_it_riba_sale_commission/tests/test_riba_sale_commission.py b/l10n_it_riba_sale_commission/tests/test_riba_sale_commission.py index 21cd70acb352..8bcbc5a2b858 100644 --- a/l10n_it_riba_sale_commission/tests/test_riba_sale_commission.py +++ b/l10n_it_riba_sale_commission/tests/test_riba_sale_commission.py @@ -6,7 +6,7 @@ from dateutil.relativedelta import relativedelta from odoo import fields -from odoo.tests.common import TransactionCase +from odoo.tests.common import Form, TransactionCase class TestRibaCommission(TransactionCase): @@ -129,6 +129,7 @@ def setUpClass(cls): "past_due_journal_id": cls.bank_journal.id, "overdue_effects_account_id": cls.unsolved_account.id, "protest_charge_account_id": cls.expenses_account.id, + "settlement_journal_id": cls.bank_journal.id, } ) cls.company = cls.env.ref("base.main_company") @@ -170,7 +171,9 @@ def setUpClass(cls): } ) - def _create_invoice(self, inv_date, payment_term, commission): + def _create_invoice(self, inv_date, payment_term, commission, agent=None): + if agent is None: + agent = self.agent_monthly self.partner.property_account_receivable_id = self.account_rec1_id.id return self.env["account.move"].create( { @@ -195,7 +198,7 @@ def _create_invoice(self, inv_date, payment_term, commission): 0, 0, { - "agent_id": self.agent_monthly.id, + "agent_id": agent.id, "commission_id": commission.id, }, ) @@ -271,7 +274,7 @@ def _settle_agent(self, agent=None, period=None, date=None, date_payment_to=None wizard = self.make_settle_model.create(vals) wizard.action_settle() - def register_payment(self, invoice): + def register_payment(self, invoice, payment_date=None): invoice.action_post() wizard_riba_issue = self.env["riba.issue"].create( @@ -304,6 +307,17 @@ def register_payment(self, invoice): ) wiz_accreditation.create_move() + payment_wizard_action = riba_list.settle_all_line() + payment_wizard_form = Form( + self.env[payment_wizard_action["res_model"]].with_context( + **payment_wizard_action["context"] + ) + ) + if payment_date: + payment_wizard_form.payment_date = payment_date + payment_wizard = payment_wizard_form.save() + payment_wizard.pay() + def test_riba_settlement(self): date = fields.Date.today() invoice = self._create_invoice( @@ -346,3 +360,39 @@ def test_riba_partial_settlement(self): ] ) self.assertEqual(0, len(settlements)) + + def test_settle_invoice_on_payment_date(self): + """When commission is "Payment Date Based", + the commission is settled based on the due date of the RiBa line. + """ + # Arrange + commission = self.commission_model.create( + { + "name": "20% based on payment date", + "fix_qty": 20.0, + "amount_base_type": "net_amount", + "invoice_state": "paid_date", + } + ) + agent = self.agent_monthly + agent.commission_id = commission + invoice = self._create_invoice( + "2020-01-15", + self.payment_term, + commission, + agent=agent, + ) + self.register_payment( + invoice, + payment_date="2020-02-15", + ) + + # Act + self._settle_agent(agent=agent, date="2020-02-01") + january_settlement = self.settle_model.search([("state", "=", "settled")]) + self._settle_agent(agent=agent, date="2020-03-01") + february_settlement = self.settle_model.search([("state", "=", "settled")]) + + # Assert + self.assertFalse(january_settlement) + self.assertEqual(invoice, february_settlement.line_ids.invoice_line_id.move_id) diff --git a/l10n_it_riba_sale_commission/views/invoice_no_commission.xml b/l10n_it_riba_sale_commission/views/invoice_no_commission.xml index 81f4cafc785a..4bb4178490e3 100644 --- a/l10n_it_riba_sale_commission/views/invoice_no_commission.xml +++ b/l10n_it_riba_sale_commission/views/invoice_no_commission.xml @@ -7,6 +7,7 @@ + diff --git a/test-requirements.txt b/test-requirements.txt index 55830e184191..9567c1889621 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1 +1,3 @@ odoo-addon-sale_commission_partial_settlement @ git+https://github.com/OCA/commission.git@refs/pull/561/head#subdirectory=setup/sale_commission_partial_settlement +# https://github.com/OCA/commission/pull/581 +odoo-addon-account_commission @ git+https://github.com/OCA/commission.git@refs/pull/581/head#subdirectory=setup/account_commission