Skip to content

Commit b7c83b2

Browse files
[MIG] account_chart_update: Migration to 18.0
1 parent 6b72249 commit b7c83b2

File tree

6 files changed

+128
-66
lines changed

6 files changed

+128
-66
lines changed

account_chart_update/README.rst

+29-29
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ Detect changes and update the Account Chart from a template
1717
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
1818
:alt: License: AGPL-3
1919
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--financial--tools-lightgray.png?logo=github
20-
:target: https://github.com/OCA/account-financial-tools/tree/17.0/account_chart_update
20+
:target: https://github.com/OCA/account-financial-tools/tree/18.0/account_chart_update
2121
:alt: OCA/account-financial-tools
2222
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23-
:target: https://translation.odoo-community.org/projects/account-financial-tools-17-0/account-financial-tools-17-0-account_chart_update
23+
:target: https://translation.odoo-community.org/projects/account-financial-tools-18-0/account-financial-tools-18-0-account_chart_update
2424
:alt: Translate me on Weblate
2525
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26-
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-financial-tools&target_branch=17.0
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-financial-tools&target_branch=18.0
2727
:alt: Try me on Runboat
2828

2929
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -34,12 +34,12 @@ on the chart template.
3434

3535
The wizard:
3636

37-
- Allows the user to compare a chart and a template showing differences
38-
on accounts, taxes, tax codes and fiscal positions.
39-
- It may create the new account, taxes, tax codes and fiscal positions
40-
detected on the template.
41-
- It can also update (overwrite) the accounts, taxes, tax codes and
42-
fiscal positions that got modified on the template.
37+
- Allows the user to compare a chart and a template showing differences
38+
on accounts, taxes, tax codes and fiscal positions.
39+
- It may create the new account, taxes, tax codes and fiscal positions
40+
detected on the template.
41+
- It can also update (overwrite) the accounts, taxes, tax codes and
42+
fiscal positions that got modified on the template.
4343

4444
**Table of contents**
4545

@@ -61,19 +61,19 @@ to exclude records individually.
6161
Known issues / Roadmap
6262
======================
6363

64-
- Generate and update account reconcile models.
65-
- Generate XML-ID for fiscal position tax and account mapping lines.
66-
- Allow to select independently operations to perform (create, update,
67-
deactivate).
68-
- Detect fiscal positions to deactivate?
64+
- Generate and update account reconcile models.
65+
- Generate XML-ID for fiscal position tax and account mapping lines.
66+
- Allow to select independently operations to perform (create, update,
67+
deactivate).
68+
- Detect fiscal positions to deactivate?
6969

7070
Bug Tracker
7171
===========
7272

7373
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-financial-tools/issues>`_.
7474
In case of trouble, please check there if your issue has already been reported.
7575
If you spotted it first, help us to smash it by providing a detailed and welcomed
76-
`feedback <https://github.com/OCA/account-financial-tools/issues/new?body=module:%20account_chart_update%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
76+
`feedback <https://github.com/OCA/account-financial-tools/issues/new?body=module:%20account_chart_update%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
7777

7878
Do not contact contributors directly about support or help with technical issues.
7979

@@ -90,23 +90,23 @@ Authors
9090
Contributors
9191
------------
9292

93-
- `Tecnativa <https://www.tecnativa.com>`__:
93+
- `Tecnativa <https://www.tecnativa.com>`__:
9494

95-
- Pedro M. Baeza
96-
- Ernesto Tejeda
97-
- Víctor Martínez
95+
- Pedro M. Baeza
96+
- Ernesto Tejeda
97+
- Víctor Martínez
9898

