2013-10-01 18:28:19 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2016-05-25 14:05:38 +02:00
|
|
|
# © 2010 Jordi Esteve, Zikzakmedia S.L. (http://www.zikzakmedia.com)
|
|
|
|
# © 2010 Pexego Sistemas Informáticos S.L.(http://www.pexego.es)
|
|
|
|
# Borja López Soilán
|
|
|
|
# © 2013 Joaquin Gutierrez (http://www.gutierrezweb.es)
|
|
|
|
# © 2015 Antonio Espinosa <antonioea@tecnativa.com>
|
|
|
|
# © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
|
|
|
|
# © 2016 Jacques-Etienne Baudoux <je@bcim.be>
|
2018-09-18 14:41:19 +02:00
|
|
|
# Copyright 2018 Tecnativa - Pedro M. Baeza
|
2016-05-25 14:05:38 +02:00
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
|
|
|
|
2018-09-18 14:41:19 +02:00
|
|
|
from odoo import _, api, exceptions, fields, models, tools
|
|
|
|
from odoo.tools import config
|
2016-05-25 14:05:38 +02:00
|
|
|
from contextlib import closing
|
|
|
|
from cStringIO import StringIO
|
2013-10-01 18:28:19 +02:00
|
|
|
import logging
|
|
|
|
|
2016-05-25 14:05:38 +02:00
|
|
|
_logger = logging.getLogger(__name__)
|
2018-09-18 14:41:19 +02:00
|
|
|
EXCEPTION_TEXT = u"Traceback (most recent call last)"
|
2013-10-01 18:28:19 +02:00
|
|
|
|
|
|
|
|
2015-03-28 14:56:47 +01:00
|
|
|
class WizardUpdateChartsAccounts(models.TransientModel):
|
2013-10-01 18:28:19 +02:00
|
|
|
_name = 'wizard.update.charts.accounts'
|
|
|
|
|
2015-03-28 14:56:47 +01:00
|
|
|
state = fields.Selection(
|
2016-05-25 14:05:38 +02:00
|
|
|
selection=[('init', 'Configuration'),
|
|
|
|
('ready', 'Select records to update'),
|
2015-03-28 14:56:47 +01:00
|
|
|
('done', 'Wizard completed')],
|
|
|
|
string='Status', readonly=True, default='init')
|
|
|
|
company_id = fields.Many2one(
|
|
|
|
comodel_name='res.company', string='Company', required=True,
|
|
|
|
ondelete='set null', default=lambda self: self.env.user.company_id.id)
|
|
|
|
chart_template_id = fields.Many2one(
|
|
|
|
comodel_name='account.chart.template', string='Chart Template',
|
2016-05-25 14:05:38 +02:00
|
|
|
ondelete='cascade', required=True)
|
|
|
|
chart_template_ids = fields.Many2many(
|
|
|
|
"account.chart.template",
|
|
|
|
string="Chart Templates",
|
|
|
|
compute="_compute_chart_template_ids",
|
|
|
|
help="Includes all chart templates.")
|
2015-03-28 14:56:47 +01:00
|
|
|
code_digits = fields.Integer(
|
|
|
|
string='# of digits', required=True,
|
|
|
|
help="No. of digits to use for account code. "
|
|
|
|
"Make sure it is the same number as existing accounts.")
|
|
|
|
lang = fields.Selection(
|
2016-05-25 14:05:38 +02:00
|
|
|
lambda self: self._get_lang_selection_options(), 'Language', size=5,
|
|
|
|
required=True,
|
|
|
|
help="For records searched by name (taxes, fiscal "
|
2015-03-28 14:56:47 +01:00
|
|
|
"positions), the template name will be matched against the "
|
|
|
|
"record name on this language.",
|
2016-05-25 14:05:38 +02:00
|
|
|
default=lambda self: self.env.context.get('lang', self.env.user.lang))
|
2015-03-28 14:56:47 +01:00
|
|
|
update_tax = fields.Boolean(
|
|
|
|
string='Update taxes', default=True,
|
|
|
|
help="Existing taxes are updated. Taxes are searched by name.")
|
|
|
|
update_account = fields.Boolean(
|
|
|
|
string='Update accounts', default=True,
|
|
|
|
help="Existing accounts are updated. Accounts are searched by code.")
|
|
|
|
update_fiscal_position = fields.Boolean(
|
|
|
|
string='Update fiscal positions', default=True,
|
|
|
|
help="Existing fiscal positions are updated. Fiscal positions are "
|
|
|
|
"searched by name.")
|
|
|
|
continue_on_errors = fields.Boolean(
|
|
|
|
string="Continue on errors", default=False,
|
|
|
|
help="If set, the wizard will continue to the next step even if "
|
2017-08-14 19:36:35 +02:00
|
|
|
"there are minor errors.")
|
2015-03-28 14:56:47 +01:00
|
|
|
tax_ids = fields.One2many(
|
|
|
|
comodel_name='wizard.update.charts.accounts.tax', ondelete='cascade',
|
|
|
|
inverse_name='update_chart_wizard_id', string='Taxes')
|
|
|
|
account_ids = fields.One2many(
|
|
|
|
comodel_name='wizard.update.charts.accounts.account',
|
|
|
|
inverse_name='update_chart_wizard_id', string='Accounts',
|
|
|
|
ondelete='cascade')
|
|
|
|
fiscal_position_ids = fields.One2many(
|
|
|
|
comodel_name='wizard.update.charts.accounts.fiscal.position',
|
|
|
|
inverse_name='update_chart_wizard_id', string='Fiscal positions',
|
|
|
|
ondelete='cascade')
|
|
|
|
new_taxes = fields.Integer(
|
2016-05-25 14:05:38 +02:00
|
|
|
string='New taxes', compute="_compute_new_taxes_count")
|
2015-03-28 14:56:47 +01:00
|
|
|
new_accounts = fields.Integer(
|
2016-05-25 14:05:38 +02:00
|
|
|
string='New accounts',
|
|
|
|
compute="_compute_new_accounts_count")
|
2018-09-18 14:41:19 +02:00
|
|
|
rejected_new_account_number = fields.Integer()
|
2015-03-28 14:56:47 +01:00
|
|
|
new_fps = fields.Integer(
|
2016-05-25 14:05:38 +02:00
|
|
|
string='New fiscal positions',
|
|
|
|
compute="_compute_new_fps_count")
|
2015-03-28 14:56:47 +01:00
|
|
|
updated_taxes = fields.Integer(
|
2016-05-25 14:05:38 +02:00
|
|
|
string='Updated taxes',
|
|
|
|
compute="_compute_updated_taxes_count")
|
2018-09-18 14:41:19 +02:00
|
|
|
rejected_updated_account_number = fields.Integer()
|
2015-03-28 14:56:47 +01:00
|
|
|
updated_accounts = fields.Integer(
|
2016-05-25 14:05:38 +02:00
|
|
|
string='Updated accounts',
|
|
|
|
compute="_compute_updated_accounts_count")
|
2015-03-28 14:56:47 +01:00
|
|
|
updated_fps = fields.Integer(
|
2016-05-25 14:05:38 +02:00
|
|
|
string='Updated fiscal positions',
|
|
|
|
compute="_compute_updated_fps_count")
|
2015-03-28 14:56:47 +01:00
|
|
|
deleted_taxes = fields.Integer(
|
2016-05-25 14:05:38 +02:00
|
|
|
string='Deactivated taxes',
|
|
|
|
compute="_compute_deleted_taxes_count")
|
2015-03-28 14:56:47 +01:00
|
|
|
log = fields.Text(string='Messages and Errors', readonly=True)
|
|
|
|
|
2016-05-25 14:05:38 +02:00
|
|
|
@api.model
|
|
|
|
def _get_lang_selection_options(self):
|
|
|
|
"""Gets the available languages for the selection."""
|
|
|
|
langs = self.env['res.lang'].search([])
|
|
|
|
return [(lang.code, lang.name) for lang in langs]
|
2015-03-28 14:56:47 +01:00
|
|
|
|
2016-05-25 14:05:38 +02:00
|
|
|
@api.multi
|
|
|
|
@api.depends("chart_template_id")
|
|
|
|
def _compute_chart_template_ids(self):
|
|
|
|
self.chart_template_ids = (
|
|
|
|
self.env['wizard.multi.charts.accounts']
|
|
|
|
._get_chart_parent_ids(self.chart_template_id))
|
2015-03-28 14:56:47 +01:00
|
|
|
|
2016-05-25 14:05:38 +02:00
|
|
|
@api.multi
|
2015-03-28 14:56:47 +01:00
|
|
|
@api.depends('tax_ids')
|
2016-05-25 14:05:38 +02:00
|
|
|
def _compute_new_taxes_count(self):
|
|
|
|
self.new_taxes = len(self.tax_ids.filtered(lambda x: x.type == 'new'))
|
2015-03-28 14:56:47 +01:00
|
|
|
|
2016-05-25 14:05:38 +02:00
|
|
|
@api.multi
|
2015-03-28 14:56:47 +01:00
|
|
|
@api.depends('account_ids')
|
2016-05-25 14:05:38 +02:00
|
|
|
def _compute_new_accounts_count(self):
|
2015-03-28 14:56:47 +01:00
|
|
|
self.new_accounts = len(
|
2018-09-18 14:41:19 +02:00
|
|
|
self.account_ids.filtered(lambda x: x.type == 'new')
|
|
|
|
) - self.rejected_new_account_number
|
2015-03-28 14:56:47 +01:00
|
|
|
|
2016-05-25 14:05:38 +02:00
|
|
|
@api.multi
|
2015-03-28 14:56:47 +01:00
|
|
|
@api.depends('fiscal_position_ids')
|
2016-05-25 14:05:38 +02:00
|
|
|
def _compute_new_fps_count(self):
|
2015-03-28 14:56:47 +01:00
|
|
|
self.new_fps = len(
|
2016-05-25 14:05:38 +02:00
|
|
|
self.fiscal_position_ids.filtered(lambda x: x.type == 'new'))
|
2015-03-28 14:56:47 +01:00
|
|
|
|
2016-05-25 14:05:38 +02:00
|
|
|
@api.multi
|
2015-03-28 14:56:47 +01:00
|
|
|
@api.depends('tax_ids')
|
2016-05-25 14:05:38 +02:00
|
|
|
def _compute_updated_taxes_count(self):
|
2015-03-28 14:56:47 +01:00
|
|
|
self.updated_taxes = len(
|
2016-05-25 14:05:38 +02:00
|
|
|
self.tax_ids.filtered(lambda x: x.type == 'updated'))
|
2015-03-28 14:56:47 +01:00
|
|
|
|
2016-05-25 14:05:38 +02:00
|
|
|
@api.multi
|
2015-03-28 14:56:47 +01:00
|
|
|
@api.depends('account_ids')
|
2016-05-25 14:05:38 +02:00
|
|
|
def _compute_updated_accounts_count(self):
|
2015-03-28 14:56:47 +01:00
|
|
|
self.updated_accounts = len(
|
2018-09-18 14:41:19 +02:00
|
|
|
self.account_ids.filtered(lambda x: x.type == 'updated')
|
|
|
|
) - self.rejected_updated_account_number
|
2015-03-28 14:56:47 +01:00
|
|
|
|
2016-05-25 14:05:38 +02:00
|
|
|
@api.multi
|
2015-03-28 14:56:47 +01:00
|
|
|
@api.depends('fiscal_position_ids')
|
2016-05-25 14:05:38 +02:00
|
|
|
def _compute_updated_fps_count(self):
|
2015-03-28 14:56:47 +01:00
|
|
|
self.updated_fps = len(
|
2016-05-25 14:05:38 +02:00
|
|
|
self.fiscal_position_ids.filtered(lambda x: x.type == 'updated'))
|
2015-03-28 14:56:47 +01:00
|
|
|
|
2016-05-25 14:05:38 +02:00
|
|
|
@api.multi
|
2015-03-28 14:56:47 +01:00
|
|
|
@api.depends('tax_ids')
|
2016-05-25 14:05:38 +02:00
|
|
|
def _compute_deleted_taxes_count(self):
|
2015-03-28 14:56:47 +01:00
|
|
|
self.deleted_taxes = len(
|
2016-05-25 14:05:38 +02:00
|
|
|
self.tax_ids.filtered(lambda x: x.type == 'deleted'))
|
2013-10-01 18:28:19 +02:00
|
|
|
|
2015-03-28 14:56:47 +01:00
|
|
|
@api.multi
|
2016-05-25 14:05:38 +02:00
|
|
|
@api.onchange("company_id")
|
|
|
|
def _onchage_company_update_chart_template(self):
|
|
|
|
self.chart_template_id = self.company_id.chart_template_id
|
2013-10-01 18:28:19 +02:00
|
|
|
|
2015-03-28 14:56:47 +01:00
|
|
|
@api.model
|
|
|
|
def _get_code_digits(self, company=None):
|
2017-11-02 17:34:58 +01:00
|
|
|
"""Returns the number of digits for the accounts, fetched from
|
|
|
|
the company.
|
2014-06-30 11:12:36 +02:00
|
|
|
"""
|
2017-11-02 17:34:58 +01:00
|
|
|
if company is None:
|
2015-03-28 14:56:47 +01:00
|
|
|
company = self.env.user.company_id
|
2017-11-02 17:34:58 +01:00
|
|
|
return company.accounts_code_digits or 6
|
2013-10-01 18:28:19 +02:00
|
|
|
|
2015-03-28 14:56:47 +01:00
|
|
|
@api.onchange('company_id')
|
|
|
|
def onchange_company_id(self):
|
|
|
|
"""Update the code digits when the company changes"""
|
|
|
|
self.code_digits = self._get_code_digits(company=self.company_id)
|
|
|
|
|
2016-05-25 14:05:38 +02:00
|
|
|
@api.multi
|
|
|
|
def _reopen(self):
|
|
|
|
return {
|
|
|
|
'type': 'ir.actions.act_window',
|
|
|
|
'view_mode': 'form',
|
|
|
|
'view_type': 'form',
|
|
|
|
'res_id': self.id,
|
|
|
|
'res_model': self._name,
|
|
|
|
'target': 'new',
|
|
|
|
# save original model in context,
|
|
|
|
# because selecting the list of available
|
|
|
|
# templates requires a model in context
|
|
|
|
'context': {
|
|
|
|
'default_model': self._name,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2015-03-28 14:56:47 +01:00
|
|
|
@api.multi
|
|
|
|
def action_init(self):
|
|
|
|
"""Initial action that sets the initial state."""
|
2016-05-25 14:05:38 +02:00
|
|
|
self.state = 'init'
|
|
|
|
return self._reopen()
|
2015-03-28 14:56:47 +01:00
|
|
|
|
|
|
|
@api.multi
|
|
|
|
def action_find_records(self):
|
|
|
|
"""Searchs for records to update/create and shows them."""
|
|
|
|
self = self.with_context(lang=self.lang)
|
|
|
|
# Search for, and load, the records to create/update.
|
|
|
|
if self.update_tax:
|
2016-05-25 14:05:38 +02:00
|
|
|
self._find_taxes()
|
2015-03-28 14:56:47 +01:00
|
|
|
if self.update_account:
|
2016-05-25 14:05:38 +02:00
|
|
|
self._find_accounts()
|
2015-03-28 14:56:47 +01:00
|
|
|
if self.update_fiscal_position:
|
2016-05-25 14:05:38 +02:00
|
|
|
self._find_fiscal_positions()
|
2015-03-28 14:56:47 +01:00
|
|
|
# Write the results, and go to the next step.
|
2016-05-25 14:05:38 +02:00
|
|
|
self.state = 'ready'
|
|
|
|
return self._reopen()
|
2013-10-01 18:28:19 +02:00
|
|
|
|
2015-03-28 14:56:47 +01:00
|
|
|
@api.multi
|
|
|
|
def action_update_records(self):
|
2016-05-25 14:05:38 +02:00
|
|
|
"""Action that creates/updates/deletes the selected elements."""
|
|
|
|
self = self.with_context(lang=self.lang)
|
2018-09-18 14:41:19 +02:00
|
|
|
self.rejected_new_account_number = 0
|
|
|
|
self.rejected_updated_account_number = 0
|
2016-05-25 14:05:38 +02:00
|
|
|
with closing(StringIO()) as log_output:
|
|
|
|
handler = logging.StreamHandler(log_output)
|
|
|
|
_logger.addHandler(handler)
|
|
|
|
# Create or update the records.
|
|
|
|
if self.update_tax:
|
|
|
|
self._update_taxes()
|
2018-09-18 14:41:19 +02:00
|
|
|
perform_rest = True
|
2016-05-25 14:05:38 +02:00
|
|
|
if self.update_account:
|
|
|
|
self._update_accounts()
|
2018-09-18 14:41:19 +02:00
|
|
|
if (EXCEPTION_TEXT in log_output.getvalue() and
|
|
|
|
not self.continue_on_errors): # Abort early
|
|
|
|
perform_rest = False
|
|
|
|
# Clear this cache for avoiding incorrect account hits (as it was
|
|
|
|
# queried before account creation)
|
|
|
|
self.find_account_by_templates.clear_cache(self)
|
|
|
|
if self.update_tax and perform_rest:
|
|
|
|
self._update_taxes_pending_for_accounts()
|
|
|
|
if self.update_fiscal_position and perform_rest:
|
2016-05-25 14:05:38 +02:00
|
|
|
self._update_fiscal_positions()
|
|
|
|
# Store new chart in the company
|
|
|
|
self.company_id.chart_template_id = self.chart_template_id
|
|
|
|
_logger.removeHandler(handler)
|
|
|
|
self.log = log_output.getvalue()
|
|
|
|
# Check if errors where detected and wether we should stop.
|
2018-09-18 14:41:19 +02:00
|
|
|
if EXCEPTION_TEXT in self.log and not self.continue_on_errors:
|
2016-05-25 14:05:38 +02:00
|
|
|
raise exceptions.Warning(
|
|
|
|
_("One or more errors detected!\n\n%s") % self.log)
|
|
|
|
# Store the data and go to the next step.
|
|
|
|
self.state = 'done'
|
|
|
|
return self._reopen()
|
2015-03-28 14:56:47 +01:00
|
|
|
|
|
|
|
@api.multi
|
2016-05-25 14:05:38 +02:00
|
|
|
@tools.ormcache("templates")
|
|
|
|
def find_tax_by_templates(self, templates):
|
|
|
|
"""Find a tax that matches the template."""
|
2015-03-28 14:56:47 +01:00
|
|
|
# search inactive taxes too, to avoid re-creating
|
|
|
|
# taxes that have been deactivated before
|
2016-05-25 14:05:38 +02:00
|
|
|
Tax = self.env['account.tax'].with_context(active_test=False)
|
|
|
|
result = Tax
|
|
|
|
for template in templates:
|
|
|
|
single = Tax
|
|
|
|
criteria = (
|
|
|
|
("name", "=", template.name),
|
|
|
|
("description", "=", template.name),
|
|
|
|
("name", "=", template.description),
|
|
|
|
("description", "=", template.description),
|
|
|
|
)
|
|
|
|
for domain in criteria:
|
|
|
|
if single:
|
|
|
|
break
|
|
|
|
if domain[2]:
|
|
|
|
single = Tax.search(
|
|
|
|
[domain,
|
|
|
|
("company_id", "=", self.company_id.id),
|
|
|
|
("type_tax_use", "=", template.type_tax_use)],
|
|
|
|
limit=1)
|
|
|
|
result |= single
|
2018-09-18 14:59:54 +02:00
|
|
|
return result[:1].id
|
2016-05-25 14:05:38 +02:00
|
|
|
|
|
|
|
@api.model
|
|
|
|
@tools.ormcache("code")
|
|
|
|
def padded_code(self, code):
|
|
|
|
"""Return a right-zero-padded code with the chosen digits."""
|
|
|
|
return code.ljust(self.code_digits, '0')
|
2015-03-28 14:56:47 +01:00
|
|
|
|
|
|
|
@api.multi
|
2016-05-25 14:05:38 +02:00
|
|
|
@tools.ormcache("templates")
|
|
|
|
def find_account_by_templates(self, templates):
|
|
|
|
"""Find an account that matches the template."""
|
|
|
|
return self.env['account.account'].search(
|
|
|
|
[('code', 'in', map(self.padded_code, templates.mapped("code"))),
|
2018-09-18 14:59:54 +02:00
|
|
|
('company_id', '=', self.company_id.id)],
|
|
|
|
).id
|
2015-03-28 14:56:47 +01:00
|
|
|
|
|
|
|
@api.multi
|
2016-05-25 14:05:38 +02:00
|
|
|
@tools.ormcache("templates")
|
|
|
|
def find_fp_by_templates(self, templates):
|
|
|
|
"""Find a real fiscal position from a template."""
|
|
|
|
return self.env['account.fiscal.position'].search(
|
|
|
|
[('name', 'in', templates.mapped("name")),
|
2018-09-18 14:59:54 +02:00
|
|
|
('company_id', '=', self.company_id.id)], limit=1).id
|
2016-05-25 14:05:38 +02:00
|
|
|
|
|
|
|
@api.multi
|
2017-08-14 19:36:35 +02:00
|
|
|
@tools.ormcache("templates", "current_fp_accounts")
|
|
|
|
def find_fp_account_by_templates(self, templates, current_fp_accounts):
|
2016-05-25 14:05:38 +02:00
|
|
|
result = []
|
|
|
|
for tpl in templates:
|
2018-09-18 14:59:54 +02:00
|
|
|
pos_id = self.find_fp_by_templates(tpl.position_id)
|
|
|
|
src_id = self.find_account_by_templates(tpl.account_src_id)
|
|
|
|
dest_id = self.find_account_by_templates(tpl.account_dest_id)
|
2018-09-18 14:41:19 +02:00
|
|
|
existing = self.env["account.fiscal.position.account"].search([
|
2018-09-18 14:59:54 +02:00
|
|
|
("position_id", "=", pos_id),
|
|
|
|
("account_src_id", "=", src_id),
|
2018-09-18 14:41:19 +02:00
|
|
|
("account_dest_id", "=", dest_id),
|
2017-08-14 19:36:35 +02:00
|
|
|
])
|
|
|
|
if not existing:
|
2016-05-25 14:05:38 +02:00
|
|
|
# create a new mapping
|
|
|
|
result.append((0, 0, {
|
2018-09-18 14:59:54 +02:00
|
|
|
'position_id': pos_id,
|
|
|
|
'account_src_id': src_id,
|
|
|
|
'account_dest_id': dest_id,
|
2017-08-14 19:36:35 +02:00
|
|
|
}))
|
|
|
|
else:
|
|
|
|
current_fp_accounts -= existing
|
|
|
|
# Mark to be removed the lines not found
|
|
|
|
if current_fp_accounts:
|
|
|
|
result += [(2, x.id) for x in current_fp_accounts]
|
2016-05-25 14:05:38 +02:00
|
|
|
return result
|
|
|
|
|
|
|
|
@api.multi
|
2017-08-14 19:36:35 +02:00
|
|
|
@tools.ormcache("templates", "current_fp_taxes")
|
|
|
|
def find_fp_tax_by_templates(self, templates, current_fp_taxes):
|
2016-05-25 14:05:38 +02:00
|
|
|
result = []
|
|
|
|
for tpl in templates:
|
2018-09-18 14:59:54 +02:00
|
|
|
pos_id = self.find_fp_by_templates(tpl.position_id)
|
|
|
|
src_id = self.find_tax_by_templates(tpl.tax_src_id)
|
|
|
|
dest_id = self.find_tax_by_templates(tpl.tax_dest_id)
|
2018-09-18 14:41:19 +02:00
|
|
|
existing = self.env["account.fiscal.position.tax"].search([
|
2018-09-18 14:59:54 +02:00
|
|
|
("position_id", "=", pos_id),
|
|
|
|
("tax_src_id", "=", src_id),
|
2018-09-18 14:41:19 +02:00
|
|
|
("tax_dest_id", "=", dest_id),
|
2017-08-14 19:36:35 +02:00
|
|
|
])
|
|
|
|
if not existing:
|
2016-05-25 14:05:38 +02:00
|
|
|
# create a new mapping
|
|
|
|
result.append((0, 0, {
|
2018-09-18 14:59:54 +02:00
|
|
|
'position_id': pos_id,
|
|
|
|
'tax_src_id': src_id,
|
|
|
|
'tax_dest_id': dest_id,
|
2017-08-14 19:36:35 +02:00
|
|
|
}))
|
|
|
|
else:
|
|
|
|
current_fp_taxes -= existing
|
|
|
|
# Mark to be removed the lines not found
|
|
|
|
if current_fp_taxes:
|
|
|
|
result += [(2, x.id) for x in current_fp_taxes]
|
2016-05-25 14:05:38 +02:00
|
|
|
return result
|
|
|
|
|
|
|
|
@api.model
|
2018-09-18 14:41:19 +02:00
|
|
|
@tools.ormcache("name")
|
|
|
|
def fields_to_ignore(self, template, name):
|
2016-05-25 14:05:38 +02:00
|
|
|
"""Get fields that will not be used when checking differences.
|
|
|
|
|
2018-09-18 14:41:19 +02:00
|
|
|
:param str template: A template record.
|
|
|
|
:param str name: The name of the template model.
|
|
|
|
:return set: Fields to ignore in diff.
|
2014-03-21 02:01:05 +01:00
|
|
|
"""
|
2018-09-18 14:41:19 +02:00
|
|
|
specials_mapping = {
|
|
|
|
"account.tax.template": {
|
|
|
|
"children_tax_ids",
|
|
|
|
},
|
2016-05-25 14:05:38 +02:00
|
|
|
"account.account.template": {
|
|
|
|
"code",
|
|
|
|
},
|
2017-08-14 19:36:35 +02:00
|
|
|
}
|
2018-09-18 14:41:19 +02:00
|
|
|
specials = ({"display_name", "__last_update", "company_id"} |
|
|
|
|
specials_mapping.get(name, set()))
|
2016-05-25 14:05:38 +02:00
|
|
|
return set(models.MAGIC_COLUMNS) | specials
|
|
|
|
|
|
|
|
@api.model
|
|
|
|
def diff_fields(self, template, real):
|
|
|
|
"""Get fields that are different in template and real records.
|
|
|
|
|
2017-03-14 11:54:08 +01:00
|
|
|
:param odoo.models.Model template:
|
2016-05-25 14:05:38 +02:00
|
|
|
Template record.
|
2017-03-14 11:54:08 +01:00
|
|
|
:param odoo.models.Model real:
|
2016-05-25 14:05:38 +02:00
|
|
|
Real record.
|
|
|
|
|
|
|
|
:return dict:
|
|
|
|
Fields that are different in both records, and the expected value.
|
2014-03-21 02:01:05 +01:00
|
|
|
"""
|
2016-05-25 14:05:38 +02:00
|
|
|
result = dict()
|
2018-09-18 14:41:19 +02:00
|
|
|
ignore = self.fields_to_ignore(template, template._name)
|
2016-05-25 14:05:38 +02:00
|
|
|
for key, field in template._fields.iteritems():
|
|
|
|
if key in ignore:
|
|
|
|
continue
|
2018-09-18 14:41:19 +02:00
|
|
|
expected = t = None
|
2016-05-25 14:05:38 +02:00
|
|
|
# Translate template records to reals for comparison
|
2018-09-18 14:41:19 +02:00
|
|
|
relation = field.get_description(self.env).get("relation", "")
|
|
|
|
if relation:
|
|
|
|
if ".tax.template" in relation:
|
|
|
|
t = "tax"
|
|
|
|
elif ".account.template" in relation:
|
|
|
|
t = "account"
|
|
|
|
if t:
|
|
|
|
find = getattr(
|
|
|
|
self,
|
|
|
|
"find_%s%s_by_templates" % (
|
|
|
|
"fp_" if ".fiscal.position" in relation
|
|
|
|
else "",
|
|
|
|
t))
|
|
|
|
if ".fiscal.position" in relation:
|
|
|
|
# Special case: if something is returned, then
|
|
|
|
# there's any difference, so it will get non equal
|
|
|
|
# when comparing, although we get the warning
|
|
|
|
# "Comparing apples with oranges"
|
|
|
|
expected = find(template[key], real[key])
|
|
|
|
else:
|
|
|
|
exp_id = find(template[key])
|
|
|
|
expected = self.env[relation[:-9]].browse(exp_id)
|
2016-05-25 14:05:38 +02:00
|
|
|
# Register detected differences
|
|
|
|
try:
|
2018-09-18 14:41:19 +02:00
|
|
|
if expected is not None:
|
|
|
|
if expected != [] and expected != real[key]:
|
2016-05-25 14:05:38 +02:00
|
|
|
result[key] = expected
|
2018-09-18 14:41:19 +02:00
|
|
|
elif template[key] != real[key]:
|
|
|
|
result[key] = template[key]
|
|
|
|
if isinstance(result.get(key, False), models.Model):
|
|
|
|
# Avoid to cache recordset references
|
|
|
|
result[key] = result[key].id
|
2016-05-25 14:05:38 +02:00
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
return result
|
|
|
|
|
|
|
|
@api.model
|
|
|
|
def diff_notes(self, template, real):
|
|
|
|
"""Get notes for humans on why is this record going to be updated.
|
|
|
|
|
|
|
|
:param openerp.models.Model template:
|
|
|
|
Template record.
|
|
|
|
|
|
|
|
:param openerp.models.Model real:
|
|
|
|
Real record.
|
|
|
|
|
|
|
|
:return str:
|
|
|
|
Notes result.
|
2014-03-21 02:01:05 +01:00
|
|
|
"""
|
2016-05-25 14:05:38 +02:00
|
|
|
result = list()
|
|
|
|
different_fields = sorted(
|
|
|
|
template._fields[f].get_description(self.env)["string"]
|
|
|
|
for f in self.diff_fields(template, real).keys())
|
|
|
|
if different_fields:
|
|
|
|
result.append(
|
|
|
|
_("Differences in these fields: %s.") %
|
|
|
|
", ".join(different_fields))
|
|
|
|
# Special for taxes
|
|
|
|
if template._name == "account.tax.template":
|
|
|
|
if not real.active:
|
|
|
|
result.append(_("Tax is disabled."))
|
|
|
|
return "\n".join(result)
|
|
|
|
|
|
|
|
@api.multi
|
|
|
|
def _find_taxes(self):
|
|
|
|
"""Search for, and load, tax templates to create/update/delete."""
|
2018-09-18 14:59:54 +02:00
|
|
|
found_taxes_ids = []
|
2015-03-28 14:56:47 +01:00
|
|
|
self.tax_ids.unlink()
|
2016-05-25 14:05:38 +02:00
|
|
|
# Search for changes between template and real tax
|
|
|
|
for template in self.chart_template_ids.mapped("tax_template_ids"):
|
|
|
|
# Check if the template matches a real tax
|
2018-09-18 14:59:54 +02:00
|
|
|
tax_id = self.find_tax_by_templates(template)
|
|
|
|
if not tax_id:
|
2016-05-25 14:05:38 +02:00
|
|
|
# Tax to be created
|
|
|
|
self.tax_ids.create({
|
|
|
|
'tax_id': template.id,
|
2015-03-28 14:56:47 +01:00
|
|
|
'update_chart_wizard_id': self.id,
|
2013-10-01 18:28:19 +02:00
|
|
|
'type': 'new',
|
2014-03-21 02:01:05 +01:00
|
|
|
'notes': _('Name or description not found.'),
|
2016-05-25 14:05:38 +02:00
|
|
|
})
|
2015-03-28 14:56:47 +01:00
|
|
|
else:
|
2018-09-18 14:59:54 +02:00
|
|
|
found_taxes_ids.append(tax_id)
|
2016-05-25 14:05:38 +02:00
|
|
|
# Check the tax for changes
|
2018-09-18 14:59:54 +02:00
|
|
|
tax = self.env['account.tax'].browse(tax_id)
|
2016-05-25 14:05:38 +02:00
|
|
|
notes = self.diff_notes(template, tax)
|
2015-03-28 14:56:47 +01:00
|
|
|
if notes:
|
2016-05-25 14:05:38 +02:00
|
|
|
# Tax to be updated
|
|
|
|
self.tax_ids.create({
|
|
|
|
'tax_id': template.id,
|
2015-03-28 14:56:47 +01:00
|
|
|
'update_chart_wizard_id': self.id,
|
2013-10-01 18:28:19 +02:00
|
|
|
'type': 'updated',
|
2018-09-18 14:59:54 +02:00
|
|
|
'update_tax_id': tax_id,
|
2013-10-01 18:28:19 +02:00
|
|
|
'notes': notes,
|
2015-03-28 14:56:47 +01:00
|
|
|
})
|
|
|
|
# search for taxes not in the template and propose them for
|
|
|
|
# deactivation
|
2018-09-18 14:41:19 +02:00
|
|
|
taxes_to_deactivate = self.env['account.tax'].search(
|
2016-05-25 14:05:38 +02:00
|
|
|
[('company_id', '=', self.company_id.id),
|
2018-09-18 14:59:54 +02:00
|
|
|
("id", "not in", found_taxes_ids),
|
2016-05-25 14:05:38 +02:00
|
|
|
("active", "=", True)])
|
2018-09-18 14:41:19 +02:00
|
|
|
for tax in taxes_to_deactivate:
|
2016-05-25 14:05:38 +02:00
|
|
|
self.tax_ids.create({
|
2015-03-28 14:56:47 +01:00
|
|
|
'update_chart_wizard_id': self.id,
|
2014-12-24 00:23:39 +01:00
|
|
|
'type': 'deleted',
|
2016-05-25 14:05:38 +02:00
|
|
|
'update_tax_id': tax.id,
|
2015-03-28 14:56:47 +01:00
|
|
|
'notes': _("To deactivate: not in the template"),
|
|
|
|
})
|
|
|
|
|
2016-05-25 14:05:38 +02:00
|
|
|
@api.multi
|
|
|
|
def _find_accounts(self):
|
|
|
|
"""Load account templates to create/update."""
|
2016-02-21 20:05:33 +01:00
|
|
|
self.account_ids.unlink()
|
2016-05-25 14:05:38 +02:00
|
|
|
for template in self.chart_template_ids.mapped("account_ids"):
|
|
|
|
# Search for a real account that matches the template
|
2018-09-18 14:59:54 +02:00
|
|
|
account_id = self.find_account_by_templates(template)
|
|
|
|
if not account_id:
|
2016-05-25 14:05:38 +02:00
|
|
|
# Account to be created
|
|
|
|
self.account_ids.create({
|
|
|
|
'account_id': template.id,
|
2015-03-28 14:56:47 +01:00
|
|
|
'update_chart_wizard_id': self.id,
|
2013-10-01 18:28:19 +02:00
|
|
|
'type': 'new',
|
2016-05-25 14:05:38 +02:00
|
|
|
'notes': _('No account found with this code.'),
|
2015-03-28 14:56:47 +01:00
|
|
|
})
|
|
|
|
else:
|
2016-05-25 14:05:38 +02:00
|
|
|
# Check the account for changes
|
2018-09-18 14:59:54 +02:00
|
|
|
account = self.env['account.account'].browse(account_id)
|
2016-05-25 14:05:38 +02:00
|
|
|
notes = self.diff_notes(template, account)
|
2015-03-28 14:56:47 +01:00
|
|
|
if notes:
|
2016-05-25 14:05:38 +02:00
|
|
|
# Account to be updated
|
|
|
|
self.account_ids.create({
|
|
|
|
'account_id': template.id,
|
2015-03-28 14:56:47 +01:00
|
|
|
'update_chart_wizard_id': self.id,
|
2013-10-01 18:28:19 +02:00
|
|
|
'type': 'updated',
|
2018-09-18 14:59:54 +02:00
|
|
|
'update_account_id': account_id,
|
2013-10-01 18:28:19 +02:00
|
|
|
'notes': notes,
|
2015-03-28 14:56:47 +01:00
|
|
|
})
|
|
|
|
|
2016-05-25 14:05:38 +02:00
|
|
|
@api.multi
|
|
|
|
def _find_fiscal_positions(self):
|
|
|
|
"""Load fiscal position templates to create/update."""
|
2015-03-28 14:56:47 +01:00
|
|
|
wiz_fp = self.env['wizard.update.charts.accounts.fiscal.position']
|
|
|
|
self.fiscal_position_ids.unlink()
|
2017-03-14 11:54:08 +01:00
|
|
|
|
2013-10-01 18:28:19 +02:00
|
|
|
# Search for new / updated fiscal positions
|
2016-05-25 14:05:38 +02:00
|
|
|
templates = self.env['account.fiscal.position.template'].search(
|
|
|
|
[('chart_template_id', 'in', self.chart_template_ids.ids)])
|
|
|
|
for template in templates:
|
|
|
|
# Search for a real fiscal position that matches the template
|
2018-09-18 14:59:54 +02:00
|
|
|
fp_id = self.find_fp_by_templates(template)
|
|
|
|
if not fp_id:
|
2016-05-25 14:05:38 +02:00
|
|
|
# Fiscal position to be created
|
2015-03-28 14:56:47 +01:00
|
|
|
wiz_fp.create({
|
2016-05-25 14:05:38 +02:00
|
|
|
'fiscal_position_id': template.id,
|
2015-03-28 14:56:47 +01:00
|
|
|
'update_chart_wizard_id': self.id,
|
2013-10-01 18:28:19 +02:00
|
|
|
'type': 'new',
|
2016-05-25 14:05:38 +02:00
|
|
|
'notes': _('No fiscal position found with this name.')
|
2015-03-28 14:56:47 +01:00
|
|
|
})
|
2016-05-25 14:05:38 +02:00
|
|
|
else:
|
|
|
|
# Check the fiscal position for changes
|
2018-09-18 14:59:54 +02:00
|
|
|
fp = self.env['account.fiscal.position'].browse(fp_id)
|
2016-05-25 14:05:38 +02:00
|
|
|
notes = self.diff_notes(template, fp)
|
|
|
|
if notes:
|
|
|
|
# Fiscal position template to be updated
|
|
|
|
wiz_fp.create({
|
|
|
|
'fiscal_position_id': template.id,
|
|
|
|
'update_chart_wizard_id': self.id,
|
|
|
|
'type': 'updated',
|
2018-09-18 14:59:54 +02:00
|
|
|
'update_fiscal_position_id': fp_id,
|
2016-05-25 14:05:38 +02:00
|
|
|
'notes': notes,
|
|
|
|
})
|
2013-10-01 18:28:19 +02:00
|
|
|
|
2015-03-28 14:56:47 +01:00
|
|
|
@api.multi
|
2016-05-25 14:05:38 +02:00
|
|
|
def _update_taxes(self):
|
|
|
|
"""Process taxes to create/update/deactivate."""
|
2015-03-28 14:56:47 +01:00
|
|
|
for wiz_tax in self.tax_ids:
|
2016-05-25 14:05:38 +02:00
|
|
|
template, tax = wiz_tax.tax_id, wiz_tax.update_tax_id
|
|
|
|
# Deactivate tax
|
2014-12-24 00:23:39 +01:00
|
|
|
if wiz_tax.type == 'deleted':
|
2016-05-25 14:05:38 +02:00
|
|
|
tax.active = False
|
2018-09-18 14:41:19 +02:00
|
|
|
_logger.info(_("Deactivated tax %s."), "'%s'" % tax.name)
|
2014-12-24 00:23:39 +01:00
|
|
|
continue
|
2016-05-25 14:05:38 +02:00
|
|
|
# Create tax
|
2013-10-01 18:28:19 +02:00
|
|
|
if wiz_tax.type == 'new':
|
2018-09-18 14:41:19 +02:00
|
|
|
template._generate_tax(self.company_id)
|
|
|
|
_logger.info(_("Created tax %s."), "'%s'" % template.name)
|
2016-05-25 14:05:38 +02:00
|
|
|
# Update tax
|
|
|
|
else:
|
|
|
|
for key, value in self.diff_fields(template, tax).iteritems():
|
2018-09-18 14:41:19 +02:00
|
|
|
# We defer update because account might not be created yet
|
|
|
|
if key in {'account_id', 'refund_account_id'}:
|
|
|
|
continue
|
2016-05-25 14:05:38 +02:00
|
|
|
tax[key] = value
|
2018-09-18 14:41:19 +02:00
|
|
|
_logger.info(_("Updated tax %s."), "'%s'" % template.name)
|
2015-03-28 14:56:47 +01:00
|
|
|
|
|
|
|
@api.multi
|
2016-05-25 14:05:38 +02:00
|
|
|
def _update_accounts(self):
|
2015-03-28 14:56:47 +01:00
|
|
|
"""Process accounts to create/update."""
|
|
|
|
for wiz_account in self.account_ids:
|
2016-05-25 14:05:38 +02:00
|
|
|
account, template = (wiz_account.update_account_id,
|
|
|
|
wiz_account.account_id)
|
2013-10-01 18:28:19 +02:00
|
|
|
if wiz_account.type == 'new':
|
|
|
|
# Create the account
|
2018-09-18 14:41:19 +02:00
|
|
|
tax_template_ref = {
|
|
|
|
tax.id: self.find_tax_by_templates(tax) for tax in
|
|
|
|
template.tax_ids
|
|
|
|
}
|
|
|
|
vals = self.chart_template_id._get_account_vals(
|
|
|
|
self.company_id, template,
|
|
|
|
self.padded_code(template.code),
|
|
|
|
tax_template_ref,
|
|
|
|
)
|
2013-10-01 18:28:19 +02:00
|
|
|
try:
|
2016-05-25 14:05:38 +02:00
|
|
|
with self.env.cr.savepoint():
|
2018-09-18 14:41:19 +02:00
|
|
|
self.chart_template_id.create_record_with_xmlid(
|
|
|
|
self.company_id, template, 'account.account', vals,
|
|
|
|
)
|
|
|
|
_logger.info(
|
2016-05-25 14:05:38 +02:00
|
|
|
_("Created account %s."),
|
2018-09-18 14:41:19 +02:00
|
|
|
"'%s - %s'" % (vals['code'], vals['name']),
|
|
|
|
)
|
|
|
|
except Exception:
|
|
|
|
self.rejected_new_account_number += 1
|
|
|
|
if config['test_enable']:
|
|
|
|
_logger.info(EXCEPTION_TEXT)
|
|
|
|
else: # pragma: no cover
|
|
|
|
_logger.exception(
|
|
|
|
"ERROR: " + _("Exception creating account %s."),
|
|
|
|
"'%s - %s'" % (template.code, template.name),
|
|
|
|
)
|
|
|
|
if not self.continue_on_errors:
|
|
|
|
break
|
2015-03-28 14:56:47 +01:00
|
|
|
else:
|
2013-10-01 18:28:19 +02:00
|
|
|
# Update the account
|
|
|
|
try:
|
2016-05-25 14:05:38 +02:00
|
|
|
with self.env.cr.savepoint():
|
|
|
|
for key, value in (self.diff_fields(template, account)
|
|
|
|
.iteritems()):
|
|
|
|
account[key] = value
|
2018-09-18 14:41:19 +02:00
|
|
|
_logger.info(
|
|
|
|
_("Updated account %s."),
|
|
|
|
"'%s - %s'" % (account.code, account.name),
|
|
|
|
)
|
|
|
|
except Exception:
|
|
|
|
self.rejected_updated_account_number += 1
|
|
|
|
if config['test_enable']:
|
|
|
|
_logger.info(EXCEPTION_TEXT)
|
|
|
|
else: # pragma: no cover
|
|
|
|
_logger.exception(
|
|
|
|
"ERROR: " + _("Exception writing account %s."),
|
|
|
|
"'%s - %s'" % (account.code, account.name),
|
|
|
|
)
|
|
|
|
if not self.continue_on_errors:
|
|
|
|
break
|
2013-10-01 18:28:19 +02:00
|
|
|
|
2015-03-28 14:56:47 +01:00
|
|
|
@api.multi
|
2016-05-25 14:05:38 +02:00
|
|
|
def _update_taxes_pending_for_accounts(self):
|
2015-03-28 14:56:47 +01:00
|
|
|
"""Updates the taxes (created or updated on previous steps) to set
|
2014-03-21 02:01:05 +01:00
|
|
|
the references to the accounts (the taxes where created/updated first,
|
2015-03-28 14:56:47 +01:00
|
|
|
when the referenced accounts are still not available).
|
2014-03-21 02:01:05 +01:00
|
|
|
"""
|
2016-05-25 14:05:38 +02:00
|
|
|
for wiz_tax in self.tax_ids:
|
|
|
|
if wiz_tax.type == "deleted" or not wiz_tax.update_tax_id:
|
|
|
|
continue
|
2018-09-18 14:41:19 +02:00
|
|
|
template = wiz_tax.tax_id
|
|
|
|
tax = wiz_tax.update_tax_id
|
|
|
|
done = False
|
|
|
|
for key, value in self.diff_fields(template, tax).iteritems():
|
|
|
|
if key in {'account_id', 'refund_account_id'}:
|
|
|
|
tax[key] = value
|
|
|
|
done = True
|
|
|
|
if done:
|
|
|
|
_logger.info(_("Post-updated tax %s."), "'%s'" % tax.name)
|
2015-03-28 14:56:47 +01:00
|
|
|
|
2016-05-25 14:05:38 +02:00
|
|
|
def _prepare_fp_vals(self, fp_template):
|
2015-03-28 14:56:47 +01:00
|
|
|
# Tax mappings
|
|
|
|
tax_mapping = []
|
|
|
|
for fp_tax in fp_template.tax_ids:
|
|
|
|
# Create the fp tax mapping
|
|
|
|
tax_mapping.append({
|
2018-09-18 14:59:54 +02:00
|
|
|
'tax_src_id': self.find_tax_by_templates(fp_tax.tax_src_id),
|
|
|
|
'tax_dest_id': self.find_tax_by_templates(fp_tax.tax_dest_id),
|
2015-03-28 14:56:47 +01:00
|
|
|
})
|
|
|
|
# Account mappings
|
|
|
|
account_mapping = []
|
|
|
|
for fp_account in fp_template.account_ids:
|
|
|
|
# Create the fp account mapping
|
|
|
|
account_mapping.append({
|
|
|
|
'account_src_id': (
|
2018-09-18 14:59:54 +02:00
|
|
|
self.find_account_by_templates(fp_account.account_src_id)
|
|
|
|
),
|
2015-03-28 14:56:47 +01:00
|
|
|
'account_dest_id': (
|
2018-09-18 14:59:54 +02:00
|
|
|
self.find_account_by_templates(fp_account.account_dest_id)
|
|
|
|
),
|
2015-03-28 14:56:47 +01:00
|
|
|
})
|
|
|
|
return {
|
|
|
|
'company_id': self.company_id.id,
|
|
|
|
'name': fp_template.name,
|
|
|
|
'tax_ids': [(0, 0, x) for x in tax_mapping],
|
|
|
|
'account_ids': [(0, 0, x) for x in account_mapping],
|
|
|
|
}
|
2013-10-01 18:28:19 +02:00
|
|
|
|
2015-03-28 14:56:47 +01:00
|
|
|
@api.multi
|
2016-05-25 14:05:38 +02:00
|
|
|
def _update_fiscal_positions(self):
|
2015-03-28 14:56:47 +01:00
|
|
|
"""Process fiscal position templates to create/update."""
|
|
|
|
for wiz_fp in self.fiscal_position_ids:
|
2016-05-25 14:05:38 +02:00
|
|
|
fp, template = (wiz_fp.update_fiscal_position_id,
|
|
|
|
wiz_fp.fiscal_position_id)
|
2013-10-01 18:28:19 +02:00
|
|
|
if wiz_fp.type == 'new':
|
|
|
|
# Create a new fiscal position
|
2018-09-18 14:41:19 +02:00
|
|
|
self.chart_template_id.create_record_with_xmlid(
|
|
|
|
self.company_id, template, 'account.fiscal.position',
|
|
|
|
self._prepare_fp_vals(template),
|
|
|
|
)
|
2015-03-28 14:56:47 +01:00
|
|
|
else:
|
2016-05-25 14:05:38 +02:00
|
|
|
# Update the given fiscal position
|
|
|
|
for key, value in self.diff_fields(template, fp).iteritems():
|
2017-08-14 19:36:35 +02:00
|
|
|
fp[key] = value
|
2018-09-18 14:41:19 +02:00
|
|
|
_logger.info(
|
2016-05-25 14:05:38 +02:00
|
|
|
_("Created or updated fiscal position %s."),
|
2018-09-18 14:41:19 +02:00
|
|
|
"'%s'" % template.name)
|
2015-03-28 14:56:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
class WizardUpdateChartsAccountsTax(models.TransientModel):
|
2013-10-01 18:28:19 +02:00
|
|
|
_name = 'wizard.update.charts.accounts.tax'
|
2015-03-28 14:56:47 +01:00
|
|
|
_description = ("Tax that needs to be updated (new or updated in the "
|
|
|
|
"template).")
|
|
|
|
|
|
|
|
tax_id = fields.Many2one(
|
|
|
|
comodel_name='account.tax.template', string='Tax template',
|
|
|
|
ondelete='set null')
|
|
|
|
update_chart_wizard_id = fields.Many2one(
|
|
|
|
comodel_name='wizard.update.charts.accounts',
|
|
|
|
string='Update chart wizard', required=True, ondelete='cascade')
|
|
|
|
type = fields.Selection(
|
|
|
|
selection=[('new', 'New template'),
|
|
|
|
('updated', 'Updated template'),
|
2016-05-25 14:05:38 +02:00
|
|
|
('deleted', 'Tax to deactivate')],
|
|
|
|
string='Type',
|
|
|
|
readonly=True)
|
|
|
|
type_tax_use = fields.Selection(
|
|
|
|
related="tax_id.type_tax_use",
|
|
|
|
readonly=True)
|
2015-03-28 14:56:47 +01:00
|
|
|
update_tax_id = fields.Many2one(
|
|
|
|
comodel_name='account.tax', string='Tax to update', required=False,
|
|
|
|
ondelete='set null')
|
2016-05-25 14:05:38 +02:00
|
|
|
notes = fields.Text('Notes', readonly=True)
|
2015-03-28 14:56:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
class WizardUpdateChartsAccountsAccount(models.TransientModel):
|
2013-10-01 18:28:19 +02:00
|
|
|
_name = 'wizard.update.charts.accounts.account'
|
2015-03-28 14:56:47 +01:00
|
|
|
_description = ("Account that needs to be updated (new or updated in the "
|
|
|
|
"template).")
|
|
|
|
|
|
|
|
account_id = fields.Many2one(
|
|
|
|
comodel_name='account.account.template', string='Account template',
|
|
|
|
required=True, ondelete='set null')
|
|
|
|
update_chart_wizard_id = fields.Many2one(
|
|
|
|
comodel_name='wizard.update.charts.accounts',
|
|
|
|
string='Update chart wizard', required=True, ondelete='cascade'
|
|
|
|
)
|
|
|
|
type = fields.Selection(
|
|
|
|
selection=[('new', 'New template'),
|
2016-05-25 14:05:38 +02:00
|
|
|
('updated', 'Updated template')],
|
|
|
|
string='Type',
|
|
|
|
readonly=True)
|
2015-03-28 14:56:47 +01:00
|
|
|
update_account_id = fields.Many2one(
|
|
|
|
comodel_name='account.account', string='Account to update',
|
|
|
|
required=False, ondelete='set null')
|
2016-05-25 14:05:38 +02:00
|
|
|
notes = fields.Text('Notes', readonly=True)
|
2015-03-28 14:56:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
class WizardUpdateChartsAccountsFiscalPosition(models.TransientModel):
|
2013-10-01 18:28:19 +02:00
|
|
|
_name = 'wizard.update.charts.accounts.fiscal.position'
|
2015-03-28 14:56:47 +01:00
|
|
|
_description = ("Fiscal position that needs to be updated (new or updated "
|
|
|
|
"in the template).")
|
|
|
|
|
|
|
|
fiscal_position_id = fields.Many2one(
|
|
|
|
comodel_name='account.fiscal.position.template',
|
|
|
|
string='Fiscal position template', required=True, ondelete='set null')
|
|
|
|
update_chart_wizard_id = fields.Many2one(
|
|
|
|
comodel_name='wizard.update.charts.accounts',
|
|
|
|
string='Update chart wizard', required=True, ondelete='cascade')
|
|
|
|
type = fields.Selection(
|
|
|
|
selection=[('new', 'New template'),
|
2016-05-25 14:05:38 +02:00
|
|
|
('updated', 'Updated template')],
|
2017-08-14 19:36:35 +02:00
|
|
|
string='Type', readonly=True, required=True,
|
|
|
|
)
|
2015-03-28 14:56:47 +01:00
|
|
|
update_fiscal_position_id = fields.Many2one(
|
|
|
|
comodel_name='account.fiscal.position', required=False,
|
|
|
|
string='Fiscal position to update', ondelete='set null')
|
2016-05-25 14:05:38 +02:00
|
|
|
notes = fields.Text('Notes', readonly=True)
|