-
-
Notifications
You must be signed in to change notification settings - Fork 398
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] account_reconcile_model_inclusion
- Loading branch information
Showing
17 changed files
with
832 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
======================================== | ||
Reconciliation model inclusion/exclusion | ||
======================================== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:4b34b13c2c66ef191993b5a96c02315d7eb330d531916ab6328f2da05a725033 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png | ||
:target: https://odoo-community.org/page/development-status | ||
:alt: Alpha | ||
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--reconcile-lightgray.png?logo=github | ||
:target: https://github.com/OCA/account-reconcile/tree/16.0/account_reconcile_model_inclusion | ||
:alt: OCA/account-reconcile | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/account-reconcile-16-0/account-reconcile-16-0-account_reconcile_model_inclusion | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png | ||
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-reconcile&target_branch=16.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module allows to include or exclude other models when matching | ||
reconciliation rules. | ||
|
||
Doing so can simplify models significantly for cases where there's some | ||
overlap between sets of codes to match, like "if it looks like XX XX, | ||
take rule 1, if it looks like XX XXX take rule 2, but if XX XX and XX | ||
XXX are present in any order, take rule 3". | ||
|
||
.. IMPORTANT:: | ||
This is an alpha version, the data model and design can change at any time without warning. | ||
Only for development or testing purpose, do not use in production. | ||
`More details on development status <https://odoo-community.org/page/development-status>`_ | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Configuration | ||
============= | ||
|
||
To configure this module, you need to: | ||
|
||
1. Go to Accounting / Banks / Reconciliation Models | ||
2. Fill in rules to include/exclude in the conditions tab | ||
|
||
Usage | ||
===== | ||
|
||
To use this module, you need to: | ||
|
||
1. Configure a reconciliation model as outlined above | ||
2. Observe it will be used according to the configuration during | ||
reconciliation | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-reconcile/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us to smash it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/account-reconcile/issues/new?body=module:%20account_reconcile_model_inclusion%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
------- | ||
|
||
* Hunki Enterprises BV | ||
|
||
Contributors | ||
------------ | ||
|
||
- Holger Brunn <[email protected]> | ||
(https://hunki-enterprises.com) | ||
|
||
Maintainers | ||
----------- | ||
|
||
This module is maintained by the OCA. | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
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. | ||
|
||
.. |maintainer-hbrunn| image:: https://github.com/hbrunn.png?size=40px | ||
:target: https://github.com/hbrunn | ||
:alt: hbrunn | ||
|
||
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__: | ||
|
||
|maintainer-hbrunn| | ||
|
||
This module is part of the `OCA/account-reconcile <https://github.com/OCA/account-reconcile/tree/16.0/account_reconcile_model_inclusion>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright 2025 Hunki Enterprises BV | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) | ||
|
||
{ | ||
"name": "Reconciliation model inclusion/exclusion", | ||
"summary": "Allows to match only when other models match/don't match", | ||
"version": "16.0.1.0.0", | ||
"development_status": "Alpha", | ||
"category": "Accounting", | ||
"website": "https://github.com/OCA/account-reconcile", | ||
"author": "Hunki Enterprises BV, Odoo Community Association (OCA)", | ||
"maintainers": ["hbrunn"], | ||
"license": "AGPL-3", | ||
"depends": [ | ||
"account", | ||
], | ||
"data": [ | ||
"views/account_reconcile_model.xml", | ||
], | ||
"demo": [ | ||
"demo/account_reconcile_model.xml", | ||
], | ||
} |
51 changes: 51 additions & 0 deletions
51
account_reconcile_model_inclusion/demo/account_reconcile_model.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<!-- Copyright 2025 Hunki Enterprises BV | ||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) --> | ||
<data> | ||
<record id="model_rule_two_blocks" model="account.reconcile.model"> | ||
<field name="name">Two blocks</field> | ||
<field name="rule_type">writeoff_suggestion</field> | ||
<field name="match_label">match_regex</field> | ||
<field name="match_label_param">.*\bXX\s+\d{2}\s+\d{2}\b.*</field> | ||
</record> | ||
<record id="model_rule_three_blocks" model="account.reconcile.model"> | ||
<field name="name">Three blocks</field> | ||
<field name="rule_type">writeoff_suggestion</field> | ||
<field name="match_label">match_regex</field> | ||
<field name="match_label_param">.*\bXY\s+\d{2}\s+\d{2}\s+\d{2}\b.*</field> | ||
</record> | ||
<record id="model_rule_three_blocks_xx" model="account.reconcile.model"> | ||
<field name="name">Three blocks (includes two blocks)</field> | ||
<field name="rule_type">writeoff_suggestion</field> | ||
<field name="match_label">match_regex</field> | ||
<field name="match_label_param">.*\bXX\s+\d{2}\s+\d{2}\s+\d{2}\b.*</field> | ||
</record> | ||
<record id="model_rule_both" model="account.reconcile.model"> | ||
<field name="name">Both blocks</field> | ||
<field name="rule_type">writeoff_suggestion</field> | ||
<field | ||
name="include_reconcile_model_ids" | ||
eval="[Command.set([ref('model_rule_two_blocks'), ref('model_rule_three_blocks')])]" | ||
/> | ||
</record> | ||
<record id="model_rule_both_xx" model="account.reconcile.model"> | ||
<field name="name">Both XX blocks</field> | ||
<field name="rule_type">writeoff_suggestion</field> | ||
<field | ||
name="include_reconcile_model_ids" | ||
eval="[Command.set([ref('model_rule_two_blocks'), ref('model_rule_three_blocks_xx')])]" | ||
/> | ||
</record> | ||
<record id="model_rule_two_blocks" model="account.reconcile.model"> | ||
<field | ||
name="exclude_reconcile_model_ids" | ||
eval="[Command.set([ref('model_rule_both'), ref('model_rule_both_xx')])]" | ||
/> | ||
</record> | ||
<record id="model_rule_three_blocks" model="account.reconcile.model"> | ||
<field | ||
name="exclude_reconcile_model_ids" | ||
eval="[Command.set([ref('model_rule_both')])]" | ||
/> | ||
</record> | ||
</data> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import account_reconcile_model |
73 changes: 73 additions & 0 deletions
73
account_reconcile_model_inclusion/models/account_reconcile_model.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Copyright 2025 Hunki Enterprises BV | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) | ||
|
||
from odoo import fields, models | ||
from odoo.tools.safe_eval import safe_eval | ||
|
||
|
||
class AccountReconcileModel(models.Model): | ||
_inherit = "account.reconcile.model" | ||
|
||
include_reconcile_model_ids = fields.Many2many( | ||
comodel_name="account.reconcile.model", | ||
relation="account_reconcile_model_include_rel", | ||
column1="model_id", | ||
column2="included_model_id", | ||
) | ||
exclude_reconcile_model_ids = fields.Many2many( | ||
comodel_name="account.reconcile.model", | ||
relation="account_reconcile_model_exclude_rel", | ||
column1="model_id", | ||
column2="excluded_model_id", | ||
) | ||
|
||
def _account_reconcile_model_inclusion_expression(self, seen=None): | ||
""" | ||
Build an expression with 'm{model.id}' as variables that expresses | ||
the applicability of a model recursively wrt includes/excludes | ||
""" | ||
seen = seen or set() | ||
seen.add(self) | ||
result = ( | ||
f"(m{self.id} and " | ||
+ ( | ||
" and ".join( | ||
include._account_reconcile_model_inclusion_expression(seen.copy()) | ||
if include not in seen | ||
else f"m{include.id}" | ||
for include in self.include_reconcile_model_ids | ||
) | ||
or "True" | ||
) | ||
+ " and " | ||
+ ( | ||
" and ".join( | ||
"not " | ||
+ exclude._account_reconcile_model_inclusion_expression(seen.copy()) | ||
if exclude not in seen | ||
else f"m{exclude.id}" | ||
for exclude in self.exclude_reconcile_model_ids | ||
) | ||
or "True" | ||
) | ||
+ ")" | ||
) | ||
return result | ||
|
||
def _is_applicable_for(self, st_line, partner): | ||
""" | ||
Apply inclusion/exclusion of other models' results | ||
""" | ||
result = super()._is_applicable_for(st_line, partner) | ||
|
||
if not result or self.env.context.get("account_reconcile_model_inclusion"): | ||
return result | ||
|
||
expression = self._account_reconcile_model_inclusion_expression() | ||
eval_context = { | ||
f"m{model.id}": model._is_applicable_for(st_line, partner) | ||
for model in self.search([]).with_context( | ||
account_reconcile_model_inclusion=True | ||
) | ||
} | ||
return safe_eval(expression, eval_context) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
To configure this module, you need to: | ||
|
||
1. Go to Accounting / Banks / Reconciliation Models | ||
2. Fill in rules to include/exclude in the conditions tab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Holger Brunn \<[email protected]> (https://hunki-enterprises.com) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
This module allows to include or exclude other models when matching reconciliation rules. | ||
|
||
Doing so can simplify models significantly for cases where there's some overlap between sets of codes to match, like "if it looks like XX XX, take rule 1, if it looks like XX XXX take rule 2, but if XX XX and XX XXX are present in any order, take rule 3". |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
To use this module, you need to: | ||
|
||
1. Configure a reconciliation model as outlined above | ||
2. Observe it will be used according to the configuration during reconciliation |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.