Skip to content

Commit

Permalink
[MIG] account_chart_update: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ljsalvatierra-factorlibre committed Jan 30, 2023
1 parent 663cb7e commit e515102
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 59 deletions.
13 changes: 8 additions & 5 deletions account_chart_update/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ 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/15.0/account_chart_update
:target: https://github.com/OCA/account-financial-tools/tree/16.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-15-0/account-financial-tools-15-0-account_chart_update
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/92/15.0
:target: https://runbot.odoo-community.org/runbot/92/16.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
|badge1| |badge2| |badge3| |badge4| |badge5|

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
Expand Down Expand Up @@ -69,7 +69,7 @@ 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 smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/account-financial-tools/issues/new?body=module:%20account_chart_update%0Aversion:%2015.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:%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.

Expand Down Expand Up @@ -97,6 +97,9 @@ Contributors
* Alberto Martín - Guadaltech <[email protected]>
* Fernando La Chica - GreenIce <[email protected]>
* Jairo Llopis (https://www.moduon.team/)
* `Factor Libre <https://factorlibre.com>`_:

* Luis J. Salvatierra

Maintainers
~~~~~~~~~~~
Expand All @@ -111,6 +114,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/15.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/16.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": "15.0.1.2.0",
"version": "16.0.1.0.0",
"author": "Tecnativa, BCIM, Okia, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-financial-tools",
"depends": ["account", "l10n_generic_coa"],
Expand Down
3 changes: 3 additions & 0 deletions account_chart_update/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@
* Alberto Martín - Guadaltech <[email protected]>
* Fernando La Chica - GreenIce <[email protected]>
* Jairo Llopis (https://www.moduon.team/)
* `Factor Libre <https://factorlibre.com>`_:

* Luis J. Salvatierra
43 changes: 18 additions & 25 deletions account_chart_update/tests/test_account_chart_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ def _create_xml_id(self, record):
}
)

def _create_account_tmpl(self, name, code, user_type, chart_template):
def _create_account_tmpl(self, name, code, account_type, chart_template):
record = self.env["account.account.template"].create(
{
"name": name,
"code": code,
"user_type_id": user_type.id,
"account_type": account_type,
"chart_template_id": chart_template and chart_template.id,
}
)
Expand Down Expand Up @@ -118,26 +118,19 @@ def setUp(self):
]
}
)
self.account_type = self.env["account.account.type"].create(
{
"name": "Test account_chart_update account type",
"internal_group": "income",
}
)
self.account_template = self._create_account_tmpl(
"Test", "100000", self.account_type, False
"Test", "100000", "income", False
)
self.chart_template = self.env.ref(
"l10n_generic_coa.configurable_chart_template"
)
# Avoid re-creating taxes.
# If false, the taxes that are created will be overwrited.
self.chart_template.complete_tax_set = True
self.account_template.chart_template_id = self.chart_template.id
self.account_template_pl = self._create_account_tmpl(
"Undistributed Profits/Losses",
"999999",
self.env.ref("account.data_unaffected_earnings"),
"equity",
self.chart_template,
)
self.tax_template = self._create_tax_tmpl("Test tax", self.chart_template)
Expand Down Expand Up @@ -236,7 +229,7 @@ def test_chart_update(self):
{"tag_ids": [(6, 0, self.account_tag_1.ids)]}
)
new_account_tmpl = self._create_account_tmpl(
"Test account 2", "333333", self.account_type, self.chart_template
"Test account 2", "333333", "income", self.chart_template
)
new_fp = self._create_fp_tmpl("Test fp 2", self.chart_template)
fp_template_tax = self.env["account.fiscal.position.tax.template"].create(
Expand Down Expand Up @@ -450,7 +443,7 @@ def test_chart_update(self):
# Errors on account_creation
self.account_template.currency_id = False
new_account_tmpl_2 = self._create_account_tmpl(
"Test account 3", "444444", self.account_type, self.chart_template
"Test account 3", "444444", "income", self.chart_template
)
wizard = self.wizard_obj.create(self.wizard_vals)
wizard.action_find_records()
Expand Down Expand Up @@ -543,9 +536,9 @@ def test_matching(self):
wizard.fiscal_position_ids.fiscal_position_id, self.fp_template
)
# There is no XML-ID
self.assertFalse(list(self.tax.get_xml_id().values())[0])
self.assertFalse(list(self.account.get_xml_id().values())[0])
self.assertFalse(list(self.fp.get_xml_id().values())[0])
self.assertFalse(list(self.tax.get_external_id().values())[0])
self.assertFalse(list(self.account.get_external_id().values())[0])
self.assertFalse(list(self.fp.get_external_id().values())[0])
# Update for recreating XML-ID
wizard.action_update_records()
self.assertEqual(wizard.updated_taxes, 1)
Expand All @@ -555,9 +548,9 @@ def test_matching(self):
self.assertEqual(self.account.name, self.account_template.name)
self.assertEqual(self.fp.note, self.fp_template.note)
# There is XML-ID now
self.assertTrue(list(self.tax.get_xml_id().values())[0])
self.assertTrue(list(self.account.get_xml_id().values())[0])
self.assertTrue(list(self.fp.get_xml_id().values())[0])
self.assertTrue(list(self.tax.get_external_id().values())[0])
self.assertTrue(list(self.account.get_external_id().values())[0])
self.assertTrue(list(self.fp.get_external_id().values())[0])
wizard.unlink()

