diff --git a/account_commission/README.rst b/account_commission/README.rst index 7b841fca9..f36cea245 100644 --- a/account_commission/README.rst +++ b/account_commission/README.rst @@ -2,7 +2,7 @@ Account commissions =================== -.. +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! @@ -133,6 +133,7 @@ Contributors - Pedro M. Baeza - Manuel Calero + - Sergio Teruel - `Quartile `__: @@ -166,7 +167,7 @@ promote its widespread use. Current `maintainer `__: -|maintainer-pedrobaeza| +|maintainer-pedrobaeza| This module is part of the `OCA/commission `_ project on GitHub. diff --git a/account_commission/readme/CONTRIBUTORS.rst b/account_commission/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..720c33db6 --- /dev/null +++ b/account_commission/readme/CONTRIBUTORS.rst @@ -0,0 +1,21 @@ +* Pexego. +* Davide Corio +* Joao Alfredo Gama Batista +* Sandy Carter +* Giorgio Borelli +* Daniel Campos +* Oihane Crucelaegui +* Nicola Malcontenti +* Aitor Bouzas +* Alexei Rivera + +* `Tecnativa `__: + + * Pedro M. Baeza + * Manuel Calero + * Sergio Teruel + +* `Quartile `__: + + * Aung Ko Ko Lin + * Yoshi Tashiro diff --git a/account_commission/static/description/index.html b/account_commission/static/description/index.html index e32f50484..f7f521cb6 100644 --- a/account_commission/static/description/index.html +++ b/account_commission/static/description/index.html @@ -366,7 +366,7 @@

Account commissions

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:0fb13edf183d9d1ecf7c4415929fabd687f91bd51e719c0e149a7148c57da4ef +!! source digest: sha256:5788ea4c8f7cbff1e1296b584c797d90bca62e947922efbccef2b06e5dcc79b6 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

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

This module adds the function to calculate commissions in invoices @@ -479,6 +479,7 @@

