[IMP] partner_statement: Allow to exclude accounts

This commit is contained in:
Simone Rubino
2025-05-05 18:28:29 +02:00
committed by Miquel Raïch
parent 965ea7d6ff
commit 795f9c60fe
6 changed files with 129 additions and 11 deletions

View File

@@ -4,6 +4,7 @@
from dateutil.relativedelta import relativedelta
from odoo import api, fields, models
from odoo.osv import expression
class StatementCommon(models.AbstractModel):
@@ -38,6 +39,44 @@ class StatementCommon(models.AbstractModel):
[("asset_receivable", "Receivable"), ("liability_payable", "Payable")],
default="asset_receivable",
)
excluded_accounts_selector = fields.Char(
string="Accounts to exclude",
help="Select account codes to be excluded "
"with a comma-separated list of expressions like 70%.",
)
@api.model
def _get_excluded_accounts_domain(self, selector):
"""Convert an account codes selector to a domain to search accounts.
The selector is a comma-separated list of expressions like 70%.
The algorithm is the same as
AccountingExpressionProcessor._account_codes_to_domain
of `mis_builder` module.
"""
if not selector:
selector = ""
domains = []
for account_code in selector.split(","):
account_code = account_code.strip()
if "%" in account_code:
domains.append(
[
("code", "=like", account_code),
]
)
else:
domains.append(
[
("code", "=", account_code),
]
)
return expression.OR(domains)
def _get_excluded_accounts(self):
self.ensure_one()
domain = self._get_excluded_accounts_domain(self.excluded_accounts_selector)
return self.env["account.account"].search(domain)
@api.onchange("aging_type")
def onchange_aging_type(self):
@@ -59,6 +98,7 @@ class StatementCommon(models.AbstractModel):
"account_type": self.account_type,
"aging_type": self.aging_type,
"filter_negative_balances": self.filter_negative_balances,
"excluded_accounts_ids": self._get_excluded_accounts().ids,
}
def button_export_html(self):