From 8a9338bee3d843390f29e0f6481dc52131b11ccd Mon Sep 17 00:00:00 2001 From: "matteo.tognini" Date: Fri, 20 Dec 2024 11:06:56 +0100 Subject: [PATCH] [IMP]account_commission: possibility to add payment date limit on settle commissions --- account_commission/__manifest__.py | 1 + account_commission/models/account_move.py | 23 ++++++++++++++++++- .../static/description/index.html | 11 ++++----- .../wizards/commission_make_settle.py | 12 ++++++++++ .../wizards/commission_make_settle_views.xml | 13 +++++++++++ 5 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 account_commission/wizards/commission_make_settle_views.xml diff --git a/account_commission/__manifest__.py b/account_commission/__manifest__.py index 2df9479c6..e2de22cbe 100644 --- a/account_commission/__manifest__.py +++ b/account_commission/__manifest__.py @@ -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, } diff --git a/account_commission/models/account_move.py b/account_commission/models/account_move.py index dc9fafc50..3a323d2ae 100644 --- a/account_commission/models/account_move.py +++ b/account_commission/models/account_move.py @@ -251,7 +251,28 @@ def _skip_settlement(self): :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 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 + return False diff --git a/account_commission/static/description/index.html b/account_commission/static/description/index.html index a600aa989..aa09f532f 100644 --- a/account_commission/static/description/index.html +++ b/account_commission/static/description/index.html @@ -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. @@ -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 } @@ -301,7 +300,7 @@ span.pre { white-space: pre } -span.problematic, pre.problematic { +span.problematic { color: red } span.section-subtitle { @@ -491,9 +490,7 @@

Contributors

Maintainers

This module is maintained by the OCA.

- -Odoo Community Association - +Odoo Community Association

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.

diff --git a/account_commission/wizards/commission_make_settle.py b/account_commission/wizards/commission_make_settle.py index 929d31f82..a90c3b8d7 100644 --- a/account_commission/wizards/commission_make_settle.py +++ b/account_commission/wizards/commission_make_settle.py @@ -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 [ @@ -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() diff --git a/account_commission/wizards/commission_make_settle_views.xml b/account_commission/wizards/commission_make_settle_views.xml new file mode 100644 index 000000000..26ce73851 --- /dev/null +++ b/account_commission/wizards/commission_make_settle_views.xml @@ -0,0 +1,13 @@ + + + + commission.make.settle.date.payment + commission.make.settle + + + + + + + +