Skip to content

Commit cbe1a95

Browse files
committed
[FIX] fieldservice_account: 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 868c114 commit cbe1a95

File tree

1 file changed

+36
-24
lines changed

1 file changed

+36
-24
lines changed

fieldservice_account/tests/test_fsm_account.py

+36-24
Original file line numberDiff line numberDiff line change
@@ -3,55 +3,67 @@
33

44
from datetime import datetime, timedelta
55

6+
from odoo.tests import tagged
67
from odoo.tests.common import TransactionCase
78

89

10+
@tagged("-at_install", "post_install")
911
class FSMAccountCase(TransactionCase):
10-
def setUp(self):
11-
super(FSMAccountCase, self).setUp()
12-
self.Wizard = self.env["fsm.wizard"]
13-
self.WorkOrder = self.env["fsm.order"]
14-
self.AccountInvoice = self.env["account.move"]
15-
self.AccountInvoiceLine = self.env["account.move.line"]
12+
@classmethod
13+
def setUpClass(cls):
14+
super().setUpClass()
15+
if not cls.env.company.chart_template_id:
16+
# Load a CoA if there's none in current company
17+
coa = cls.env.ref("l10n_generic_coa.configurable_chart_template", False)
18+
if not coa:
19+
# Load the first available CoA
20+
coa = cls.env["account.chart.template"].search(
21+
[("visible", "=", True)], limit=1
22+
)
23+
coa.try_loading(company=cls.env.company, install_demo=False)
24+
cls.Wizard = cls.env["fsm.wizard"]
25+
cls.WorkOrder = cls.env["fsm.order"]
26+
cls.AccountInvoice = cls.env["account.move"]
27+
cls.AccountInvoiceLine = cls.env["account.move.line"]
1628
# create a Res Partner
17-
self.test_partner = self.env["res.partner"].create(
29+
cls.test_partner = cls.env["res.partner"].create(
1830
{"name": "Test Partner", "phone": "123", "email": "tp@email.com"}
1931
)
2032
# create a Res Partner to be converted to FSM Location/Person
21-
self.test_loc_partner = self.env["res.partner"].create(
33+
cls.test_loc_partner = cls.env["res.partner"].create(
2234
{"name": "Test Loc Partner", "phone": "ABC", "email": "tlp@email.com"}
2335
)
24-
self.test_loc_partner2 = self.env["res.partner"].create(
36+
cls.test_loc_partner2 = cls.env["res.partner"].create(
2537
{"name": "Test Loc Partner 2", "phone": "123", "email": "tlp@example.com"}
2638
)
2739
# create expected FSM Location to compare to converted FSM Location
28-
self.test_location = self.env["fsm.location"].create(
40+
cls.test_location = cls.env["fsm.location"].create(
2941
{
3042
"name": "Test Location",
3143
"phone": "123",
3244
"email": "tp@email.com",
33-
"partner_id": self.test_loc_partner.id,
34-
"owner_id": self.test_loc_partner.id,
45+
"partner_id": cls.test_loc_partner.id,
46+
"owner_id": cls.test_loc_partner.id,
3547
}
3648
)
37-
self.test_order = self.env["fsm.order"].create(
49+
cls.test_order = cls.env["fsm.order"].create(
3850
{
39-
"location_id": self.test_location.id,
51+
"location_id": cls.test_location.id,
4052
"date_start": datetime.today(),
4153
"date_end": datetime.today() + timedelta(hours=2),
4254
"request_early": datetime.today(),
4355
}
4456
)
45-
self.test_order2 = self.env["fsm.order"].create(
57+
cls.test_order2 = cls.env["fsm.order"].create(
4658
{
47-
"location_id": self.test_location.id,
59+
"location_id": cls.test_location.id,
4860
"date_start": datetime.today(),
4961
"date_end": datetime.today() + timedelta(hours=2),
5062
"request_early": datetime.today(),
5163
}
5264
)
53-
company = self.env.user.company_id
54-
self.default_account_revenue = self.env["account.account"].search(
65+
company = cls.env.user.company_id
66+
cls.default_account_revenue = cls.env["account.account"].search(
5567
[
5668
("company_id", "=", company.id),
5769
("account_type", "=", "income"),
@@ -64,9 +76,9 @@ def setUp(self):
6476
limit=1,
6577
)
6678

67-
self.test_invoice = self.env["account.move"].create(
79+
cls.test_invoice = cls.env["account.move"].create(
6880
{
69-
"partner_id": self.test_partner.id,
81+
"partner_id": cls.test_partner.id,
7082
"move_type": "out_invoice",
7183
"invoice_date": datetime.today().date(),
7284
"invoice_line_ids": [
@@ -86,23 +98,23 @@ def setUp(self):
8698
0,
8799
{
88100
"name": "line_debit",
89-
"account_id": self.default_account_revenue.id,
101+
"account_id": cls.default_account_revenue.id,
90102
},
91103
),
92104
(
93105
0,
94106
0,
95107
{
96108
"name": "line_credit",
97-
"account_id": self.default_account_revenue.id,
109+
"account_id": cls.default_account_revenue.id,
98110
},
99111
),
100112
],
101113
}
102114
)
103-
self.test_invoice2 = self.env["account.move"].create(
115+
cls.test_invoice2 = cls.env["account.move"].create(
104116
{
105-
"partner_id": self.test_partner.id,
117+
"partner_id": cls.test_partner.id,
106118
"move_type": "out_invoice",
107119
"invoice_date": datetime.today().date(),
108120
"invoice_line_ids": [

0 commit comments

Comments
 (0)