Skip to content

Commit

Permalink
[IMP] l10n_it_riba_sale_commission: Settle based on RiBa due date
Browse files Browse the repository at this point in the history
  • Loading branch information
SirAionTech committed Dec 9, 2024
1 parent 7949bbe commit a3b9746
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 18 deletions.
18 changes: 18 additions & 0 deletions l10n_it_riba_sale_commission/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
===========

Expand Down
20 changes: 20 additions & 0 deletions l10n_it_riba_sale_commission/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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
9 changes: 9 additions & 0 deletions l10n_it_riba_sale_commission/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -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.
46 changes: 32 additions & 14 deletions l10n_it_riba_sale_commission/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
: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.
Expand Down Expand Up @@ -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 }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -401,41 +402,58 @@ <h1 class="title">ITA - Integrazione tra RiBa e provvigioni su vendite</h1>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-1">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-2">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-3">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-4">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-5">Maintainers</a></li>
<li><a class="reference internal" href="#configuration" id="toc-entry-1">Configuration</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-2">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-3">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-4">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-5">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-6">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="configuration">
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<p><strong>Italiano</strong></p>
<p>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”.</p>
<p><strong>English</strong></p>
<p>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.</p>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-1">Bug Tracker</a></h1>
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/l10n-italy/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/l10n-italy/issues/new?body=module:%20l10n_it_riba_sale_commission%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#toc-entry-2">Credits</a></h1>
<h1><a class="toc-backref" href="#toc-entry-3">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#toc-entry-3">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
<ul class="simple">
<li>Nextev Srl</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<ul class="simple">
<li>Nextev Srl &lt;<a class="reference external" href="mailto:odoo&#64;nextev.it">odoo&#64;nextev.it</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h2>
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<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>
Expand Down
58 changes: 54 additions & 4 deletions l10n_it_riba_sale_commission/tests/test_riba_sale_commission.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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(
{
Expand All @@ -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,
},
)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<field name="arch" type="xml">
<group id="header_right_group" position="inside">
<field name="no_commission" />
<field name="l10n_it_riba_commission_use_due_date" />
</group>
</field>
</record>
Expand Down
2 changes: 2 additions & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a3b9746

Please sign in to comment.