# Test 2 recreate XML-ID
Expand All @@ -575,16 +568,16 @@ def test_matching(self):
wizard.fiscal_position_ids.fiscal_position_id, self.fp_template
)
# There is no XML-ID
self.assertFalse(list(self.tax.get_xml_id().values())[0])
self.assertFalse(list(self.account.get_xml_id().values())[0])
self.assertFalse(list(self.fp.get_xml_id().values())[0])
self.assertFalse(list(self.tax.get_external_id().values())[0])
self.assertFalse(list(self.account.get_external_id().values())[0])
self.assertFalse(list(self.fp.get_external_id().values())[0])
# Update for recreating XML-ID
wizard.action_update_records()
self.assertEqual(wizard.updated_taxes, 1)
self.assertEqual(wizard.updated_accounts, 1)
self.assertEqual(wizard.updated_fps, 1)
# There is XML-ID now
self.assertTrue(list(self.tax.get_xml_id().values())[0])
self.assertTrue(list(self.account.get_xml_id().values())[0])
self.assertTrue(list(self.fp.get_xml_id().values())[0])
self.assertTrue(list(self.tax.get_external_id().values())[0])
self.assertTrue(list(self.account.get_external_id().values())[0])
self.assertTrue(list(self.fp.get_external_id().values())[0])
wizard.unlink()
23 changes: 18 additions & 5 deletions account_chart_update/wizard/wizard_chart_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,12 +448,24 @@ def find_repartition_by_templates(
repartition_type = tpl.repartition_type
account_id = self.find_account_by_templates(tpl.account_id)
tags = self.env["account.account.tag"]
tags += tpl.plus_report_line_ids.mapped("tag_ids").filtered(
lambda x: not x.tax_negate
plus_expressions = tpl.plus_report_expression_ids.filtered(
lambda x: x.engine == "tax_tags"
)
tags += tpl.minus_report_line_ids.mapped("tag_ids").filtered(
lambda x: x.tax_negate
for expression in plus_expressions:
country = expression.report_line_id.report_id.country_id
existing_tags = self.env["account.account.tag"]._get_tax_tags(
expression.formula, country.id
)
tags |= existing_tags.filtered(lambda x: not x.tax_negate)
minus_expressions = tpl.minus_report_expression_ids.filtered(
lambda x: x.engine == "tax_tags"
)
for expression in minus_expressions:
country = expression.report_line_id.report_id.country_id
existing_tags = self.env["account.account.tag"]._get_tax_tags(
expression.formula, country.id
)
tags |= existing_tags.filtered(lambda x: x.tax_negate)
tags += tpl.tag_ids
existing = self.env["account.tax.repartition.line"]
existing_candidates = current_repartition.filtered(
Expand Down Expand Up @@ -719,7 +731,8 @@ def diff_fields(self, template, real): # noqa: C901
if expected != [] and (
key
in ["invoice_repartition_line_ids", "refund_repartition_line_ids"]
or expected != real[key]
or (isinstance(expected, models.Model) and expected != real[key])
or (not isinstance(expected, models.Model))
):
result[key] = expected
else:
Expand Down
49 changes: 26 additions & 23 deletions account_chart_update/wizard/wizard_chart_update_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
statusbar_colors='{"ready":"blue","done":"blue"}'
/>
</header>
<group attrs="{'invisible':[('state','!=','init')]}">
<div attrs="{'invisible':[('state','!=','init')]}">
<h3>
<p>
<center>
Expand All @@ -26,7 +26,7 @@
</center>
</p>
</h3>
</group>
</div>
<group
string="Chart of Accounts"
attrs="{'invisible':[('state','!=','init')]}"
Expand Down Expand Up @@ -59,7 +59,7 @@
<field name="recreate_xml_ids" />
</group>
</group>
<group>
<div>
<h5>
<p>
If you leave these options set, the wizard will
Expand All @@ -70,7 +70,7 @@
Note: Only the changed fields are updated.
</p>
</h5>
</group>
</div>
</page>
<page
string="Field options"
Expand Down Expand Up @@ -335,25 +335,28 @@
</group>
</group>
<footer>
<span states="init">
<button
name="action_find_records"
string="Next"
class="oe_highlight"
type="object"
/>
</span>
<span states="ready">
<button name="action_init" string="Previous" type="object" />
<button
name="action_update_records"
string="Create/Update"
type="object"
class="oe_highlight"
/>
</span>
<span states="init,ready"> or </span>
<button special="cancel" string="Close" class="oe_link" />
<button
name="action_find_records"
string="Next"
type="object"
class="btn-primary"
states="init"
/>
<button
name="action_init"
string="Previous"
type="object"
class="btn-secondary"
states="ready"
/>
<button
name="action_update_records"
string="Create/Update"
type="object"
class="btn-primary"
states="ready"
/>
<button special="cancel" string="Close" class="btn-secondary" />
</footer>
</form>
</field>
Expand Down

0 comments on commit e515102

Please sign in to comment.