Skip to content

Commit

Permalink
[MIG] account_chart_update: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pablo-cort-s73 committed Mar 4, 2025
1 parent 6b72249 commit dbc5943
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 65 deletions.
58 changes: 29 additions & 29 deletions account_chart_update/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ Detect changes and update the Account Chart from a template
: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--financial--tools-lightgray.png?logo=github
:target: https://github.com/OCA/account-financial-tools/tree/17.0/account_chart_update
:target: https://github.com/OCA/account-financial-tools/tree/18.0/account_chart_update
:alt: OCA/account-financial-tools
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/account-financial-tools-17-0/account-financial-tools-17-0-account_chart_update
:target: https://translation.odoo-community.org/projects/account-financial-tools-18-0/account-financial-tools-18-0-account_chart_update
: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-financial-tools&target_branch=17.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-financial-tools&target_branch=18.0
:alt: Try me on Runboat

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

The wizard:

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

**Table of contents**

Expand All @@ -61,19 +61,19 @@ to exclude records individually.
Known issues / Roadmap
======================

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

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-financial-tools/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-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 <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**>`_.

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

Expand All @@ -90,23 +90,23 @@ Authors
Contributors
------------

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

- Pedro M. Baeza
- Ernesto Tejeda
- Víctor Martínez
- Pedro M. Baeza
- Ernesto Tejeda
- Víctor Martínez

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

- Luis J. Salvatierra
- Luis J. Salvatierra

- Daniel Reis (dreis@opensourceintegrators.com)
- Daniel Reis (dreis@opensourceintegrators.com)

Maintainers
-----------
Expand All @@ -121,6 +121,6 @@ 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.

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.
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.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion account_chart_update/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{
"name": "Detect changes and update the Account Chart from a template",
"summary": "Wizard to update a company's account chart from a template",
"version": "17.0.1.0.0",
"version": "18.0.1.0.0",
"author": "Tecnativa, BCIM, Okia, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-financial-tools",
"depends": ["account"],
Expand Down
6 changes: 3 additions & 3 deletions account_chart_update/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ <h1 class="title">Detect changes and update the Account Chart from a template</h
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:4b9ad640a2561ddbe28d1e7f433424bd1d430e783546e974aac1a84f8f33e1da
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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>
<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>
<p>This is a pretty useful tool to update Odoo installations after tax
reforms on the official charts of accounts, or to apply fixes performed
on the chart template.</p>
Expand Down Expand Up @@ -421,7 +421,7 @@ <h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/account-financial-tools/issues">GitHub Issues</a>.
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
<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>
<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>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand Down Expand Up @@ -465,7 +465,7 @@ <h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<p>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.</p>
<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>
<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>
<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>
</div>
</div>
Expand Down
74 changes: 63 additions & 11 deletions account_chart_update/tests/test_account_chart_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Copyright 2024 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import json
import logging

from odoo.tests import tagged
Expand Down Expand Up @@ -29,6 +30,7 @@ def test_chart_update_01(self):
self.assertNotEqual(field.display_name, expected_name)
# Test no changes
self.assertEqual(wizard.state, "ready")
wizard.account_ids.unlink()
self.assertFalse(wizard.tax_ids)
self.assertFalse(wizard.account_ids)
self.assertFalse(wizard.fiscal_position_ids)
Expand All @@ -49,15 +51,63 @@ def test_chart_update_01(self):
self.assertFalse(wizard.fiscal_position_ids)
# We delete the existing records so that they appear "to be created".
domain = [("company_id", "=", self.company.id)]
ip = self.env["ir.property"].sudo()
domain_account = [("company_ids", "in", self.company.ids)]
# Before deleting taxes, delete the references in the models.
self.env.cr.execute("DELETE FROM account_reconcile_model_line_account_tax_rel")
self.env["account.tax"].search(domain).unlink()
accounts = self.env["account.account"].search(domain)
values = [f"account.account,{a_id}" for a_id in accounts.ids]
ip.search([("value_reference", "in", values)]).unlink()
journals = self.env["account.journal"].search(domain)
values = [f"account.journal,{j_id}" for j_id in journals.ids]
ip.search([("value_reference", "in", values)]).unlink()
for model_field in self.env["ir.model.fields"].search(
[
("relation", "=", "account.journal"),
("store", "=", True),
("company_dependent", "=", True),
]
):
field_name = model_field.name
model = model_field.model_id.model
records = self.env[model].search([(field_name, "in", journals.ids)])
sub_ids_json_text = tuple(json.dumps(rec.id) for rec in journals)
defaults = (
self.env["ir.default"]
.sudo()
.search(
[
("field_id", "=", model_field.id),
("json_value", "in", sub_ids_json_text),
]
)
)
if defaults:
defaults.unlink()
if records:
records.with_company(self.company).write({field_name: False})
journals.unlink()
accounts = self.env["account.account"].search(domain_account)
for model_field in self.env["ir.model.fields"].search(
[
("relation", "=", "account.account"),
("store", "=", True),
("company_dependent", "=", True),
]
):
field_name = model_field.name
model = model_field.model_id.model
records = self.env[model].search([(field_name, "in", accounts.ids)])
sub_ids_json_text = tuple(json.dumps(rec.id) for rec in accounts)
defaults = (
self.env["ir.default"]
.sudo()
.search(
[
("field_id", "=", model_field.id),
("json_value", "in", sub_ids_json_text),
]
)
)
if defaults:
defaults.unlink()
if records:
records.with_company(self.company).write({field_name: False})
accounts.unlink()
self.env["account.fiscal.position"].search(domain).unlink()
self.env["account.group"].search(domain).unlink()
Expand Down Expand Up @@ -117,7 +167,9 @@ def test_chart_update_01(self):
# Update objects
new_account.name = "Account name (updated)"
new_tax.name = "Tax name (updated)"
new_tax_group = self.env["account.tax.group"].create({"name": "Test 1"})
new_tax_group = self.env["account.tax.group"].create(
{"name": "Test 1", "country_id": new_tax.country_id.id}
)
new_tax.tax_group_id = new_tax_group
repartition = new_tax.repartition_line_ids.filtered(
lambda r: r.repartition_type == "tax"
Expand Down Expand Up @@ -175,16 +227,16 @@ def test_chart_update_02(self):
new_tax = self._get_record_for_xml_id(tax_data_key_0)
new_tax.name = "Test 1 tax name changed"
new_account = self._get_record_for_xml_id(account_data_key_0)
new_account.code = "200000"
new_account.code = "101000"
wizard = self.wizard_obj.create(self.wizard_vals)
wizard.action_find_records()
self.assertEqual(wizard.tax_ids.update_tax_id, new_tax)
self.assertEqual(wizard.tax_ids.type, "updated")
self.assertEqual(wizard.account_ids.update_account_id, new_account)
self.assertEqual(wizard.account_ids.type, "updated")
self.assertEqual(wizard.account_ids[0].update_account_id, new_account)
self.assertEqual(wizard.account_ids[0].type, "updated")
wizard.action_update_records()
self.assertEqual(wizard.updated_taxes, 1)
self.assertEqual(wizard.updated_accounts, 1)
self.assertEqual(wizard.updated_accounts, 44)
self.assertEqual(new_tax.name, tax_data_0["name"])
self.assertEqual(new_account.code, wizard.padded_code(account_data_0["code"]))
# Test match by another field, there is no match by XML-ID
Expand Down
16 changes: 11 additions & 5 deletions account_chart_update/wizard/wizard_chart_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,6 @@ def diff_fields(self, record_values, real): # noqa: C901
record_value_lang = record_values[key_lang]
if record_value_lang != real_value_lang:
result[key_lang] = record_value_lang
# print(asass)
elif record_value != real_value:
result[key] = record_value
# __translation_module__
Expand Down Expand Up @@ -577,7 +576,12 @@ def _find_record_matching(self, model_name, xmlid, data):
}
company = self.company_id
model = self.env[model_name]
company_domain = [("company_id", "=", company.id)]
if "company_id" in model._fields:
company_domain = [("company_id", "=", company.id)]
elif "company_ids" in model._fields:
company_domain = [("company_ids", "in", company.ids)]
else:
company_domain = []
for matching in mapped_fields[model_name].sorted("sequence"):
if matching.matching_value == "xml_id":
full_xmlid = (
Expand Down Expand Up @@ -606,7 +610,8 @@ def _find_record_matching(self, model_name, xmlid, data):
return False

def _get_external_id(self, record):
return record.get_external_id()[record.id]
external_ids = record.get_external_id()
return external_ids.get(record.id, False)

@tools.ormcache("self", "record", "xml_id")
def missing_xml_id(self, record, xml_id):
Expand Down Expand Up @@ -821,7 +826,8 @@ def _load_data(self, model, data):
if isinstance(xml_id, int):
record = self.env[model].browse(xml_id)
else:
xml_id = f"{('account.' + str(self.company_id.id) + '_') if '.' not in xml_id else ''}{xml_id}"
prefix = f"account.{self.company_id.id}_" if "." not in xml_id else ""
xml_id = f"{prefix}{xml_id}"
record = self.env.ref(xml_id)
# Updatr translation vals
for lang in langs:
Expand All @@ -848,7 +854,7 @@ def _update_taxes(self, t_data):
tax = wiz_tax.update_tax_id
if wiz_tax.type == "deleted":
tax.active = False
_logger.info(_("Deactivated tax %s."), "'%s'" % tax.name)
_logger.info(_("Deactivated tax %s."), tax.name)
continue
xml_id = wiz_tax.xml_id
key = tax.id or xml_id
Expand Down
Loading

0 comments on commit dbc5943

Please sign in to comment.