Skip to content

Commit 1fbf080

Browse files
committed
[FIX] intrastat_product: Post-install test + fallback to load CoA
Since odoo/odoo@d0342c8, the default existing company is not getting a CoA automatically, provoking than the current tests fail with error: odoo.exceptions.UserError: No journal could be found in company My Company (San Francisco) for any of those types: sale provoked by the lack of a CoA installed. Thus, we put tests post-install for being sure localization modules are installed, the same as AccountTestInvoicingCommon does, but we don't inherit from it, as it creates an overhead creating 2 new companies and loading their CoA, and some more stuff, while we don't need all of that. Besides, if you don't have `l10n_generic_coa` installed, you can't use another CoA (like `l10n_es`) easily, so we put little code to select the first available CoA.
1 parent 96774bb commit 1fbf080

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

intrastat_product/tests/common.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
import xlrd
44
from werkzeug.urls import url_encode
55

6+
from odoo.tests import tagged
7+
68
from odoo.addons.intrastat_base.tests.common import IntrastatCommon
79

810

11+
@tagged("post_install", "-at_install")
912
class IntrastatProductCommon(IntrastatCommon):
1013
@classmethod
1114
def _init_products(cls):
@@ -72,6 +75,15 @@ def _init_transaction(cls):
7275
@classmethod
7376
def setUpClass(cls):
7477
super().setUpClass()
78+
if not cls.env.company.chart_template_id:
79+
# Load a CoA if there's none in current company
80+
coa = cls.env.ref("l10n_generic_coa.configurable_chart_template", False)
81+
if not coa:
82+
# Load the first available CoA
83+
coa = cls.env["account.chart.template"].search(
84+
[("visible", "=", True)], limit=1
85+
)
86+
coa.try_loading(company=cls.env.company, install_demo=False)
7587
cls.region_obj = cls.env["intrastat.region"]
7688
cls.transaction_obj = cls.env["intrastat.transaction"]
7789
cls.transport_mode_obj = cls.env["intrastat.transport_mode"]

0 commit comments

Comments
 (0)