Skip to content

Commit 50f6a32

Browse files
author
matteo.tognini
committed
[IMP]account_commission: possibility to add payment date limit on settle commissions
1 parent 6ad15f0 commit 50f6a32

5 files changed

Lines changed: 54 additions & 8 deletions

File tree

account_commission/__manifest__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"views/report_settlement_templates.xml",
2424
"report/commission_analysis_view.xml",
2525
"wizards/wizard_invoice.xml",
26+
"wizards/commission_make_settle_views.xml",
2627
],
2728
"installable": True,
2829
}

account_commission/models/account_move.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,30 @@ def _skip_settlement(self):
251251
:return: bool
252252
"""
253253
self.ensure_one()
254+
payment_based_commission = (
255+
True if self.commission_id.invoice_state == "paid" else False
256+
)
257+
if payment_based_commission and self._skip_future_payments():
258+
return True
254259
return (
255-
self.commission_id.invoice_state == "paid"
260+
payment_based_commission
256261
and self.invoice_id.payment_state not in ["in_payment", "paid", "reversed"]
257262
) or self.invoice_id.state != "posted"
263+
264+
def _skip_future_payments(self):
265+
date_payment_to = self.env.context.get("date_payment_to")
266+
if date_payment_to:
267+
payments_dates = []
268+
(
269+
invoice_partials,
270+
exchange_diff_moves,
271+
) = self.invoice_id._get_reconciled_invoices_partials()
272+
for (
273+
_partial,
274+
_amount,
275+
counterpart_line,
276+
) in invoice_partials:
277+
payments_dates.append(counterpart_line.date)
278+
if any(date_payment_to < date for date in payments_dates):
279+
return True
280+
return False

account_commission/static/description/index.html

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88

99
/*
1010
:Author: David Goodger (goodger@python.org)
11-
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
11+
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
1212
:Copyright: This stylesheet has been placed in the public domain.
1313
1414
Default cascading style sheet for the HTML output of Docutils.
15-
Despite the name, some widely supported CSS2 features are used.
1615
1716
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
1817
customize this style sheet.
@@ -275,7 +274,7 @@
275274
margin-left: 2em ;
276275
margin-right: 2em }
277276

278-
pre.code .ln { color: gray; } /* line numbers */
277+
pre.code .ln { color: grey; } /* line numbers */
279278
pre.code, code { background-color: #eeeeee }
280279
pre.code .comment, code .comment { color: #5C6576 }
281280
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@@ -301,7 +300,7 @@
301300
span.pre {
302301
white-space: pre }
303302

304-
span.problematic, pre.problematic {
303+
span.problematic {
305304
color: red }
306305

307306
span.section-subtitle {
@@ -491,9 +490,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
491490
<div class="section" id="maintainers">
492491
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
493492
<p>This module is maintained by the OCA.</p>
494-
<a class="reference external image-reference" href="https://odoo-community.org">
495-
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
496-
</a>
493+
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
497494
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
498495
mission is to support the collaborative development of Odoo features and
499496
promote its widespread use.</p>

account_commission/wizards/commission_make_settle.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ class CommissionMakeSettle(models.TransientModel):
1313
selection_add=[("sale_invoice", "Sales Invoices")],
1414
ondelete={"sale_invoice": "cascade"},
1515
)
16+
date_payment_to = fields.Date(
17+
"Payment date up to",
18+
help="For payment-based commissions, settlements will be created for payments \
19+
with date up to the one set in this field.",
20+
default=fields.Date.today,
21+
)
1622

1723
def _get_account_settle_domain(self, agent, date_to_agent):
1824
return [
@@ -46,3 +52,9 @@ def _prepare_settlement_line_vals(self, settlement, line):
4652
}
4753
)
4854
return res
55+
56+
def action_settle(self):
57+
context_date_payment = self.env.context.copy()
58+
context_date_payment["date_payment_to"] = self.date_payment_to
59+
self.env.context = context_date_payment
60+
return super().action_settle()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<odoo>
3+
<record id="view_commission_make_settle_date_payment" model="ir.ui.view">
4+
<field name="name">commission.make.settle.date.payment</field>
5+
<field name="model">commission.make.settle</field>
6+
<field name="inherit_id" ref="commission.view_settled_wizard" />
7+
<field name="arch" type="xml">
8+
<field name="date_to" position="after">
9+
<field name="date_payment_to" />
10+
</field>
11+
</field>
12+
</record>
13+
</odoo>

0 commit comments

Comments
 (0)