2
0

Migration and some fixes:

* Ignore changes in mail thread fields
   * account.tax.template._generate_tax return dict of objects
     and wizard fails
   * Load generic coa localization module to improve the test
This commit is contained in:
Fernando La Chica 2022-02-23 11:20:30 +01:00 committed by Luis J. Salvatierra
parent 236a764c99
commit 7fa493cf91
6 changed files with 66 additions and 61 deletions

View File

@ -10,7 +10,7 @@
"version": "15.0.1.0.0",
"author": "Tecnativa, BCIM, Okia, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-financial-tools",
"depends": ["account"],
"depends": ["account", "l10n_generic_coa"],
"category": "Accounting",
"license": "AGPL-3",
"data": [

View File

@ -722,13 +722,13 @@ msgstr "Aktualisierte Konten"
#: code:addons/account_chart_update/wizard/wizard_chart_update.py:0
#, fuzzy, python-format
msgid "Updated fiscal position %s."
msgstr "Aktualisierte Steuerzuordnungen"
msgstr "Aktualisierte Steuerzuordnungen %s."
#. module: account_chart_update
#: code:addons/account_chart_update/wizard/wizard_chart_update.py:0
#, fuzzy, python-format
msgid "Updated fiscal position %s. (Recreated XML-ID)"
msgstr "Aktualisierte Steuerzuordnungen"
msgstr "Aktualisierte Steuerzuordnungen %s. (Neu erstellt XML-ID)"
#. module: account_chart_update
#: model:ir.model.fields,field_description:account_chart_update.field_wizard_update_charts_accounts__updated_fps

View File

@ -724,13 +724,13 @@ msgstr "Cuentas actualizadas"
#: code:addons/account_chart_update/wizard/wizard_chart_update.py:0
#, fuzzy, python-format
msgid "Updated fiscal position %s."
msgstr "Posiciones fiscales actualizadas"
msgstr "%s Posiciones fiscales actualizadas"
#. module: account_chart_update
#: code:addons/account_chart_update/wizard/wizard_chart_update.py:0
#, fuzzy, python-format
msgid "Updated fiscal position %s. (Recreated XML-ID)"
msgstr "Posiciones fiscales actualizadas"
msgstr "%s Posiciones fiscales actualizadas (XML-ID Creado de nuevo)"
#. module: account_chart_update
#: model:ir.model.fields,field_description:account_chart_update.field_wizard_update_charts_accounts__updated_fps

View File

@ -1,9 +1,13 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging
from odoo import fields
from odoo.tests import common
from odoo.tools import mute_logger
_logger = logging.getLogger(__name__)
class TestAccountChartUpdate(common.HttpCase):
at_install = False
@ -67,8 +71,17 @@ class TestAccountChartUpdate(common.HttpCase):
def setUp(self):
super(TestAccountChartUpdate, self).setUp()
# Make sure user is in English
self.env.user.lang = "en_US"
self.env.user.write(
{
"groups_id": [
(6, 0, self.env.user.groups_id.ids),
(4, self.env.ref("account.group_account_user").id),
(4, self.env.ref("account.group_account_invoice").id),
(4, self.env.ref("base.group_multi_company").id),
]
}
)
self.account_type = self.env["account.account.type"].create(
{
"name": "Test account_chart_update account type",
@ -78,16 +91,12 @@ class TestAccountChartUpdate(common.HttpCase):
self.account_template = self._create_account_tmpl(
"Test", "100000", self.account_type, False
)
self.chart_template = self.env["account.chart.template"].create(
{
"name": "Test account_chart_update chart",
"currency_id": self.env.ref("base.EUR").id,
"code_digits": 6,
"cash_account_code_prefix": "570",
"bank_account_code_prefix": "572",
"transfer_account_code_prefix": "100000",
}
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",
@ -124,12 +133,20 @@ class TestAccountChartUpdate(common.HttpCase):
{
"name": "Test account_chart_update company",
"currency_id": self.chart_template.currency_id.id,
"country_id": self.env.ref("base.es").id,
}
)
company_user = self.env.user.copy({"company_id": self.company.id})
chart_by_company_user = self.chart_template.with_user(company_user)
self.env.user.write(
{
"company_ids": [
(6, 0, self.env.user.company_ids.ids),
(4, self.company.id),
],
"company_id": self.company.id,
}
)
chart_by_company_user = self.chart_template.with_user(self.env.user)
chart_by_company_user.try_loading()
self.tax = self.env["account.tax"].search(
[
("name", "=", self.tax_template.name),
@ -261,7 +278,7 @@ class TestAccountChartUpdate(common.HttpCase):
self.account_template.tag_ids = [
(6, 0, [self.account_tag_1.id, self.account_tag_2.id])
]
self.fp_template.note = "Test note"
self.fp_template.note = "<p>Test note</p>"
self.fp_template.account_ids.account_dest_id = new_account_tmpl.id
self.fp_template.tax_ids.tax_dest_id = self.tax_template.id
wizard = self.wizard_obj.create(self.wizard_vals)
@ -318,7 +335,7 @@ class TestAccountChartUpdate(common.HttpCase):
self.assertFalse(wizard.fiscal_position_ids)
self.tax_template.description = "Test description"
self.account_template.name = "Other name"
self.fp_template.note = "Test note"
self.fp_template.note = "<p>Test note</p>"
wizard.unlink()
# Remove objects
new_tax_tmpl.unlink()
@ -372,7 +389,7 @@ class TestAccountChartUpdate(common.HttpCase):
self.tax_template.description = "Other description"
wizard = self.wizard_obj.create(self.wizard_vals)
wizard.action_find_records()
with self.assertRaises(Exception):
with self.assertRaises(Exception): # noqa: B017
wizard.action_update_records()
# Errors on account update - continuing after that
wizard.continue_on_errors = True
@ -391,7 +408,7 @@ class TestAccountChartUpdate(common.HttpCase):
wizard.action_find_records()
self.assertEqual(wizard.account_ids.type, "new")
new_account_tmpl_2.code = "333333" # Trick the code for forcing error
with self.assertRaises(Exception):
with self.assertRaises(Exception): # noqa: B017
wizard.action_update_records()
wizard.continue_on_errors = True
wizard.action_update_records()
@ -431,7 +448,7 @@ class TestAccountChartUpdate(common.HttpCase):
self._get_model_data(self.fp).unlink()
self.tax_template.description = "Test 2 tax description changed"
self.account_template.name = "Test 2 account name changed"
self.fp_template.note = "Test 2 fp note changed"
self.fp_template.note = "<p>Test 2 fp note changed</p>"
wizard = self.wizard_obj.create(self.wizard_vals)
wizard.action_find_records()
self.assertEqual(wizard.tax_ids.tax_id, self.tax_template)
@ -465,7 +482,7 @@ class TestAccountChartUpdate(common.HttpCase):
# Test 1 recreate XML-ID
self.tax_template.description = "Test 4 tax description changed"
self.account_template.name = "Test 4 account name changed"
self.fp_template.note = "Test 4 fp note changed"
self.fp_template.note = "<p>Test 4 fp note changed</p>"
self.wizard_vals.update(recreate_xml_ids=True)
wizard = self.wizard_obj.create(self.wizard_vals)
wizard.action_find_records()

View File

@ -89,7 +89,6 @@ class WizardUpdateChartsAccounts(models.TransientModel):
"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 "
"there are minor errors.",
@ -110,21 +109,15 @@ class WizardUpdateChartsAccounts(models.TransientModel):
inverse_name="update_chart_wizard_id",
string="Fiscal positions",
)
new_taxes = fields.Integer(string="New taxes", compute="_compute_new_taxes_count")
new_accounts = fields.Integer(
string="New accounts", compute="_compute_new_accounts_count"
)
new_taxes = fields.Integer(compute="_compute_new_taxes_count")
new_accounts = fields.Integer(compute="_compute_new_accounts_count")
rejected_new_account_number = fields.Integer()
new_fps = fields.Integer(
string="New fiscal positions", compute="_compute_new_fps_count"
)
updated_taxes = fields.Integer(
string="Updated taxes", compute="_compute_updated_taxes_count"
)
updated_taxes = fields.Integer(compute="_compute_updated_taxes_count")
rejected_updated_account_number = fields.Integer()
updated_accounts = fields.Integer(
string="Updated accounts", compute="_compute_updated_accounts_count"
)
updated_accounts = fields.Integer(compute="_compute_updated_accounts_count")
updated_fps = fields.Integer(
string="Updated fiscal positions", compute="_compute_updated_fps_count"
)
@ -532,7 +525,7 @@ class WizardUpdateChartsAccounts(models.TransientModel):
try:
real |= self.env.ref(self._get_real_xml_name(template))
except BaseException:
pass
_logger.info("Is not real xml Name")
if not real:
continue
@ -568,7 +561,7 @@ class WizardUpdateChartsAccounts(models.TransientModel):
try:
real |= self.env.ref(self._get_real_xml_name(template))
except BaseException:
pass
_logger.info("Is not real xml Name")
if not real:
continue
@ -667,7 +660,8 @@ class WizardUpdateChartsAccounts(models.TransientModel):
"""
specials_mapping = {
"account.tax.template": {"chart_template_id", "children_tax_ids"},
"account.account.template": {"chart_template_id", "root_id", "nocreate"},
"account.account.template": set(self.env["mail.thread"]._fields)
| {"chart_template_id", "root_id", "nocreate"},
"account.fiscal.position.template": {"chart_template_id"},
}
specials = {
@ -944,9 +938,12 @@ class WizardUpdateChartsAccounts(models.TransientModel):
# First create taxes in batch
taxes_to_create = self.tax_ids.filtered(lambda x: x.type == "new")
todo_dict = taxes_to_create.mapped("tax_id")._generate_tax(self.company_id)
template_to_tax_dict = {}
for key in todo_dict["tax_template_to_tax"].keys():
template_to_tax_dict[key.id] = todo_dict["tax_template_to_tax"][key].id
for wiz_tax in taxes_to_create:
new_tax = self.env["account.tax"].browse(
todo_dict["tax_template_to_tax"][wiz_tax.tax_id.id]
template_to_tax_dict[wiz_tax.tax_id.id]
)
_logger.info(
_("Created tax %s."), "'{}' (ID:{})".format(new_tax.name, new_tax.id)
@ -1060,14 +1057,14 @@ class WizardUpdateChartsAccounts(models.TransientModel):
]:
if v[fld]:
acc_id = self.find_account_by_templates(
self.env["account.account.template"].browse(v[fld])
self.env["account.account.template"].browse(v[fld].id)
)
if acc_id:
vals[fld] = acc_id
else:
raise exceptions.UserError(
_("No real account found for template account with ID %s")
% v[fld]
% v[fld].id
)
if vals:
tax = self.env["account.tax"].browse(k)
@ -1078,7 +1075,7 @@ class WizardUpdateChartsAccounts(models.TransientModel):
if v["account_id"]:
rep_line = self.env["account.tax.repartition.line"].browse(k)
acc_id = self.find_account_by_templates(
self.env["account.account.template"].browse(v["account_id"])
self.env["account.account.template"].browse(v["account_id"].id)
)
if acc_id:
rep_line.write({"account_id": acc_id})
@ -1086,7 +1083,7 @@ class WizardUpdateChartsAccounts(models.TransientModel):
else:
raise exceptions.UserError(
_("No real account found for template account with ID %s")
% v["account_id"]
% v["account_id"].id
)
for wiz_tax in self.tax_ids.filtered(lambda r: r.type == "updated"):
@ -1188,7 +1185,6 @@ class WizardUpdateChartsAccountsTax(models.TransientModel):
("updated", "Updated template"),
("deleted", "Tax to deactivate"),
],
string="Type",
readonly=False,
)
type_tax_use = fields.Selection(related="tax_id.type_tax_use", readonly=True)
@ -1198,11 +1194,8 @@ class WizardUpdateChartsAccountsTax(models.TransientModel):
required=False,
ondelete="set null",
)
notes = fields.Text("Notes", readonly=True)
recreate_xml_ids = fields.Boolean(
string="Recreate missing XML-IDs",
related="update_chart_wizard_id.recreate_xml_ids",
)
notes = fields.Text(readonly=True)
recreate_xml_ids = fields.Boolean(related="update_chart_wizard_id.recreate_xml_ids")
class WizardUpdateChartsAccountsAccount(models.TransientModel):
@ -1224,7 +1217,6 @@ class WizardUpdateChartsAccountsAccount(models.TransientModel):
)
type = fields.Selection(
selection=[("new", "New template"), ("updated", "Updated template")],
string="Type",
readonly=False,
)
update_account_id = fields.Many2one(
@ -1233,11 +1225,8 @@ class WizardUpdateChartsAccountsAccount(models.TransientModel):
required=False,
ondelete="set null",
)
notes = fields.Text("Notes", readonly=True)
recreate_xml_ids = fields.Boolean(
string="Recreate missing XML-IDs",
related="update_chart_wizard_id.recreate_xml_ids",
)
notes = fields.Text(readonly=True)
recreate_xml_ids = fields.Boolean(related="update_chart_wizard_id.recreate_xml_ids")
class WizardUpdateChartsAccountsFiscalPosition(models.TransientModel):
@ -1259,7 +1248,6 @@ class WizardUpdateChartsAccountsFiscalPosition(models.TransientModel):
)
type = fields.Selection(
selection=[("new", "New template"), ("updated", "Updated template")],
string="Type",
readonly=False,
)
update_fiscal_position_id = fields.Many2one(
@ -1268,7 +1256,7 @@ class WizardUpdateChartsAccountsFiscalPosition(models.TransientModel):
string="Fiscal position to update",
ondelete="set null",
)
notes = fields.Text("Notes", readonly=True)
notes = fields.Text(readonly=True)
recreate_xml_ids = fields.Boolean(
string="Recreate missing XML-IDs",
related="update_chart_wizard_id.recreate_xml_ids",

View File

@ -214,7 +214,7 @@
attrs="{'invisible': [('update_tax', '=', False)]}"
>
<field name="tax_ids" nolabel="1">
<tree string="Taxes" colors="red:type=='updated'">
<tree decoration-danger="type=='updated'">
<field name="tax_id" />
<field name="update_tax_id" />
<field name="type_tax_use" />
@ -249,7 +249,7 @@
attrs="{'invisible': [('update_account', '=', False)]}"
>
<field name="account_ids" nolabel="1">
<tree string="Accounts" colors="red:type=='updated'">
<tree decoration-danger="type=='updated'">
<field name="account_id" />
<field name="update_account_id" />
<field name="notes" />
@ -283,8 +283,8 @@
>
<field name="fiscal_position_ids" nolabel="1">
<tree
string="Fiscal positions"
colors="red:type=='updated'"
name="fiscal_positions"
decoration-danger="type=='updated'"
>
<field name="fiscal_position_id" />
<field name="update_fiscal_position_id" />