Skip to content

Commit ee84e7c

Browse files
committed
Merge PR #363 into 18.0
Signed-off-by sergiocorato
2 parents b72923c + 3c1ea9a commit ee84e7c

20 files changed

Lines changed: 1413 additions & 0 deletions
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
=================================
2+
Account Fiscal Year Closing Range
3+
=================================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:6257b951ee200f96e4195794fff8603e50cafb0973170611bc0d7c60dedd0255
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--closing-lightgray.png?logo=github
20+
:target: https://github.com/OCA/account-closing/tree/18.0/account_fiscal_year_closing_range
21+
:alt: OCA/account-closing
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/account-closing-18-0/account-closing-18-0-account_fiscal_year_closing_range
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-closing&target_branch=18.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module extends the fiscal year closing functionality to allow
32+
mapping account ranges.
33+
34+
**Table of contents**
35+
36+
.. contents::
37+
:local:
38+
39+
Configuration
40+
=============
41+
42+
To configure this module, you need to:
43+
44+
1. Go to *Accounting > Accounting > Fiscal Year Closings*.
45+
2. Create or edit a fiscal year closing or a template.
46+
3. In the **Moves configuration** section, edit a configuration line.
47+
4. Locate the **Accounts mapping** section.
48+
5. Click the **"Generate Range"** button to open the wizard.
49+
6. Once the lines are generated by the wizard, save the configuration.
50+
51+
Usage
52+
=====
53+
54+
**Account Range Wizard**
55+
56+
If you want to generate multiple mapping records at once for a specific
57+
range of accounts:
58+
59+
1. Go to the **Accounts mapping** section in a Fiscal Year Closing
60+
configuration or template.
61+
62+
2. Click the **"Generate Range"** button (magic icon) located above the
63+
mapping list.
64+
65+
3. In the wizard:
66+
67+
- Set the **Start Account Code** and **End Account Code**.
68+
- Enter the **Destination Account Code** (e.g., ``3.1.01.001``).
69+
- Optional: Define a **Mapping Name Prefix** to identify these lines
70+
easily.
71+
72+
4. Click **"Generate Mappings"**.
73+
74+
5. The wizard will find all accounts in the range and create an
75+
individual mapping line for each one, using the provided destination
76+
code.
77+
78+
Bug Tracker
79+
===========
80+
81+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-closing/issues>`_.
82+
In case of trouble, please check there if your issue has already been reported.
83+
If you spotted it first, help us to smash it by providing a detailed and welcomed
84+
`feedback <https://github.com/OCA/account-closing/issues/new?body=module:%20account_fiscal_year_closing_range%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
85+
86+
Do not contact contributors directly about support or help with technical issues.
87+
88+
Credits
89+
=======
90+
91+
Authors
92+
-------
93+
94+
* Escodoo
95+
96+
Contributors
97+
------------
98+
99+
- `Escodoo <https://escodoo.com.br/>`__
100+
101+
- Kaynnan Lemes <kaynnan.lemes@escodoo.com.br>
102+
103+
Maintainers
104+
-----------
105+
106+
This module is maintained by the OCA.
107+
108+
.. image:: https://odoo-community.org/logo.png
109+
:alt: Odoo Community Association
110+
:target: https://odoo-community.org
111+
112+
OCA, or the Odoo Community Association, is a nonprofit organization whose
113+
mission is to support the collaborative development of Odoo features and
114+
promote its widespread use.
115+
116+
.. |maintainer-kaynnan, marcelsavegnago| image:: https://github.com/kaynnan, marcelsavegnago.png?size=40px
117+
:target: https://github.com/kaynnan, marcelsavegnago
118+
:alt: kaynnan, marcelsavegnago
119+
120+
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
121+
122+
|maintainer-kaynnan, marcelsavegnago|
123+
124+
This module is part of the `OCA/account-closing <https://github.com/OCA/account-closing/tree/18.0/account_fiscal_year_closing_range>`_ project on GitHub.
125+
126+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import models
2+
from . import wizards
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "Account Fiscal Year Closing Range",
3+
"summary": "Allow mapping account ranges in fiscal year closing",
4+
"version": "18.0.1.0.0",
5+
"category": "Accounting & Finance",
6+
"website": "https://github.com/OCA/account-closing",
7+
"author": "Escodoo, Odoo Community Association (OCA)",
8+
"maintainers": ["kaynnan, marcelsavegnago"],
9+
"license": "AGPL-3",
10+
"installable": True,
11+
"depends": [
12+
"account_fiscal_year_closing",
13+
],
14+
"data": [
15+
"security/ir.model.access.csv",
16+
"views/account_fiscalyear_closing_views.xml",
17+
"views/account_fiscalyear_closing_template_views.xml",
18+
"wizards/mapping_range_wizard.xml",
19+
],
20+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import account_fiscalyear_closing
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Copyright 2026 Kaynnan Lemes <kaynnan.lemes@escodoo.com.br>
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import api, fields, models
5+
6+
7+
class AccountFiscalyearClosingMapping(models.Model):
8+
_inherit = "account.fiscalyear.closing.mapping"
9+
10+
code_start = fields.Char(
11+
string="Start Account Code",
12+
)
13+
code_end = fields.Char(
14+
string="End Account Code",
15+
)
16+
17+
@api.model_create_multi
18+
def create(self, vals_list):
19+
for vals in vals_list:
20+
if "dest_account_id" in vals and isinstance(vals["dest_account_id"], int):
21+
vals["dest_account_id"] = [vals["dest_account_id"]]
22+
return super().create(vals_list)
23+
24+
def write(self, vals):
25+
if "dest_account_id" in vals and isinstance(vals["dest_account_id"], int):
26+
vals["dest_account_id"] = [vals["dest_account_id"]]
27+
return super().write(vals)
28+
29+
30+
class AccountFiscalyearClosingConfig(models.Model):
31+
_inherit = "account.fiscalyear.closing.config"
32+
33+
def _get_mapping_account_domain(self, mapping):
34+
"""
35+
Construct the search domain for accounts based on range or pattern.
36+
Returns None if no valid configuration is found.
37+
"""
38+
domain = [("company_ids", "in", [self.fyc_id.company_id.id])]
39+
40+
if mapping.code_start and mapping.code_end:
41+
domain += [
42+
("code", ">=", mapping.code_start),
43+
("code", "<=", mapping.code_end),
44+
]
45+
elif mapping.src_accounts:
46+
domain += [("code", "=ilike", mapping.src_accounts)]
47+
else:
48+
return None
49+
50+
return domain
51+
52+
def _mapping_move_lines_get(self):
53+
"""
54+
Retrieve move lines for the closing entry.
55+
Overridden to support account filtering by range (Start/End)
56+
in addition to the standard pattern matching.
57+
"""
58+
move_lines = []
59+
dest_totals = {}
60+
61+
for account_map in self.mapping_ids:
62+
dest = account_map.dest_account_id
63+
dest_totals.setdefault(dest, 0.0)
64+
65+
domain = self._get_mapping_account_domain(account_map)
66+
if not domain:
67+
continue
68+
69+
src_accounts = self.env["account.account"].search(domain, order="code ASC")
70+
71+
for account in src_accounts:
72+
closing_type = self.closing_type_get(account)
73+
balance = 0.0
74+
move_line = {}
75+
76+
if closing_type == "balance":
77+
lines = account_map.account_lines_get(account)
78+
balance, move_line = account_map.move_line_prepare(account, lines)
79+
if move_line:
80+
move_lines.append(move_line)
81+
82+
elif closing_type == "unreconciled":
83+
partners = account_map.account_partners_get(account)
84+
for partner in partners:
85+
balance, move_line = account_map.move_line_partner_prepare(
86+
account, partner
87+
)
88+
if move_line:
89+
move_lines.append(move_line)
90+
91+
if dest and balance:
92+
dest_totals[dest] -= balance
93+
94+
for account_map in self.mapping_ids.filtered("dest_account_id"):
95+
dest = account_map.dest_account_id
96+
balance = dest_totals.get(dest, 0.0)
97+
98+
if not balance:
99+
continue
100+
101+
dest_totals[dest] = 0.0
102+
move_line = account_map.dest_move_line_prepare(dest, balance)
103+
if move_line:
104+
move_lines.append(move_line)
105+
106+
return move_lines
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
To configure this module, you need to:
2+
3+
1. Go to *Accounting \> Accounting \> Fiscal Year Closings*.
4+
2. Create or edit a fiscal year closing or a template.
5+
3. In the **Moves configuration** section, edit a configuration line.
6+
4. Locate the **Accounts mapping** section.
7+
5. Click the **"Generate Range"** button to open the wizard.
8+
6. Once the lines are generated by the wizard, save the configuration.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- [Escodoo](https://escodoo.com.br/)
2+
- Kaynnan Lemes \<kaynnan.lemes@escodoo.com.br\>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This module extends the fiscal year closing functionality to allow
2+
mapping account ranges.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
**Account Range Wizard**
2+
3+
If you want to generate multiple mapping records at once for a specific
4+
range of accounts:
5+
6+
1. Go to the **Accounts mapping** section in a Fiscal Year Closing
7+
configuration or template.
8+
9+
2. Click the **"Generate Range"** button (magic icon) located above the
10+
mapping list.
11+
12+
3. In the wizard:
13+
- Set the **Start Account Code** and **End Account Code**.
14+
- Enter the **Destination Account Code** (e.g., `3.1.01.001`).
15+
- Optional: Define a **Mapping Name Prefix** to identify these lines
16+
easily.
17+
18+
4. Click **"Generate Mappings"**.
19+
20+
5. The wizard will find all accounts in the range and create an
21+
individual mapping line for each one, using the provided destination
22+
code.

0 commit comments

Comments
 (0)