Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0[IMP]account_commission: add payment date limit on settle commissions #588

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
}
23 changes: 22 additions & 1 deletion account_commission/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,28 @@
:return: bool
"""
self.ensure_one()
payment_based_commission = self.commission_id.invoice_state == "paid"
if payment_based_commission and 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"
payment_based_commission
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 (goodger@python.org)
: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>
Loading