99-
- Jacques-Etienne Baudoux <je@bcim.be>
100-
- Sylvain Van Hoof <sylvain@okia.be>
101-
- Nacho Muñoz <nacmuro@gmail.com>
102-
- Alberto Martín - Guadaltech <alberto.martin@guadaltech.es>
103-
- Fernando La Chica - GreenIce <fernandolachica@gmail.com>
104-
- Jairo Llopis (https://www.moduon.team/)
105-
- `Factor Libre <https://factorlibre.com>`__:
99+
- Jacques-Etienne Baudoux <je@bcim.be>
100+
- Sylvain Van Hoof <sylvain@okia.be>
101+
- Nacho Muñoz <nacmuro@gmail.com>
102+
- Alberto Martín - Guadaltech <alberto.martin@guadaltech.es>
103+
- Fernando La Chica - GreenIce <fernandolachica@gmail.com>
104+
- Jairo Llopis (https://www.moduon.team/)
105+
- `Factor Libre <https://factorlibre.com>`__:
106106

107-
- Luis J. Salvatierra
107+
- Luis J. Salvatierra
108108

109-
- Daniel Reis (dreis@opensourceintegrators.com)
109+
- Daniel Reis (dreis@opensourceintegrators.com)
110110

111111
Maintainers
112112
-----------
@@ -121,6 +121,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
121121
mission is to support the collaborative development of Odoo features and
122122
promote its widespread use.
123123

124-
This module is part of the `OCA/account-financial-tools <https://github.com/OCA/account-financial-tools/tree/17.0/account_chart_update>`_ project on GitHub.
124+
This module is part of the `OCA/account-financial-tools <https://github.com/OCA/account-financial-tools/tree/18.0/account_chart_update>`_ project on GitHub.
125125

126126
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

account_chart_update/__manifest__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{
88
"name": "Detect changes and update the Account Chart from a template",
99
"summary": "Wizard to update a company's account chart from a template",
10-
"version": "17.0.1.0.0",
10+
"version": "18.0.1.0.0",
1111
"author": "Tecnativa, BCIM, Okia, Odoo Community Association (OCA)",
1212
"website": "https://github.com/OCA/account-financial-tools",
1313
"depends": ["account"],

account_chart_update/static/description/index.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ <h1 class="title">Detect changes and update the Account Chart from a template</h
369369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
370370
!! source digest: sha256:4b9ad640a2561ddbe28d1e7f433424bd1d430e783546e974aac1a84f8f33e1da
371371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
372-
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/account-financial-tools/tree/17.0/account_chart_update"><img alt="OCA/account-financial-tools" src="https://img.shields.io/badge/github-OCA%2Faccount--financial--tools-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/account-financial-tools-17-0/account-financial-tools-17-0-account_chart_update"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/account-financial-tools&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
372+
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/account-financial-tools/tree/18.0/account_chart_update"><img alt="OCA/account-financial-tools" src="https://img.shields.io/badge/github-OCA%2Faccount--financial--tools-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/account-financial-tools-18-0/account-financial-tools-18-0-account_chart_update"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/account-financial-tools&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
373373
<p>This is a pretty useful tool to update Odoo installations after tax
374374
reforms on the official charts of accounts, or to apply fixes performed
375375
on the chart template.</p>
@@ -421,7 +421,7 @@ <h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
421421
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/account-financial-tools/issues">GitHub Issues</a>.
422422
In case of trouble, please check there if your issue has already been reported.
423423
If you spotted it first, help us to smash it by providing a detailed and welcomed
424-
<a class="reference external" href="https://github.com/OCA/account-financial-tools/issues/new?body=module:%20account_chart_update%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
424+
<a class="reference external" href="https://github.com/OCA/account-financial-tools/issues/new?body=module:%20account_chart_update%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
425425
<p>Do not contact contributors directly about support or help with technical issues.</p>
426426
</div>
427427
<div class="section" id="credits">
@@ -465,7 +465,7 @@ <h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
465465
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
466466
mission is to support the collaborative development of Odoo features and
467467
promote its widespread use.</p>
468-
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/account-financial-tools/tree/17.0/account_chart_update">OCA/account-financial-tools</a> project on GitHub.</p>
468+
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/account-financial-tools/tree/18.0/account_chart_update">OCA/account-financial-tools</a> project on GitHub.</p>
469469
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
470470
</div>
471471
</div>

account_chart_update/tests/test_account_chart_update.py

+63-11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright 2024 Tecnativa - Víctor Martínez
33
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
44

5+
import json
56
import logging
67

78
from odoo.tests import tagged
@@ -29,6 +30,7 @@ def test_chart_update_01(self):
2930
self.assertNotEqual(field.display_name, expected_name)
3031
# Test no changes
3132
self.assertEqual(wizard.state, "ready")
33+
wizard.account_ids.unlink()
3234
self.assertFalse(wizard.tax_ids)
3335
self.assertFalse(wizard.account_ids)
3436
self.assertFalse(wizard.fiscal_position_ids)
@@ -49,15 +51,63 @@ def test_chart_update_01(self):
4951
self.assertFalse(wizard.fiscal_position_ids)
5052
# We delete the existing records so that they appear "to be created".
5153
domain = [("company_id", "=", self.company.id)]
52-
ip = self.env["ir.property"].sudo()
54+
domain_account = [("company_ids", "in", self.company.ids)]
55+
# Before deleting taxes, delete the references in the models.
56+
self.env.cr.execute("DELETE FROM account_reconcile_model_line_account_tax_rel")
5357
self.env["account.tax"].search(domain).unlink()
54-
accounts = self.env["account.account"].search(domain)
55-
values = [f"account.account,{a_id}" for a_id in accounts.ids]
56-
ip.search([("value_reference", "in", values)]).unlink()
5758
journals = self.env["account.journal"].search(domain)
58-
values = [f"account.journal,{j_id}" for j_id in journals.ids]
59-
ip.search([("value_reference", "in", values)]).unlink()
59+
for model_field in self.env["ir.model.fields"].search(
60+
[
61+
("relation", "=", "account.journal"),
62+
("store", "=", True),
63+
("company_dependent", "=", True),
64+
]
65+
):
66+
field_name = model_field.name
67+
model = model_field.model_id.model
68+
records = self.env[model].search([(field_name, "in", journals.ids)])
69+
sub_ids_json_text = tuple(json.dumps(rec.id) for rec in journals)
70+
defaults = (
71+
self.env["ir.default"]
72+
.sudo()
73+
.search(
74+
[
75+
("field_id", "=", model_field.id),
76+
("json_value", "in", sub_ids_json_text),
77+
]
78+
)
79+
)
80+
if defaults:
81+
defaults.unlink()
82+
if records:
83+
records.with_company(self.company).write({field_name: False})
6084
journals.unlink()
85+
accounts = self.env["account.account"].search(domain_account)
86+
for model_field in self.env["ir.model.fields"].search(
87+
[
88+
("relation", "=", "account.account"),
89+
("store", "=", True),
90+
("company_dependent", "=", True),
91+
]
92+
):
93+
field_name = model_field.name
94+
model = model_field.model_id.model
95+
records = self.env[model].search([(field_name, "in", accounts.ids)])
96+
sub_ids_json_text = tuple(json.dumps(rec.id) for rec in accounts)
97+
defaults = (
98+
self.env["ir.default"]
99+
.sudo()
100+
.search(
101+
[
102+
("field_id", "=", model_field.id),
103+
("json_value", "in", sub_ids_json_text),
104+
]
105+
)
106+
)
107+
if defaults:
108+
defaults.unlink()
109+
if records:
110+
records.with_company(self.company).write({field_name: False})
61111
accounts.unlink()
62112
self.env["account.fiscal.position"].search(domain).unlink()
63113
self.env["account.group"].search(domain).unlink()
@@ -117,7 +167,9 @@ def test_chart_update_01(self):
117167
# Update objects
118168
new_account.name = "Account name (updated)"
119169
new_tax.name = "Tax name (updated)"
120-
new_tax_group = self.env["account.tax.group"].create({"name": "Test 1"})
170+
new_tax_group = self.env["account.tax.group"].create(
171+
{"name": "Test 1", "country_id": new_tax.country_id.id}
172+
)
121173
new_tax.tax_group_id = new_tax_group
122174
repartition = new_tax.repartition_line_ids.filtered(
123175
lambda r: r.repartition_type == "tax"
@@ -175,16 +227,16 @@ def test_chart_update_02(self):
175227
new_tax = self._get_record_for_xml_id(tax_data_key_0)
176228
new_tax.name = "Test 1 tax name changed"
177229
new_account = self._get_record_for_xml_id(account_data_key_0)
178-
new_account.code = "200000"
230+
new_account.code = "101000"
179231
wizard = self.wizard_obj.create(self.wizard_vals)
180232
wizard.action_find_records()
181233
self.assertEqual(wizard.tax_ids.update_tax_id, new_tax)
182234
self.assertEqual(wizard.tax_ids.type, "updated")
183-
self.assertEqual(wizard.account_ids.update_account_id, new_account)
184-
self.assertEqual(wizard.account_ids.type, "updated")
235+
self.assertEqual(wizard.account_ids[0].update_account_id, new_account)
236+
self.assertEqual(wizard.account_ids[0].type, "updated")
185237
wizard.action_update_records()
186238
self.assertEqual(wizard.updated_taxes, 1)
187-
self.assertEqual(wizard.updated_accounts, 1)
239+
self.assertEqual(wizard.updated_accounts, 44)
188240
self.assertEqual(new_tax.name, tax_data_0["name"])
189241
self.assertEqual(new_account.code, wizard.padded_code(account_data_0["code"]))
190242
# Test match by another field, there is no match by XML-ID

account_chart_update/wizard/wizard_chart_update.py

+16-6
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,11 @@ def diff_fields(self, record_values, real): # noqa: C901
466466
continue
467467
field = fields_by_key[key]
468468
record_value, real_value = record_values[key], real[key]
469-
if real._name == "account.account" and key == "code":
469+
if (
470+
real._name == "account.account"
471+
and key == "code"
472+
and isinstance(real_value, str)
473+
):
470474
record_value = self.padded_code(record_value)
471475
real_value = self.padded_code(real_value)
472476
# Field ttype conditions
@@ -522,7 +526,6 @@ def diff_fields(self, record_values, real): # noqa: C901
522526
record_value_lang = record_values[key_lang]
523527
if record_value_lang != real_value_lang:
524528
result[key_lang] = record_value_lang
525-
# print(asass)
526529
elif record_value != real_value:
527530
result[key] = record_value
528531
# __translation_module__
@@ -577,7 +580,12 @@ def _find_record_matching(self, model_name, xmlid, data):
577580
}
578581
company = self.company_id
579582
model = self.env[model_name]
580-
company_domain = [("company_id", "=", company.id)]
583+
if "company_id" in model._fields:
584+
company_domain = [("company_id", "=", company.id)]
585+
elif "company_ids" in model._fields:
586+
company_domain = [("company_ids", "in", company.ids)]
587+
else:
588+
company_domain = []
581589
for matching in mapped_fields[model_name].sorted("sequence"):
582590
if matching.matching_value == "xml_id":
583591
full_xmlid = (
@@ -606,7 +614,8 @@ def _find_record_matching(self, model_name, xmlid, data):
606614
return False
607615

608616
def _get_external_id(self, record):
609-
return record.get_external_id()[record.id]
617+
external_ids = record.get_external_id()
618+
return external_ids.get(record.id, False)
610619

611620
@tools.ormcache("self", "record", "xml_id")
612621
def missing_xml_id(self, record, xml_id):
@@ -821,7 +830,8 @@ def _load_data(self, model, data):
821830
if isinstance(xml_id, int):
822831
record = self.env[model].browse(xml_id)
823832
else:
824-
xml_id = f"{('account.' + str(self.company_id.id) + '_') if '.' not in xml_id else ''}{xml_id}"
833+
prefix = f"account.{self.company_id.id}_" if "." not in xml_id else ""
834+
xml_id = f"{prefix}{xml_id}"
825835
record = self.env.ref(xml_id)
826836
# Updatr translation vals
827837
for lang in langs:
@@ -848,7 +858,7 @@ def _update_taxes(self, t_data):
848858
tax = wiz_tax.update_tax_id
849859
if wiz_tax.type == "deleted":
850860
tax.active = False
851-
_logger.info(_("Deactivated tax %s."), "'%s'" % tax.name)
861+
_logger.info(_("Deactivated tax %s."), tax.name)
852862
continue
853863
xml_id = wiz_tax.xml_id
854864
key = tax.id or xml_id

0 commit comments

Comments
 (0)