Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions account_chart_update/README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

===========================================================
Detect changes and update the Account Chart from a template
===========================================================
Expand All @@ -17,7 +13,7 @@ Detect changes and update the Account Chart from a template
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
.. |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--financial--tools-lightgray.png?logo=github
Expand Down Expand Up @@ -112,6 +108,7 @@ Contributors
- Luis J. Salvatierra

- Daniel Reis (dreis@opensourceintegrators.com)
- Joel Estrada (https://www.moduon.team/)

Maintainers
-----------
Expand Down
1 change: 1 addition & 0 deletions account_chart_update/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
- [Factor Libre](https://factorlibre.com):
- Luis J. Salvatierra
- Daniel Reis (dreis@opensourceintegrators.com)
- Joel Estrada (<https://www.moduon.team/>)
29 changes: 12 additions & 17 deletions account_chart_update/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>README.rst</title>
<title>Detect changes and update the Account Chart from a template</title>
<style type="text/css">

/*
Expand Down Expand Up @@ -360,21 +360,16 @@
</style>
</head>
<body>
<div class="document">
<div class="document" id="detect-changes-and-update-the-account-chart-from-a-template">
<h1 class="title">Detect changes and update the Account Chart from a template</h1>


<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
</a>
<div class="section" id="detect-changes-and-update-the-account-chart-from-a-template">
<h1>Detect changes and update the Account Chart from a template</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:4d72193905c8f22ba5d52b73b3102141bdfff6d614502cd05450666c53c0b727
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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/license-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><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 @@ -402,7 +397,7 @@ <h1>Detect changes and update the Account Chart from a template</h1>
</ul>
</div>
<div class="section" id="usage">
<h2><a class="toc-backref" href="#toc-entry-1">Usage</a></h2>
<h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
<p>The wizard, accesible from <em>Accounting &gt; Settings &gt; Update Chart
Template</em>, lets the user select what kind of objects must be
checked/updated, and whether old records must be checked for changes and
Expand All @@ -412,7 +407,7 @@ <h2><a class="toc-backref" href="#toc-entry-1">Usage</a></h2>
to exclude records individually.</p>
</div>
<div class="section" id="known-issues-roadmap">
<h2><a class="toc-backref" href="#toc-entry-2">Known issues / Roadmap</a></h2>
<h1><a class="toc-backref" href="#toc-entry-2">Known issues / Roadmap</a></h1>
<ul class="simple">
<li>Generate and update account reconcile models.</li>
<li>Generate XML-ID for fiscal position tax and account mapping lines.</li>
Expand All @@ -422,25 +417,25 @@ <h2><a class="toc-backref" href="#toc-entry-2">Known issues / Roadmap</a></h2>
</ul>
</div>
<div class="section" id="bug-tracker">
<h2><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h2>
<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:%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">
<h2><a class="toc-backref" href="#toc-entry-4">Credits</a></h2>
<h1><a class="toc-backref" href="#toc-entry-4">Credits</a></h1>
<div class="section" id="authors">
<h3><a class="toc-backref" href="#toc-entry-5">Authors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-5">Authors</a></h2>
<ul class="simple">
<li>Tecnativa</li>
<li>BCIM</li>
<li>Okia</li>
</ul>
</div>
<div class="section" id="contributors">
<h3><a class="toc-backref" href="#toc-entry-6">Contributors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<ul class="simple">
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
<li>Pedro M. Baeza</li>
Expand All @@ -460,10 +455,11 @@ <h3><a class="toc-backref" href="#toc-entry-6">Contributors</a></h3>
</ul>
</li>
<li>Daniel Reis (<a class="reference external" href="mailto:dreis&#64;opensourceintegrators.com">dreis&#64;opensourceintegrators.com</a>)</li>
<li>Joel Estrada (<a class="reference external" href="https://www.moduon.team/">https://www.moduon.team/</a>)</li>
</ul>
</div>
<div class="section" id="maintainers">
<h3><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h3>
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
Expand All @@ -476,6 +472,5 @@ <h3><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h3>
</div>
</div>
</div>
</div>
</body>
</html>
65 changes: 50 additions & 15 deletions account_chart_update/wizard/wizard_chart_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,41 +211,60 @@ def _domain_per_name(self, name):
]

def _domain_tax_group_field_ids(self):
return self._domain_per_name("account.tax.group")
return self._domain_per_name("account.tax.group") + [
("ttype", "!=", "one2many")
]

def _domain_tax_field_ids(self):
return self._domain_per_name("account.tax")
# Allow specific o2m fields critical for comparison
# (repartition_line_ids) but exclude other o2m
return self._domain_per_name("account.tax") + [
"|",
("ttype", "!=", "one2many"),
(
"name",
"in",
[
"repartition_line_ids",
],
),
]

def _domain_account_field_ids(self):
return self._domain_per_name("account.account")
return self._domain_per_name("account.account") + [("ttype", "!=", "one2many")]

def _domain_account_group_field_ids(self):
return self._domain_per_name("account.group")
return self._domain_per_name("account.group") + [("ttype", "!=", "one2many")]

def _domain_fp_field_ids(self):
return self._domain_per_name("account.fiscal.position")
return self._domain_per_name("account.fiscal.position") + [
("ttype", "!=", "one2many")
]

def _default_tax_group_field_ids(self):
return [
(4, x.id)
for x in self.env["ir.model.fields"].search(
self._domain_tax_group_field_ids() + [("ttype", "!=", "one2many")],
self._domain_tax_group_field_ids()
+ self.get_uncheck_fields_domain("account.tax.group"),
)
]

def _default_tax_field_ids(self):
return [
(4, x.id)
for x in self.env["ir.model.fields"].search(
self._domain_tax_field_ids() + [("ttype", "!=", "one2many")],
self._domain_tax_field_ids()
+ self.get_uncheck_fields_domain("account.tax"),
)
]

def _default_account_field_ids(self):
return [
(4, x.id)
for x in self.env["ir.model.fields"].search(
self._domain_account_field_ids() + [("ttype", "!=", "one2many")],
self._domain_account_field_ids()
+ self.get_uncheck_fields_domain("account.account"),
)
]

Expand All @@ -254,13 +273,17 @@ def _default_account_group_field_ids(self):
(4, x.id)
for x in self.env["ir.model.fields"].search(
self._domain_account_group_field_ids()
+ self.get_uncheck_fields_domain("account.group")
)
]

def _default_fp_field_ids(self):
return [
(4, x.id)
for x in self.env["ir.model.fields"].search(self._domain_fp_field_ids())
for x in self.env["ir.model.fields"].search(
self._domain_fp_field_ids()
+ self.get_uncheck_fields_domain("account.fiscal.position")
)
]

def _get_matching_ids(self, model_name, ordered_opts):
Expand Down Expand Up @@ -494,22 +517,18 @@ def padded_code(self, code):
def fields_to_ignore(self, name):
"""Get fields that will not be used when checking differences.

:param str template: A template record.
:param str name: The name of the template model.
:return set: Fields to ignore in diff.
"""
mail_thread_fields = set(self.env["mail.thread"]._fields)
specials_mapping = {
"account.tax.group": mail_thread_fields | {"sequence"},
"account.tax": mail_thread_fields | {"children_tax_ids", "sequence"},
"account.tax": mail_thread_fields | {"children_tax_ids"} | {"sequence"},
"account.account": mail_thread_fields
| {
"root_id",
},
"account.group": {"parent_id", "code_prefix_end"},
"account.fiscal.position": {
"sequence",
},
"account.group": {"parent_id"},
}
specials = {
"display_name",
Expand All @@ -518,6 +537,22 @@ def fields_to_ignore(self, name):
} | specials_mapping.get(name, set())
return set(models.MAGIC_COLUMNS) | specials

@api.model
def get_default_unchecked_fields(self, name):
"""Get fields that should be unchecked by default for a given model.

:param str name: The name of the template model.
:return set: Fields to uncheck by default.
"""
unchecked_mapping = {
"account.fiscal.position": {"sequence"},
}
return unchecked_mapping.get(name, set())

def get_uncheck_fields_domain(self, name):
unchecked_fields = list(self.get_default_unchecked_fields(name))
return [("name", "not in", unchecked_fields)]

@api.model
def diff_fields(self, record_values, real): # noqa: C901
"""Get fields that are different in record values and real records.
Expand Down