[FIX+IMP] account_chart_update: Fix fiscal position mapping + translations + clean authors
As this module has been written from scratch with a totally different technique, I clean the list and update copyrights.
This commit is contained in:
parent
88488fd5f1
commit
fa34bca71b
@ -54,13 +54,7 @@ Credits
|
|||||||
Contributors
|
Contributors
|
||||||
------------
|
------------
|
||||||
|
|
||||||
* Jordi Esteve
|
* Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
||||||
* Borja López Soilán
|
|
||||||
* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
|
|
||||||
* Joaquín Gutierrez <joaquingpedrosa@gmail.com>
|
|
||||||
* invitu
|
|
||||||
* Stéphane Bidoul <stephane.bidoul@acsone.eu>
|
|
||||||
* Antonio Espinosa <antonioea@antiun.com>
|
|
||||||
* Jairo Llopis <jairo.llopis@tecnativa.com>
|
* Jairo Llopis <jairo.llopis@tecnativa.com>
|
||||||
* Jacques-Etienne Baudoux <je@bcim.be>
|
* Jacques-Etienne Baudoux <je@bcim.be>
|
||||||
|
|
||||||
|
@ -1,31 +1,21 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# © 2010 Zikzakmedia S.L. (http://www.zikzakmedia.com)
|
# Copyright 2015-2017 Pedro Manuel Baeza <pedro.baeza@tecnativa.com>
|
||||||
# © 2010 Pexego Sistemas Informáticos S.L.(http://www.pexego.es)
|
# Copyright 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
|
||||||
# © 2013 Joaquin Gutierrez (http://www.gutierrezweb.es)
|
# Copyright 2016 Jacques-Etienne Baudoux <je@bcim.be>
|
||||||
# © 2015 Pedro Manuel Baeza <pedro.baeza@serviciosbaeza.com>
|
|
||||||
# © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
|
|
||||||
# © 2016 Jacques-Etienne Baudoux <je@bcim.be>
|
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
{
|
{
|
||||||
'name': "Detect changes and update the Account Chart from a template",
|
'name': "Detect changes and update the Account Chart from a template",
|
||||||
"summary": "Wizard to update a company's account chart from a template",
|
"summary": "Wizard to update a company's account chart from a template",
|
||||||
'version': "9.0.1.0.0",
|
'version': "9.0.1.0.0",
|
||||||
'author': "Zikzakmedia SL, "
|
'author': "Tecnativa, "
|
||||||
"Pexego, "
|
|
||||||
"Serv. Tecnol. Avanzados - Pedro M. Baeza, "
|
|
||||||
"ACSONE A/V, "
|
|
||||||
"Tecnativa, "
|
|
||||||
"BCIM,"
|
"BCIM,"
|
||||||
"Odoo Community Association (OCA)",
|
"Odoo Community Association (OCA)",
|
||||||
'website': "http://odoo-community.org",
|
'website': "http://odoo-community.org",
|
||||||
'depends': ["account"],
|
'depends': ["account"],
|
||||||
'category': "Accounting & Finance",
|
'category': "Accounting & Finance",
|
||||||
'contributors': [
|
'contributors': [
|
||||||
'Joaquín Gutierrez',
|
|
||||||
'Pedro M. Baeza',
|
'Pedro M. Baeza',
|
||||||
'invitu',
|
|
||||||
'Stéphane Bidoul',
|
|
||||||
'Jairo Llopis',
|
'Jairo Llopis',
|
||||||
'Jacques-Etienne Baudoux',
|
'Jacques-Etienne Baudoux',
|
||||||
],
|
],
|
||||||
|
@ -8,14 +8,14 @@
|
|||||||
<field name="model">account.config.settings</field>
|
<field name="model">account.config.settings</field>
|
||||||
<field name="inherit_id" ref="account.view_account_config_settings"/>
|
<field name="inherit_id" ref="account.view_account_config_settings"/>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<xpath expr="//button[@name='%(account.open_account_charts_modules)d']
|
<xpath expr="//button[@name='%(account.open_account_charts_modules)d']/.." position="after">
|
||||||
/.."
|
|
||||||
position="after">
|
|
||||||
<div>
|
<div>
|
||||||
<button string="Update current chart template"
|
<button string="Update chart template"
|
||||||
name="%(action_wizard_update_chart)d"
|
name="%(action_wizard_update_chart)d"
|
||||||
|
context="{'default_company_id': company_id}"
|
||||||
type="action"
|
type="action"
|
||||||
class="oe_link"/>
|
class="oe_link"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</xpath>
|
</xpath>
|
||||||
</field>
|
</field>
|
||||||
|
@ -59,8 +59,7 @@ class WizardUpdateChartsAccounts(models.TransientModel):
|
|||||||
continue_on_errors = fields.Boolean(
|
continue_on_errors = fields.Boolean(
|
||||||
string="Continue on errors", default=False,
|
string="Continue on errors", default=False,
|
||||||
help="If set, the wizard will continue to the next step even if "
|
help="If set, the wizard will continue to the next step even if "
|
||||||
"there are minor errors (for example the parent account "
|
"there are minor errors.")
|
||||||
"of a new account couldn't be set).")
|
|
||||||
tax_ids = fields.One2many(
|
tax_ids = fields.One2many(
|
||||||
comodel_name='wizard.update.charts.accounts.tax', ondelete='cascade',
|
comodel_name='wizard.update.charts.accounts.tax', ondelete='cascade',
|
||||||
inverse_name='update_chart_wizard_id', string='Taxes')
|
inverse_name='update_chart_wizard_id', string='Taxes')
|
||||||
@ -213,7 +212,6 @@ class WizardUpdateChartsAccounts(models.TransientModel):
|
|||||||
def action_find_records(self):
|
def action_find_records(self):
|
||||||
"""Searchs for records to update/create and shows them."""
|
"""Searchs for records to update/create and shows them."""
|
||||||
self = self.with_context(lang=self.lang)
|
self = self.with_context(lang=self.lang)
|
||||||
|
|
||||||
# Search for, and load, the records to create/update.
|
# Search for, and load, the records to create/update.
|
||||||
if self.update_tax:
|
if self.update_tax:
|
||||||
self._find_taxes()
|
self._find_taxes()
|
||||||
@ -221,7 +219,6 @@ class WizardUpdateChartsAccounts(models.TransientModel):
|
|||||||
self._find_accounts()
|
self._find_accounts()
|
||||||
if self.update_fiscal_position:
|
if self.update_fiscal_position:
|
||||||
self._find_fiscal_positions()
|
self._find_fiscal_positions()
|
||||||
|
|
||||||
# Write the results, and go to the next step.
|
# Write the results, and go to the next step.
|
||||||
self.state = 'ready'
|
self.state = 'ready'
|
||||||
return self._reopen()
|
return self._reopen()
|
||||||
@ -309,51 +306,57 @@ class WizardUpdateChartsAccounts(models.TransientModel):
|
|||||||
('company_id', '=', self.company_id.id)])
|
('company_id', '=', self.company_id.id)])
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
@tools.ormcache("templates")
|
@tools.ormcache("templates", "current_fp_accounts")
|
||||||
def find_fp_account_by_templates(self, templates):
|
def find_fp_account_by_templates(self, templates, current_fp_accounts):
|
||||||
result = []
|
result = []
|
||||||
for tpl in templates:
|
for tpl in templates:
|
||||||
pos_id = self.find_fp_by_templates(tpl.position_id).id
|
pos = self.find_fp_by_templates(tpl.position_id)
|
||||||
src_id = self.find_account_by_templates(tpl.account_src_id).id
|
src = self.find_account_by_templates(tpl.account_src_id)
|
||||||
dest_id = self.find_account_by_templates(tpl.account_dest_id).id
|
dest = self.find_account_by_templates(tpl.account_dest_id)
|
||||||
mapping = self.env["account.fiscal.position.account"].search([
|
mappings = self.env["account.fiscal.position.account"].search([
|
||||||
("position_id", "=", pos_id),
|
("position_id", "=", pos.id),
|
||||||
("account_src_id", "=", src_id),
|
("account_src_id", "=", src.id),
|
||||||
], limit=1)
|
])
|
||||||
if not mapping:
|
existing = mappings.filtered(lambda x: x.account_dest_id == dest)
|
||||||
|
if not existing:
|
||||||
# create a new mapping
|
# create a new mapping
|
||||||
result.append((0, 0, {
|
result.append((0, 0, {
|
||||||
'position_id': pos_id,
|
'position_id': pos.id,
|
||||||
'account_src_id': src_id,
|
'account_src_id': src.id,
|
||||||
'account_dest_id': dest_id,
|
'account_dest_id': dest.id,
|
||||||
}))
|
}))
|
||||||
elif mapping.account_dest_id.id != dest_id:
|
else:
|
||||||
# update an existing mapping
|
current_fp_accounts -= existing
|
||||||
result.append((1, mapping.id, {'account_dest_id': dest_id}))
|
# Mark to be removed the lines not found
|
||||||
|
if current_fp_accounts:
|
||||||
|
result += [(2, x.id) for x in current_fp_accounts]
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
@tools.ormcache("templates")
|
@tools.ormcache("templates", "current_fp_taxes")
|
||||||
def find_fp_tax_by_templates(self, templates):
|
def find_fp_tax_by_templates(self, templates, current_fp_taxes):
|
||||||
result = []
|
result = []
|
||||||
for tpl in templates:
|
for tpl in templates:
|
||||||
pos_id = self.find_fp_by_templates(tpl.position_id).id
|
pos = self.find_fp_by_templates(tpl.position_id)
|
||||||
src_id = self.find_tax_by_templates(tpl.tax_src_id).id
|
src = self.find_tax_by_templates(tpl.tax_src_id)
|
||||||
dest_id = self.find_tax_by_templates(tpl.tax_dest_id).id
|
dest = self.find_tax_by_templates(tpl.tax_dest_id)
|
||||||
mapping = self.env["account.fiscal.position.tax"].search([
|
mappings = self.env["account.fiscal.position.tax"].search([
|
||||||
("position_id", "=", pos_id),
|
("position_id", "=", pos.id),
|
||||||
("tax_src_id", "=", src_id),
|
("tax_src_id", "=", src.id),
|
||||||
], limit=1)
|
])
|
||||||
if not mapping:
|
existing = mappings.filtered(lambda x: x.tax_dest_id == dest)
|
||||||
|
if not existing:
|
||||||
# create a new mapping
|
# create a new mapping
|
||||||
result.append((0, 0, {
|
result.append((0, 0, {
|
||||||
'position_id': pos_id,
|
'position_id': pos.id,
|
||||||
'tax_src_id': src_id,
|
'tax_src_id': src.id,
|
||||||
'tax_dest_id': dest_id,
|
'tax_dest_id': dest.id,
|
||||||
}))
|
}))
|
||||||
elif mapping.tax_dest_id.id != dest_id:
|
else:
|
||||||
# update an existing mapping
|
current_fp_taxes -= existing
|
||||||
result.append((1, mapping.id, {'tax_dest_id': dest_id}))
|
# Mark to be removed the lines not found
|
||||||
|
if current_fp_taxes:
|
||||||
|
result += [(2, x.id) for x in current_fp_taxes]
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
@ -376,11 +379,17 @@ class WizardUpdateChartsAccounts(models.TransientModel):
|
|||||||
"refund_account_id",
|
"refund_account_id",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
to_include = {
|
||||||
|
"account.fiscal.position.template": [
|
||||||
|
'tax_ids',
|
||||||
|
'account_ids',
|
||||||
|
],
|
||||||
|
}
|
||||||
specials = ({"display_name", "__last_update"} |
|
specials = ({"display_name", "__last_update"} |
|
||||||
specials.get(template._name, set()))
|
specials.get(template._name, set()))
|
||||||
for key, field in template._fields.iteritems():
|
for key, field in template._fields.iteritems():
|
||||||
if (template._name == "account.fiscal.position.template" and
|
if (template._name in to_include and
|
||||||
key == 'tax_ids'):
|
key in to_include[template._name]):
|
||||||
continue
|
continue
|
||||||
if ".template" in field.get_description(self.env).get(
|
if ".template" in field.get_description(self.env).get(
|
||||||
"relation", ""):
|
"relation", ""):
|
||||||
@ -405,12 +414,10 @@ class WizardUpdateChartsAccounts(models.TransientModel):
|
|||||||
for key, field in template._fields.iteritems():
|
for key, field in template._fields.iteritems():
|
||||||
if key in ignore:
|
if key in ignore:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
relation = expected = t = None
|
relation = expected = t = None
|
||||||
# Code must be padded to check equality
|
# Code must be padded to check equality
|
||||||
if key == "code":
|
if key == "code":
|
||||||
expected = self.padded_code(template.code)
|
expected = self.padded_code(template.code)
|
||||||
|
|
||||||
# Translate template records to reals for comparison
|
# Translate template records to reals for comparison
|
||||||
else:
|
else:
|
||||||
relation = field.get_description(self.env).get("relation", "")
|
relation = field.get_description(self.env).get("relation", "")
|
||||||
@ -426,8 +433,11 @@ class WizardUpdateChartsAccounts(models.TransientModel):
|
|||||||
"fp_" if ".fiscal.position" in relation
|
"fp_" if ".fiscal.position" in relation
|
||||||
else "",
|
else "",
|
||||||
t))
|
t))
|
||||||
|
if ".fiscal.position" in relation:
|
||||||
|
# Special case
|
||||||
|
expected = find(template[key], real[key])
|
||||||
|
else:
|
||||||
expected = find(template[key])
|
expected = find(template[key])
|
||||||
|
|
||||||
# Register detected differences
|
# Register detected differences
|
||||||
try:
|
try:
|
||||||
if not relation:
|
if not relation:
|
||||||
@ -439,7 +449,6 @@ class WizardUpdateChartsAccounts(models.TransientModel):
|
|||||||
result[key] = expected
|
result[key] = expected
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
@ -463,12 +472,10 @@ class WizardUpdateChartsAccounts(models.TransientModel):
|
|||||||
result.append(
|
result.append(
|
||||||
_("Differences in these fields: %s.") %
|
_("Differences in these fields: %s.") %
|
||||||
", ".join(different_fields))
|
", ".join(different_fields))
|
||||||
|
|
||||||
# Special for taxes
|
# Special for taxes
|
||||||
if template._name == "account.tax.template":
|
if template._name == "account.tax.template":
|
||||||
if not real.active:
|
if not real.active:
|
||||||
result.append(_("Tax is disabled."))
|
result.append(_("Tax is disabled."))
|
||||||
|
|
||||||
return "\n".join(result)
|
return "\n".join(result)
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
@ -554,7 +561,6 @@ class WizardUpdateChartsAccounts(models.TransientModel):
|
|||||||
"""Load fiscal position templates to create/update."""
|
"""Load fiscal position templates to create/update."""
|
||||||
wiz_fp = self.env['wizard.update.charts.accounts.fiscal.position']
|
wiz_fp = self.env['wizard.update.charts.accounts.fiscal.position']
|
||||||
self.fiscal_position_ids.unlink()
|
self.fiscal_position_ids.unlink()
|
||||||
|
|
||||||
# Search for new / updated fiscal positions
|
# Search for new / updated fiscal positions
|
||||||
templates = self.env['account.fiscal.position.template'].search(
|
templates = self.env['account.fiscal.position.template'].search(
|
||||||
[('chart_template_id', 'in', self.chart_template_ids.ids)])
|
[('chart_template_id', 'in', self.chart_template_ids.ids)])
|
||||||
@ -715,13 +721,6 @@ class WizardUpdateChartsAccounts(models.TransientModel):
|
|||||||
else:
|
else:
|
||||||
# Update the given fiscal position
|
# Update the given fiscal position
|
||||||
for key, value in self.diff_fields(template, fp).iteritems():
|
for key, value in self.diff_fields(template, fp).iteritems():
|
||||||
if isinstance(value, (list, tuple)):
|
|
||||||
for cmd in value:
|
|
||||||
if cmd[0] == 0:
|
|
||||||
fp[key].create(cmd[2])
|
|
||||||
elif cmd[0] == 1:
|
|
||||||
fp[key].browse(cmd[1]).write(cmd[2])
|
|
||||||
else:
|
|
||||||
fp[key] = value
|
fp[key] = value
|
||||||
wiz_fp.update_fiscal_position_id = fp
|
wiz_fp.update_fiscal_position_id = fp
|
||||||
_logger.debug(
|
_logger.debug(
|
||||||
@ -792,8 +791,8 @@ class WizardUpdateChartsAccountsFiscalPosition(models.TransientModel):
|
|||||||
type = fields.Selection(
|
type = fields.Selection(
|
||||||
selection=[('new', 'New template'),
|
selection=[('new', 'New template'),
|
||||||
('updated', 'Updated template')],
|
('updated', 'Updated template')],
|
||||||
string='Type',
|
string='Type', readonly=True, required=True,
|
||||||
readonly=True)
|
)
|
||||||
update_fiscal_position_id = fields.Many2one(
|
update_fiscal_position_id = fields.Many2one(
|
||||||
comodel_name='account.fiscal.position', required=False,
|
comodel_name='account.fiscal.position', required=False,
|
||||||
string='Fiscal position to update', ondelete='set null')
|
string='Fiscal position to update', ondelete='set null')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user