Skip to content

Commit c471bd0

Browse files
committed
[FIX] fieldservice_sale: 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 the error: odoo.exceptions.UserError: No journal could be found in company My Company (San Francisco) for any of those types: sale 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 cbe1a95 commit c471bd0

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

fieldservice_sale/tests/test_fsm_sale_order.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,25 @@
33

44
from odoo import fields
55
from odoo.exceptions import ValidationError
6+
from odoo.tests import tagged
67

78
from .test_fsm_sale_common import TestFSMSale
89

910

11+
@tagged("-at_install", "post_install")
1012
class TestFSMSaleOrder(TestFSMSale):
1113
@classmethod
1214
def setUpClass(cls):
13-
super(TestFSMSaleOrder, cls).setUpClass()
15+
super().setUpClass()
16+
if not cls.env.company.chart_template_id:
17+
# Load a CoA if there's none in current company
18+
coa = cls.env.ref("l10n_generic_coa.configurable_chart_template", False)
19+
if not coa:
20+
# Load the first available CoA
21+
coa = cls.env["account.chart.template"].search(
22+
[("visible", "=", True)], limit=1
23+
)
24+
coa.try_loading(company=cls.env.company, install_demo=False)
1425
cls.test_location = cls.env.ref("fieldservice.test_location")
1526

1627
# Setup products that when sold will create some FSM orders
@@ -21,8 +32,8 @@ def setUpClass(cls):
2132
"company_id": False,
2233
}
2334
)
24-
cls.pricelist_usd = cls.env["product.pricelist"].search(
25-
[("currency_id.name", "=", "USD")], limit=1
35+
cls.pricelist_usd = cls.env["product.pricelist"].create(
36+
{"name": "Test pricelist", "currency_id": cls.env.company.currency_id.id}
2637
)
2738
# Create some sale orders that will use the above products
2839
SaleOrder = cls.env["sale.order"].with_context(tracking_disable=True)

0 commit comments

Comments
 (0)