2
0

Merge PR #1714 into 16.0

Signed-off-by pedrobaeza
This commit is contained in:
OCA-git-bot 2023-08-10 15:54:34 +00:00
commit c5bed360a8
2 changed files with 82 additions and 80 deletions

View File

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

View File

@ -1,20 +1,20 @@
# Copyright 2023 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging import logging
from odoo import fields from odoo import fields
from odoo.tests import common from odoo.tests import common, tagged
from odoo.tools import mute_logger from odoo.tools import mute_logger
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
class TestAccountChartUpdate(common.HttpCase): @tagged("-at_install", "post_install")
at_install = False class TestAccountChartUpdate(common.TransactionCase):
post_install = True @classmethod
def _create_xml_id(cls, record):
def _create_xml_id(self, record): return cls.env["ir.model.data"].create(
return self.env["ir.model.data"].create(
{ {
"module": "account_chart_update", "module": "account_chart_update",
"name": "{}-{}".format(record._table, record.id), "name": "{}-{}".format(record._table, record.id),
@ -23,8 +23,9 @@ class TestAccountChartUpdate(common.HttpCase):
} }
) )
def _create_account_tmpl(self, name, code, account_type, chart_template): @classmethod
record = self.env["account.account.template"].create( def _create_account_tmpl(cls, name, code, account_type, chart_template):
record = cls.env["account.account.template"].create(
{ {
"name": name, "name": name,
"code": code, "code": code,
@ -32,16 +33,17 @@ class TestAccountChartUpdate(common.HttpCase):
"chart_template_id": chart_template and chart_template.id, "chart_template_id": chart_template and chart_template.id,
} }
) )
self._create_xml_id(record) cls._create_xml_id(record)
return record return record
def _create_tax_tmpl(self, name, chart_template): @classmethod
record = self.env["account.tax.template"].create( def _create_tax_tmpl(cls, name, chart_template):
record = cls.env["account.tax.template"].create(
{ {
"name": name, "name": name,
"amount": 0, "amount": 0,
"chart_template_id": chart_template.id, "chart_template_id": chart_template.id,
"tax_group_id": self.env.ref("account.tax_group_taxes").id, "tax_group_id": cls.env.ref("account.tax_group_taxes").id,
"refund_repartition_line_ids": [ "refund_repartition_line_ids": [
(0, 0, {"repartition_type": "base", "factor_percent": 100.0}), (0, 0, {"repartition_type": "base", "factor_percent": 100.0}),
(0, 0, {"repartition_type": "tax", "factor_percent": 100.0}), (0, 0, {"repartition_type": "tax", "factor_percent": 100.0}),
@ -54,7 +56,7 @@ class TestAccountChartUpdate(common.HttpCase):
], ],
} }
) )
self._create_xml_id(record) cls._create_xml_id(record)
return record return record
def _create_tax_template_with_account(self, name, chart_template, account): def _create_tax_template_with_account(self, name, chart_template, account):
@ -93,11 +95,12 @@ class TestAccountChartUpdate(common.HttpCase):
self._create_xml_id(record) self._create_xml_id(record)
return record return record
def _create_fp_tmpl(self, name, chart_template): @classmethod
record = self.env["account.fiscal.position.template"].create( def _create_fp_tmpl(cls, name, chart_template):
record = cls.env["account.fiscal.position.template"].create(
{"name": name, "chart_template_id": chart_template.id} {"name": name, "chart_template_id": chart_template.id}
) )
self._create_xml_id(record) cls._create_xml_id(record)
return record return record
def _get_model_data(self, record): def _get_model_data(self, record):
@ -105,97 +108,95 @@ class TestAccountChartUpdate(common.HttpCase):
[("model", "=", record._name), ("res_id", "=", record.id)] [("model", "=", record._name), ("res_id", "=", record.id)]
) )
def setUp(self): @classmethod
super(TestAccountChartUpdate, self).setUp() def setUpClass(cls):
self.env.user.lang = "en_US" super().setUpClass()
self.env.user.write( cls.env = cls.env(
{ context=dict(
"groups_id": [ cls.env.context,
(6, 0, self.env.user.groups_id.ids), mail_create_nolog=True,
(4, self.env.ref("account.group_account_user").id), mail_create_nosubscribe=True,
(4, self.env.ref("account.group_account_invoice").id), mail_notrack=True,
(4, self.env.ref("base.group_multi_company").id), no_reset_password=True,
] tracking_disable=True,
} )
) )
self.account_template = self._create_account_tmpl( cls.account_template = cls._create_account_tmpl(
"Test", "100000", "income", False "Test", "100000", "income", False
) )
self.chart_template = self.env.ref( cls.chart_template = cls.env["account.chart.template"].create(
"l10n_generic_coa.configurable_chart_template" {
"name": "Test account_chart_update chart",
"currency_id": cls.env.ref("base.EUR").id,
"code_digits": 6,
"cash_account_code_prefix": "570",
"bank_account_code_prefix": "572",
"transfer_account_code_prefix": "100000",
"property_account_receivable_id": cls.account_template.id,
"property_account_payable_id": cls.account_template.id,
"property_account_expense_categ_id": cls.account_template.id,
"property_account_income_categ_id": cls.account_template.id,
}
) )
# Avoid re-creating taxes. cls.account_template.chart_template_id = cls.chart_template.id
# If false, the taxes that are created will be overwrited. cls.account_template_pl = cls._create_account_tmpl(
self.account_template.chart_template_id = self.chart_template.id
self.account_template_pl = self._create_account_tmpl(
"Undistributed Profits/Losses", "Undistributed Profits/Losses",
"999999", "999999",
"equity", "equity",
self.chart_template, cls.chart_template,
) )
self.tax_template = self._create_tax_tmpl("Test tax", self.chart_template) cls.tax_template = cls._create_tax_tmpl("Test tax", cls.chart_template)
self.fp_template = self._create_fp_tmpl("Test fp", self.chart_template) cls.fp_template = cls._create_fp_tmpl("Test fp", cls.chart_template)
self.fp_template_tax = self.env["account.fiscal.position.tax.template"].create( cls.fp_template_tax = cls.env["account.fiscal.position.tax.template"].create(
{"tax_src_id": self.tax_template.id, "position_id": self.fp_template.id} {"tax_src_id": cls.tax_template.id, "position_id": cls.fp_template.id}
) )
self._create_xml_id(self.fp_template_tax) cls._create_xml_id(cls.fp_template_tax)
self.fp_template_account = self.env[ cls.fp_template_account = cls.env[
"account.fiscal.position.account.template" "account.fiscal.position.account.template"
].create( ].create(
{ {
"account_src_id": self.account_template.id, "account_src_id": cls.account_template.id,
"account_dest_id": self.account_template.id, "account_dest_id": cls.account_template.id,
"position_id": self.fp_template.id, "position_id": cls.fp_template.id,
} }
) )
self._create_xml_id(self.fp_template_account) cls._create_xml_id(cls.fp_template_account)
self.tax_group = self.env["account.tax.group"].create( cls.tax_group = cls.env["account.tax.group"].create({"name": "Test tax group"})
{"name": "Test tax group"} cls.account_tag_1 = cls.env["account.account.tag"].create(
)
self.account_tag_1 = self.env["account.account.tag"].create(
{"name": "Test account tag 1"} {"name": "Test account tag 1"}
) )
self.account_tag_2 = self.env["account.account.tag"].create( cls.account_tag_2 = cls.env["account.account.tag"].create(
{"name": "Test account tag 2"} {"name": "Test account tag 2"}
) )
self.company = self.env["res.company"].create( cls.company = cls.env["res.company"].create(
{ {
"name": "Test account_chart_update company", "name": "Test account_chart_update company",
"currency_id": self.chart_template.currency_id.id, "currency_id": cls.chart_template.currency_id.id,
"country_id": self.env.ref("base.es").id, "country_id": cls.env.ref("base.es").id,
} }
) )
self.env.user.write( chart_by_company_user = cls.chart_template.with_company(cls.company)
{
"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() chart_by_company_user.try_loading()
self.tax = self.env["account.tax"].search( cls.tax = cls.env["account.tax"].search(
[ [
("name", "=", self.tax_template.name), ("name", "=", cls.tax_template.name),
("company_id", "=", self.company.id), ("company_id", "=", cls.company.id),
] ]
) )
self.account = self.env["account.account"].search( cls.account = cls.env["account.account"].search(
[ [
("code", "=", self.account_template.code), ("code", "=", cls.account_template.code),
("company_id", "=", self.company.id), ("company_id", "=", cls.company.id),
] ]
) )
self.fp = self.env["account.fiscal.position"].search( cls.fp = cls.env["account.fiscal.position"].search(
[("name", "=", self.fp_template.name), ("company_id", "=", self.company.id)] [("name", "=", cls.fp_template.name), ("company_id", "=", cls.company.id)]
) )
# Prepare wizard values # Prepare wizard values
self.wizard_obj = self.env["wizard.update.charts.accounts"] cls.wizard_obj = cls.env["wizard.update.charts.accounts"]
self.wizard_vals = { cls.wizard_vals = {
"company_id": self.company.id, "company_id": cls.company.id,
"chart_template_id": self.chart_template.id, "chart_template_id": cls.chart_template.id,
"code_digits": 6, "code_digits": 6,
"lang": "en_US", "lang": "en_US",
} }
@ -515,9 +516,10 @@ class TestAccountChartUpdate(common.HttpCase):
self.assertEqual(1, wizard.updated_account_groups) self.assertEqual(1, wizard.updated_account_groups)
self.assertEqual(1, wizard.new_account_groups) self.assertEqual(1, wizard.new_account_groups)
self.assertEqual("TESTZ", group_1.code_prefix_end) self.assertEqual("TESTZ", group_1.code_prefix_end)
self.assertTrue(list(group_1.get_xml_id().values())[0]) self.assertTrue(list(group_1.get_external_id().values())[0])
def test_matching(self): # Put it to be executed in first place for avoiding DB cursor glitches
def test_00_matching(self):
# Test XML-ID matching # Test XML-ID matching
self.tax_template.name = "Test 1 tax name changed" self.tax_template.name = "Test 1 tax name changed"
self.tax_template.description = "Test tax 1 description changed" self.tax_template.description = "Test tax 1 description changed"