-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[12.0][IMP] fieldservice, improve test
- Loading branch information
Showing
12 changed files
with
535 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
|
||
<!-- res.partner --> | ||
<record id="test_partner" model="res.partner"> | ||
<field name="name">Test Partner</field> | ||
<field name="phone">123</field> | ||
<field name="email">tp@email.com</field> | ||
</record> | ||
<record id="test_loc_partner" model="res.partner"> | ||
<field name="name">Test Loc Partner</field> | ||
<field name="phone">ABC</field> | ||
<field name="email">tlp@email.com</field> | ||
</record> | ||
<record id="location_partner_1" model="res.partner"> | ||
<field name="name">Loc Partner 1</field> | ||
</record> | ||
<record id="location_partner_2" model="res.partner"> | ||
<field name="name">Loc Partner 1</field> | ||
</record> | ||
<record id="location_partner_3" model="res.partner"> | ||
<field name="name">Loc Partner 1</field> | ||
</record> | ||
|
||
<!-- res.partner with contacts --> | ||
<record id="s1" model="res.partner"> | ||
<field name="name">sub partner 1</field> | ||
<field name="type">contact</field> | ||
</record> | ||
<record id="s2" model="res.partner"> | ||
<field name="name">sub partner 2</field> | ||
<field name="type">invoice</field> | ||
</record> | ||
<record id="s3" model="res.partner"> | ||
<field name="name">sub partner 3</field> | ||
<field name="type">delivery</field> | ||
</record> | ||
<record id="s4" model="res.partner"> | ||
<field name="name">sub partner 4</field> | ||
<field name="type">private</field> | ||
</record> | ||
<record id="test_parent_partner" model="res.partner"> | ||
<field name="name">Parent Partner</field> | ||
<field name="child_ids" eval="[(6, 0, [ref('s1'), ref('s2'), ref('s3'), ref('s4')])]"/> | ||
</record> | ||
|
||
<!-- fsm.person --> | ||
<record id="test_person" model="fsm.person"> | ||
<field name="name">Test Person</field> | ||
<field name="phone">123</field> | ||
<field name="email">tp@email.com</field> | ||
</record> | ||
|
||
<!-- fsm.region --> | ||
<record id="test_region" model="fsm.region"> | ||
<field name="name">Test Region</field> | ||
</record> | ||
<record id="test_district" model="fsm.district"> | ||
<field name="name">Test District</field> | ||
<field name="region_id" eval="ref('test_region')"/> | ||
</record> | ||
<record id="test_branch" model="fsm.branch"> | ||
<field name="name">Test Branch</field> | ||
<field name="district_id" eval="ref('test_district')"/> | ||
</record> | ||
<record id="test_territory" model="fsm.territory"> | ||
<field name="name">Test Territory</field> | ||
<field name="branch_id" eval="ref('test_branch')"/> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
|
||
<!-- Equipment states --> | ||
<record id="equipment_stage_1" model="fsm.stage"> | ||
<field name="name">Equipment-1</field> | ||
<field name="sequence">1</field> | ||
<field name="stage_type">equipment</field> | ||
</record> | ||
<record id="equipment_stage_2" model="fsm.stage"> | ||
<field name="name">Equipment-2</field> | ||
<field name="sequence">2</field> | ||
<field name="stage_type">equipment</field> | ||
</record> | ||
<record id="equipment_stage_3" model="fsm.stage"> | ||
<field name="name">Equipment-3</field> | ||
<field name="sequence">3</field> | ||
<field name="stage_type">equipment</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
|
||
<!-- Location states --> | ||
<record id="location_stage_1" model="fsm.stage"> | ||
<field name="name">Location-1</field> | ||
<field name="sequence">1</field> | ||
<field name="stage_type">location</field> | ||
</record> | ||
<record id="location_stage_2" model="fsm.stage"> | ||
<field name="name">Location-2</field> | ||
<field name="sequence">2</field> | ||
<field name="stage_type">location</field> | ||
</record> | ||
<record id="location_stage_3" model="fsm.stage"> | ||
<field name="name">Location-3</field> | ||
<field name="sequence">3</field> | ||
<field name="stage_type">location</field> | ||
</record> | ||
|
||
<!-- fsm.location --> | ||
<record id="test_location" model="fsm.location"> | ||
<field name="name">Test Location</field> | ||
<field name="phone">123</field> | ||
<field name="email">tp@email.com</field> | ||
<field name="partner_id" eval="ref('test_loc_partner')"/> | ||
<field name="owner_id" eval="ref('test_loc_partner')"/> | ||
<field name="customer_id" eval="ref('test_loc_partner')"/> | ||
<field name="territory_id" eval="ref('test_territory')"/> | ||
<field name="branch_id" eval="ref('test_branch')"/> | ||
<field name="district_id" eval="ref('test_district')"/> | ||
<field name="region_id" eval="ref('test_region')"/> | ||
<field name="direction">New the old inventory</field> | ||
<field name="street">14 Tower A, main street</field> | ||
<field name="street2">Bangkok, Thailand</field> | ||
</record> | ||
|
||
<!-- Other locations --> | ||
<record id="location_1" model="fsm.location"> | ||
<field name="name">Location 1</field> | ||
<field name="partner_id" eval="ref('location_partner_1')"/> | ||
<field name="owner_id" eval="ref('location_partner_1')"/> | ||
<field name="customer_id" eval="ref('location_partner_1')"/> | ||
</record> | ||
|
||
<record id="location_2" model="fsm.location"> | ||
<field name="name">Location 2</field> | ||
<field name="partner_id" eval="ref('location_partner_2')"/> | ||
<field name="owner_id" eval="ref('location_partner_2')"/> | ||
<field name="customer_id" eval="ref('location_partner_2')"/> | ||
</record> | ||
|
||
<record id="location_3" model="fsm.location"> | ||
<field name="name">Location 3</field> | ||
<field name="partner_id" eval="ref('location_partner_3')"/> | ||
<field name="owner_id" eval="ref('location_partner_3')"/> | ||
<field name="customer_id" eval="ref('location_partner_3')"/> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
|
||
<!-- Worker states --> | ||
<record id="worker_stage_1" model="fsm.stage"> | ||
<field name="name">Workder-1</field> | ||
<field name="sequence">1</field> | ||
<field name="stage_type">worker</field> | ||
</record> | ||
<record id="worker_stage_2" model="fsm.stage"> | ||
<field name="name">Workder-2</field> | ||
<field name="sequence">2</field> | ||
<field name="stage_type">worker</field> | ||
</record> | ||
<record id="worker_stage_3" model="fsm.stage"> | ||
<field name="name">Workder-3</field> | ||
<field name="sequence">3</field> | ||
<field name="stage_type">worker</field> | ||
</record> | ||
|
||
<!-- persons --> | ||
<record id="person_1" model="fsm.person"> | ||
<field name="name">Worker-1</field> | ||
</record> | ||
<record id="person_2" model="fsm.person"> | ||
<field name="name">Worker-2</field> | ||
</record> | ||
<record id="person_3" model="fsm.person"> | ||
<field name="name">Worker-3</field> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Copyright (C) 2019 - TODAY, Open Source Integrators | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo.tests.common import TransactionCase, Form | ||
|
||
|
||
class FSMEquipment(TransactionCase): | ||
|
||
def setUp(self): | ||
super(FSMEquipment, self).setUp() | ||
self.Equipment = self.env['fsm.equipment'] | ||
self.test_location = self.env.ref('fieldservice.test_location') | ||
self.test_territory = self.env.ref('fieldservice.test_territory') | ||
self.test_branch = self.env.ref('fieldservice.test_branch') | ||
self.test_district = self.env.ref('fieldservice.test_district') | ||
self.test_region = self.env.ref('fieldservice.test_region') | ||
self.current_location = self.env.ref('fieldservice.location_1') | ||
|
||
def test_fsm_equipment(self): | ||
""" Test createing new equipment | ||
- Default stage | ||
- Onchange location | ||
- Change stage | ||
""" | ||
# Create an equipment | ||
view_id = ('fieldservice.fsm_equipment_form_view') | ||
with Form(self.Equipment, view=view_id) as f: | ||
f.name = 'Equipment 1' | ||
f.current_location_id = self.current_location | ||
f.location_id = self.test_location | ||
equipment = f.save() | ||
# Test onchange location | ||
self.assertEqual(self.test_territory, equipment.territory_id) | ||
self.assertEqual(self.test_branch, equipment.branch_id) | ||
self.assertEqual(self.test_district, equipment.district_id) | ||
self.assertEqual(self.test_region, equipment.region_id) | ||
# Test initial stage | ||
self.assertEqual(equipment.stage_id, | ||
self.env.ref('fieldservice.equipment_stage_1')) | ||
# Test change state | ||
equipment.next_stage() | ||
self.assertEqual(equipment.stage_id, | ||
self.env.ref('fieldservice.equipment_stage_2')) | ||
equipment.next_stage() | ||
self.assertEqual(equipment.stage_id, | ||
self.env.ref('fieldservice.equipment_stage_3')) | ||
self.assertTrue(equipment.hide) # hide as max stage | ||
equipment.previous_stage() | ||
self.assertEqual(equipment.stage_id, | ||
self.env.ref('fieldservice.equipment_stage_2')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
# Copyright (C) 2019 - TODAY, Open Source Integrators | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo.tests.common import TransactionCase, Form | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class FSMLocation(TransactionCase): | ||
|
||
def setUp(self): | ||
super(FSMLocation, self).setUp() | ||
self.Location = self.env['fsm.location'] | ||
self.Equipment = self.env['fsm.equipment'] | ||
self.test_location = self.env.ref('fieldservice.test_location') | ||
self.location_1 = self.env.ref('fieldservice.location_1') | ||
self.location_2 = self.env.ref('fieldservice.location_2') | ||
self.location_3 = self.env.ref('fieldservice.location_3') | ||
self.test_territory = self.env.ref('fieldservice.test_territory') | ||
self.test_loc_partner = self.env.ref('fieldservice.' | ||
'test_loc_partner') | ||
self.location_partner_1 = self.env.ref('fieldservice.' | ||
'location_partner_1') | ||
self.location_partner_2 = self.env.ref('fieldservice.' | ||
'location_partner_2') | ||
self.location_partner_3 = self.env.ref('fieldservice.' | ||
'location_partner_3') | ||
|
||
def test_fsm_location(self): | ||
""" Test createing new location | ||
- Onchange parent, will get all parent info | ||
- Default stage | ||
- Change stage | ||
- Create fsm.location.person if auto_populate_persons_on_location | ||
""" | ||
# Create an equipment | ||
view_id = ('fieldservice.fsm_location_form_view') | ||
with Form(self.Location, view=view_id) as f: | ||
f.name = 'Child Location' | ||
f.fsm_parent_id = self.test_location | ||
location = f.save() | ||
# Test child location equal to parent location | ||
for x in ['owner_id', 'customer_id', 'contact_id', 'direction', | ||
'street', 'street2', 'city', 'zip', 'state_id', 'country_id', | ||
'tz', 'territory_id']: | ||
self.assertEqual(location[x], self.test_location[x]) | ||
|
||
# Test initial stage | ||
self.assertEqual(location.stage_id, | ||
self.env.ref('fieldservice.location_stage_1')) | ||
# Test change state | ||
location.next_stage() | ||
self.assertEqual(location.stage_id, | ||
self.env.ref('fieldservice.location_stage_2')) | ||
location.next_stage() | ||
self.assertEqual(location.stage_id, | ||
self.env.ref('fieldservice.location_stage_3')) | ||
self.assertTrue(location.hide) # hide as max stage | ||
location.previous_stage() | ||
self.assertEqual(location.stage_id, | ||
self.env.ref('fieldservice.location_stage_2')) | ||
# Test create fsm.location.person, when has if territory has person_ids | ||
self.env.user.company_id.auto_populate_persons_on_location = True | ||
person_ids = [self.env.ref('fieldservice.person_1').id, | ||
self.env.ref('fieldservice.person_2').id, | ||
self.env.ref('fieldservice.person_3').id] | ||
self.test_territory.write({'person_ids': [(6, 0, person_ids)]}) | ||
location.territory_id = self.test_territory | ||
self.assertEqual(len(location.person_ids), 0) | ||
location._onchange_territory_id() | ||
self.assertEqual(len(location.person_ids), 3) | ||
|
||
def test_fsm_multi_sublocation(self): | ||
""" Test create location with many sub locations | ||
- Test recursion exceptoin | ||
- Test count all equipments, contacts, sublocations | ||
""" | ||
# Test Location > Location 1 > Location 2 > Location 3 | ||
self.location_3.fsm_parent_id = self.location_2 | ||
self.location_2.fsm_parent_id = self.location_1 | ||
self.location_1.fsm_parent_id = self.test_location | ||
# Test sublocation_count of each level | ||
self.assertEqual((self.test_location.sublocation_count, | ||
self.location_1.sublocation_count, | ||
self.location_2.sublocation_count, | ||
self.location_3.sublocation_count), (3, 2, 1, 0)) | ||
loc_ids = self.test_location.action_view_sublocation()['domain'][0][2] | ||
loc_1_ids = self.location_1.action_view_sublocation()['domain'][0][2] | ||
loc_2_ids = [self.location_2.action_view_sublocation()['res_id']] | ||
loc_3_ids = self.location_3.action_view_sublocation()['domain'][0][2] | ||
self.assertEqual((len(loc_ids), len(loc_1_ids), len(loc_2_ids), | ||
len(loc_3_ids)), (3, 2, 1, 0)) | ||
|
||
# Test recursion exception | ||
with self.assertRaises(ValidationError): | ||
self.test_location.fsm_parent_id = self.location_3 | ||
self.test_location.fsm_parent_id = False # Set back | ||
|
||
# Add equipments on each locations, and test counting | ||
location_vs_num_eq = {self.test_location.id: 1, # Topup = 9 | ||
self.location_1.id: 1, # Topup = 8 | ||
self.location_2.id: 5, # Topup = 7 | ||
self.location_3.id: 2} # Topup = 2 | ||
for loc_id, num_eq in location_vs_num_eq.items(): | ||
for i in range(num_eq): | ||
self.Equipment.create({ | ||
'name': 'Eq-%s-%s' % (str(loc_id), str(i+1)), | ||
'location_id': loc_id, | ||
'current_location_id': loc_id, }) | ||
# Test valid equipments at each location | ||
self.assertEqual((self.test_location.equipment_count, | ||
self.location_1.equipment_count, | ||
self.location_2.equipment_count, | ||
self.location_3.equipment_count), (2, 6, 7, 2)) # !! | ||
# Test smart button to open equipment | ||
loc_eq_ids = self.test_location.action_view_equipment()['domain'][0][2] | ||
loc_1_eq_ids = self.location_1.action_view_equipment()['domain'][0][2] | ||
loc_2_eq_ids = self.location_2.action_view_equipment()['domain'][0][2] | ||
loc_3_eq_ids = self.location_3.action_view_equipment()['domain'][0][2] | ||
self.assertEqual((len(loc_eq_ids), len(loc_1_eq_ids), | ||
len(loc_2_eq_ids), len(loc_3_eq_ids)), (9, 8, 7, 2)) | ||
|
||
# Set service_location_id, on relavant res.partner, test contact count | ||
self.test_loc_partner.service_location_id = self.test_location | ||
self.location_partner_1.service_location_id = self.location_1 | ||
self.location_partner_2.service_location_id = self.location_2 | ||
self.location_partner_3.service_location_id = self.location_3 | ||
# Test valid contacts at each location | ||
self.assertEqual((self.test_location.contact_count, | ||
self.location_1.contact_count, | ||
self.location_2.contact_count, | ||
self.location_3.contact_count), (4, 3, 2, 1)) | ||
# Test smart button to open contacts | ||
cont_ids = self.test_location.action_view_contacts()['domain'][0][2] | ||
cont_1_ids = self.location_1.action_view_contacts()['domain'][0][2] | ||
cont_2_ids = self.location_2.action_view_contacts()['domain'][0][2] | ||
cont_3_ids = [self.location_3.action_view_contacts()['res_id']] | ||
self.assertEqual((len(cont_ids), len(cont_1_ids), | ||
len(cont_2_ids), len(cont_3_ids)), (4, 3, 2, 1)) |
Oops, something went wrong.