Contributors

  • Tecnativa:
    • Pedro M. Baeza
    • Manuel Calero
    • +
    • Sergio Teruel
  • Quartile:
      diff --git a/account_commission/tests/test_account_commission.py b/account_commission/tests/test_account_commission.py index 203421216..c02476aad 100644 --- a/account_commission/tests/test_account_commission.py +++ b/account_commission/tests/test_account_commission.py @@ -7,7 +7,7 @@ from odoo import fields from odoo.exceptions import UserError, ValidationError -from odoo.tests import tagged +from odoo.tests import Form, tagged from odoo.addons.commission.tests.test_commission import TestCommissionBase @@ -532,3 +532,162 @@ def test_multi_currency(self): ] ) self.assertEqual(2, len(settlements)) + + def test_invoice_partial_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", + "journal_id": invoice.journal_id.id, + } + ) + ) + refund_form = Form( + self.env["account.move"].browse(move_reversal.reverse_moves()["res_id"]) + ) + with refund_form.invoice_line_ids.edit(0) as line: + line.price_unit -= 2 + refund = refund_form.save() + 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", + "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", + "journal_id": invoice.journal_id.id, + } + ) + ) + invoice2_form = Form( + self.env["account.move"].browse(move_reversal.reverse_moves()["res_id"]) + ) + with invoice2_form.invoice_line_ids.edit(0) as line: + line.price_unit -= 2 + invoice2 = invoice2_form.save() + 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.assertAlmostEqual(0.6, sum(settlements.mapped("total")), 2) + + def _register_payment(self, invoice): + payment_journal = self.env["account.journal"].search( + [("type", "=", "cash"), ("company_id", "=", self.env.company.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() + + def test_invoice_pending_settlement(self): + """Make in one settlement all pending invoices to wizard date""" + fields.Date.today() + self.commission_net_paid.invoice_state = "paid" + invoice1 = self._create_invoice( + self.agent_pending, self.commission_net_paid, "2024-02-15", currency=None + ) + # Register payment for the new invoice + invoice2 = self._create_invoice( + self.agent_pending, self.commission_net_paid, "2024-03-15", currency=None + ) + invoice3 = self._create_invoice( + self.agent_pending, self.commission_net_paid, "2024-04-15", currency=None + ) + # invoice1.invoice_line_ids.agent_ids._compute_amount() + (invoice1 + invoice2 + invoice3).action_post() + self._register_payment(invoice1) + self._register_payment(invoice2) + self._register_payment(invoice3) + self._settle_agent_invoice(self.agent_pending, 1) + settlements = self.settle_model.search([("state", "=", "settled")]) + self.assertEqual(len(settlements.line_ids), 3) diff --git a/commission/README.rst b/commission/README.rst index 031cec49a..735335852 100644 --- a/commission/README.rst +++ b/commission/README.rst @@ -2,7 +2,7 @@ Commissions =========== -.. +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! @@ -156,6 +156,7 @@ Contributors - Pedro M. Baeza - Manuel Calero + - Sergio Teruel - `Quartile `__: @@ -185,7 +186,7 @@ promote its widespread use. Current `maintainer `__: -|maintainer-pedrobaeza| +|maintainer-pedrobaeza| This module is part of the `OCA/commission `_ project on GitHub. diff --git a/commission/models/res_partner.py b/commission/models/res_partner.py index 605ba0151..d97994843 100644 --- a/commission/models/res_partner.py +++ b/commission/models/res_partner.py @@ -43,6 +43,7 @@ class ResPartner(models.Model): ("quaterly", "Quarterly"), ("semi", "Semi-annual"), ("annual", "Annual"), + ("pending", "Pending commissions"), ], string="Settlement period", default="monthly", diff --git a/commission/readme/CONTRIBUTORS.rst b/commission/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..720c33db6 --- /dev/null +++ b/commission/readme/CONTRIBUTORS.rst @@ -0,0 +1,21 @@ +* Pexego. +* Davide Corio +* Joao Alfredo Gama Batista +* Sandy Carter +* Giorgio Borelli +* Daniel Campos +* Oihane Crucelaegui +* Nicola Malcontenti +* Aitor Bouzas +* Alexei Rivera + +* `Tecnativa `__: + + * Pedro M. Baeza + * Manuel Calero + * Sergio Teruel + +* `Quartile `__: + + * Aung Ko Ko Lin + * Yoshi Tashiro diff --git a/commission/static/description/index.html b/commission/static/description/index.html index 3a06ff2a2..7b72785a8 100644 --- a/commission/static/description/index.html +++ b/commission/static/description/index.html @@ -366,7 +366,7 @@

      Commissions

      !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:0f54149f86b86660382708274a8cb05ec4cabea68b0ede1531e0147bb309d5ab +!! source digest: sha256:40d29c55743992c85878e87e4534c3ea18a1fc387a8fc20cbbde1b529abce7c0 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

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

      This module provides the base functions for commission operations to @@ -506,6 +506,7 @@

      Contributors

    • Tecnativa:
      • Pedro M. Baeza
      • Manuel Calero
      • +
      • Sergio Teruel
    • Quartile:
        diff --git a/commission/tests/test_commission.py b/commission/tests/test_commission.py index ac169937e..db6f5ead6 100644 --- a/commission/tests/test_commission.py +++ b/commission/tests/test_commission.py @@ -107,6 +107,14 @@ def setUpClass(cls): "lang": "en_US", } ) + cls.agent_pending = cls.res_partner_model.create( + { + "name": "Test Agent - Pending", + "agent": True, + "settlement": "pending", + "lang": "en_US", + } + ) # Expected to be used in inheriting modules. def _get_make_settle_vals(self, agent=None, period=None, date=None): diff --git a/commission/wizards/commission_make_settle.py b/commission/wizards/commission_make_settle.py index 22def3aa2..f5555cac0 100644 --- a/commission/wizards/commission_make_settle.py +++ b/commission/wizards/commission_make_settle.py @@ -49,6 +49,8 @@ def _get_period_start(self, agent, date_to): return date(month=1, year=date_to.year, day=1) elif agent.settlement == "annual": return date(month=1, year=date_to.year, day=1) + elif agent.settlement == "pending": + return date(month=date_to.month, year=date_to.year, day=date_to.day) def _get_next_period_date(self, agent, current_date): if agent.settlement == "monthly": @@ -66,6 +68,10 @@ def _get_next_period_date(self, agent, current_date): return current_date + relativedelta(months=6) elif agent.settlement == "annual": return current_date + relativedelta(years=1) + elif agent.settlement == "pending": + return date( + month=self.date_to.month, year=self.date_to.year, day=self.date_to.day + ) def _get_settlement(self, agent, company, currency, sett_from, sett_to): self.ensure_one() @@ -97,7 +103,7 @@ def _prepare_settlement_line_vals(self, settlement, line): "settlement_id": settlement.id, } - def _get_agent_lines(self, date_to_agent): + def _get_agent_lines(self, agent, date_to_agent): """Need to be extended according to settlement_type.""" raise NotImplementedError()