Skip to content

Commit 81b4f09

Browse files
committed
[chore] Enabling and fixing tests in spp_starter that were marked as failing on CI
1 parent 4ad9837 commit 81b4f09

File tree

3 files changed

+96
-66
lines changed

3 files changed

+96
-66
lines changed

spp_starter/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"license": "LGPL-3",
88
"development_status": "Beta",
99
"maintainers": ["jeremi", "gonzalesedwin1123"],
10-
"depends": ["base"],
10+
"depends": ["base", "product"],
1111
"data": [
1212
"security/ir.model.access.csv",
1313
"wizards/spp_starter_views.xml",

spp_starter/tests/test_spp_starter.py

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from odoo.tests import TransactionCase, tagged
1+
from odoo.tests import TransactionCase, patch, tagged
22
from odoo.tools.safe_eval import safe_eval
33

44

@@ -10,9 +10,9 @@ def setUpClass(cls):
1010
cls.sgd = cls.env.ref("base.SGD").id
1111
cls.test_record = cls.env["spp.starter"].create(
1212
{
13-
"org_name": "Newlogic",
14-
"org_address": "160 Robinson Rd #14-04 SBF Centre Singapore 068914",
15-
"org_phone": "+65 3138 4664",
13+
"org_name": "The Company",
14+
"org_address": "The Address, 12345, Country",
15+
"org_phone": "+1234567890",
1616
"org_currency_id": cls.sgd,
1717
}
1818
)
@@ -97,8 +97,12 @@ def test_04_remove_fake_apps_menu(self):
9797

9898
def test_05_remove_default_products_if_needed(self):
9999
self.test_record.conducting_inkind_transfer = "yes"
100+
# Skip product-related tests if product module is not installed
100101
if "product.template" not in self.env:
101-
self.test_record._remove_default_products_if_needed()
102+
result = self.test_record._remove_default_products_if_needed()
103+
self.assertIsNone(result)
104+
return
105+
102106
fake_product_template = self.env["product.template"].create(
103107
{
104108
"name": "Fake Test Product",
@@ -122,30 +126,35 @@ def test_07_adjust_main_company_details(self):
122126
self.assertEqual(company.phone, self.test_record.org_phone)
123127
self.assertEqual(company.currency_id, self.test_record.org_currency_id)
124128

125-
# TODO: removed below test cases because they are having errors in the CI
126-
# but they are working fine in the local machine
127-
128-
# def test_08_install_modules(self):
129-
# def find_module(module_name):
130-
# return self.env.ref(f"base.module_{module_name}", raise_if_not_found=False)
131-
132-
# spp_theme = find_module("theme_openspp_muk")
133-
# self.assertIn(spp_theme, self.test_record._install_modules())
134-
# gp2_individual = find_module("g2p_registry_individual")
135-
# gp2_group = find_module("g2p_registry_group")
136-
# self.test_record.managing_target = "group"
137-
# self.assertIn(gp2_group, self.test_record._install_modules())
138-
# self.test_record.managing_target = "individual"
139-
# self.assertIn(gp2_individual, self.test_record._install_modules())
140-
141-
# @patch("odoo.addons.base.models.ir_module.Module.button_immediate_install")
142-
# def test_09_action_done(self, mock_button_immediate_install):
143-
# mock_button_immediate_install.return_value = None
144-
# action = self.test_record.action_done()
145-
# self.assertEqual(
146-
# action,
147-
# {
148-
# "type": "ir.actions.client",
149-
# "tag": "reload",
150-
# },
151-
# )
129+
def test_08_install_modules(self):
130+
def find_module(module_name):
131+
return self.env.ref(f"base.module_{module_name}", raise_if_not_found=False)
132+
133+
# Test SP-MIS modules
134+
self.test_record.registry_target = "spmis"
135+
modules = self.test_record._install_modules()
136+
self.assertTrue(modules, "Should return some modules for SP-MIS")
137+
138+
# Check for theme module which should always be available
139+
theme_module = find_module("theme_openspp_muk")
140+
self.assertIn(theme_module, modules, "Theme module should be included")
141+
142+
# Test Farmer Registry modules
143+
self.test_record.registry_target = "farmer"
144+
modules = self.test_record._install_modules()
145+
self.assertTrue(modules, "Should return some modules for Farmer Registry")
146+
147+
# Check for theme module which should always be available
148+
self.assertIn(theme_module, modules, "Theme module should be included")
149+
150+
@patch("odoo.addons.base.models.ir_module.Module.button_immediate_install")
151+
def test_09_action_done(self, mock_button_immediate_install):
152+
mock_button_immediate_install.return_value = None
153+
action = self.test_record.action_done()
154+
self.assertEqual(
155+
action,
156+
{
157+
"type": "ir.actions.client",
158+
"tag": "reload",
159+
},
160+
)

spp_starter/wizards/spp_starter.py

Lines changed: 54 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -203,45 +203,66 @@ def _adjust_main_company_details(self):
203203
}
204204
)
205205

206+
def _find_module(self, module_name):
207+
return self.env.ref(f"base.module_{module_name}", raise_if_not_found=False)
208+
209+
def _add_module_if_found(self, res, module_name):
210+
if module := self._find_module(module_name):
211+
res |= module
212+
return res
213+
214+
def _install_spmis_base_modules(self, res):
215+
for module_name in [
216+
"spp_base",
217+
"spp_programs",
218+
"spp_change_request",
219+
"spp_change_request_change_info",
220+
"spp_event_data",
221+
]:
222+
res = self._add_module_if_found(res, module_name)
223+
return res
224+
225+
def _install_spmis_demo_modules(self, res):
226+
if self.sp_mis_demo_management == "yes":
227+
for module_name in ["spp_base_demo", "spp_mis_demo"]:
228+
res = self._add_module_if_found(res, module_name)
229+
return res
230+
231+
def _install_spmis_feature_modules(self, res):
232+
module_map = {
233+
"location_assignment": "spp_area",
234+
"service_point_management": "spp_service_points",
235+
"cash_transfer_needed": "spp_entitlement_cash",
236+
"bank_details_needed": "g2p_bank",
237+
"conducting_inkind_transfer": "spp_entitlement_in_kind",
238+
}
239+
for field, module_name in module_map.items():
240+
if getattr(self, field) == "yes":
241+
res = self._add_module_if_found(res, module_name)
242+
return res
243+
244+
def _install_farmer_modules(self, res):
245+
res = self._add_module_if_found(res, "spp_farmer_registry_base")
246+
if self.location_assignment == "yes":
247+
res = self._add_module_if_found(res, "spp_area_gis")
248+
if self.farmer_demo_management == "yes":
249+
for module_name in ["spp_base_demo", "spp_farmer_registry_demo", "spp_programs"]:
250+
res = self._add_module_if_found(res, module_name)
251+
return res
252+
206253
def _install_modules(self):
207254
self.ensure_one()
255+
res = self._find_module("theme_openspp_muk") or self.env["ir.module.module"]
208256

209-
def find_module(module_name):
210-
return self.env.ref(f"base.module_{module_name}", raise_if_not_found=False)
211-
212-
res = find_module("theme_openspp_muk")
213257
if self.registry_target == "spmis":
214-
res |= find_module("spp_base")
215-
res |= find_module("spp_programs")
216-
res |= find_module("spp_change_request")
217-
res |= find_module("spp_change_request_change_info")
218-
res |= find_module("spp_event_data")
219-
if self.sp_mis_demo_management == "yes":
220-
res |= find_module("spp_base_demo")
221-
res |= find_module("spp_mis_demo")
222-
if self.location_assignment == "yes":
223-
res |= find_module("spp_area")
224-
if self.service_point_management == "yes":
225-
res |= find_module("spp_service_points")
226-
if self.cash_transfer_needed == "yes":
227-
res |= find_module("spp_entitlement_cash")
228-
if self.bank_details_needed == "yes":
229-
res |= find_module("g2p_bank")
230-
if self.conducting_inkind_transfer == "yes":
231-
res |= find_module("spp_entitlement_in_kind")
232-
233-
if self.registry_target == "farmer":
234-
# TODO: needs to change this once the module for farmer registry default UI is created
235-
res |= find_module("spp_farmer_registry_base")
236-
if self.location_assignment == "yes":
237-
res |= find_module("spp_area_gis")
238-
if self.farmer_demo_management == "yes":
239-
res |= find_module("spp_base_demo")
240-
res |= find_module("spp_farmer_registry_demo")
241-
res |= find_module("spp_programs")
258+
res = self._install_spmis_base_modules(res)
259+
res = self._install_spmis_demo_modules(res)
260+
res = self._install_spmis_feature_modules(res)
261+
elif self.registry_target == "farmer":
262+
res = self._install_farmer_modules(res)
242263

243264
if self.id_management == "yes":
244-
res |= find_module("spp_idpass")
265+
res = self._add_module_if_found(res, "spp_idpass")
245266

246267
return res
247268

0 commit comments

Comments
 (0)