Skip to content

Commit

Permalink
[IMP]account_commission: possibility to add payment date limit on set…
Browse files Browse the repository at this point in the history
…tle commissions
  • Loading branch information
matteonext committed Dec 20, 2024
1 parent 6ad15f0 commit ba276da
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 7 deletions.
1 change: 1 addition & 0 deletions account_commission/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"views/report_settlement_templates.xml",
"report/commission_analysis_view.xml",
"wizards/wizard_invoice.xml",
"wizards/commission_make_settle_views.xml",
],
"installable": True,
}
21 changes: 21 additions & 0 deletions account_commission/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,28 @@ def _skip_settlement(self):
:return: bool
"""
self.ensure_one()
if self.commission_id.invoice_state == "paid":
if self._skip_future_payments():
return True

Check warning on line 256 in account_commission/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_commission/models/account_move.py#L256

Added line #L256 was not covered by tests
return (
self.commission_id.invoice_state == "paid"
and self.invoice_id.payment_state not in ["in_payment", "paid", "reversed"]
) or self.invoice_id.state != "posted"

def _skip_future_payments(self):
date_payment_to = self.env.context.get("date_payment_to")
if date_payment_to:
payments_dates = []
(
invoice_partials,
exchange_diff_moves,
) = self.invoice_id._get_reconciled_invoices_partials()
for (
_partial,
_amount,
counterpart_line,
) in invoice_partials:
payments_dates.append(counterpart_line.date)
if any(date_payment_to < date for date in payments_dates):
return True

Check warning on line 277 in account_commission/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_commission/models/account_move.py#L277

Added line #L277 was not covered by tests
return False
11 changes: 4 additions & 7 deletions account_commission/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@

/*
:Author: David Goodger ([email protected])
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z 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 @@ -275,7 +274,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: gray; } /* line numbers */
pre.code .ln { color: grey; } /* 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 @@ -301,7 +300,7 @@
span.pre {
white-space: pre }

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

span.section-subtitle {
Expand Down Expand Up @@ -491,9 +490,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-7">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
12 changes: 12 additions & 0 deletions account_commission/wizards/commission_make_settle.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ class CommissionMakeSettle(models.TransientModel):
selection_add=[("sale_invoice", "Sales Invoices")],
ondelete={"sale_invoice": "cascade"},
)
date_payment_to = fields.Date(
"Payment date up to",
help="For payment-based commissions, settlements will be created for payments \
with date up to the one set in this field.",
default=fields.Date.today,
)

def _get_account_settle_domain(self, agent, date_to_agent):
return [
Expand Down Expand Up @@ -46,3 +52,9 @@ def _prepare_settlement_line_vals(self, settlement, line):
}
)
return res

def action_settle(self):
context_date_payment = self.env.context.copy()
context_date_payment["date_payment_to"] = self.date_payment_to
self.env.context = context_date_payment
return super().action_settle()
13 changes: 13 additions & 0 deletions account_commission/wizards/commission_make_settle_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_commission_make_settle_date_payment" model="ir.ui.view">
<field name="name">commission.make.settle.date.payment</field>
<field name="model">commission.make.settle</field>
<field name="inherit_id" ref="commission.view_settled_wizard" />
<field name="arch" type="xml">
<field name="date_to" position="after">
<field name="date_payment_to" />
</field>
</field>
</record>
</odoo>

0 comments on commit ba276da

Please sign in to comment.