Skip to content

Commit

Permalink
[FIX] fieldservice (PM OCA#515 and OCA#577) (OCA#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
osi-scampbell authored and brian10048 committed Nov 17, 2023
1 parent 6436a10 commit cfbc31d
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 1 deletion.
4 changes: 4 additions & 0 deletions fieldservice/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (C) 2019 - TODAY, Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import test_fsm_wizard
111 changes: 111 additions & 0 deletions fieldservice/tests/test_fsm_wizard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# 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


class FieldServiceTransactionCase(TransactionCase):
"""
Test used to check that the base functionalities of Field Service.
- test_convert_location: tests that a res.partner can be converted
into a fsm.location.
- test_convert_person: tests that a res.partner can be converted into
a fsm.person.
- test_convert_sublocation: tests that the sub-contacts on a
res.partner are converted into Other Addresses.
"""
def setUp(self):
super(FieldServiceTransactionCase, self).setUp()
# create a Res Partner
self.test_partner = self.env['res.partner'].\
create({
'name': 'Test Partner',
'phone': '123',
'email': 'tp@email.com',
})
# create a Res Partner to be converted to FSM Location/Person
self.test_loc_partner = self.env['res.partner'].\
create({
'name': 'Test Loc Partner',
'phone': 'ABC',
'email': 'tlp@email.com',
})
# create expected FSM Location to compare to converted FSM Location
self.test_location = self.env['fsm.location'].\
create({
'name': 'Test Location',
'phone': '123',
'email': 'tp@email.com',
'partner_id': self.test_loc_partner.id,
'owner_id': self.test_loc_partner.id,
'customer_id': self.test_loc_partner.id,
})
# create expected FSM Person to compare to converted FSM Person
self.test_person = self.env['fsm.person'].\
create({
'name': 'Test Person',
'phone': '123',
'email': 'tp@email.com',
})
self.test_wizard = self.env['fsm.wizard']

def test_convert_location(self):
# convert test_partner to FSM Location
self.test_wizard.action_convert_location(self.test_partner)

# check if there is a new FSM Location with name 'Test Partner'
self.wiz_location = self.env['fsm.location'].\
search([('name', '=', 'Test Partner')])

# check if 'Test Partner' creation successful and fields copied over
self.assertEqual(self.test_location.phone, self.wiz_location.phone)
self.assertEqual(self.test_location.email, self.wiz_location.email)

def test_convert_person(self):
# convert test_partner to FSM Person
self.test_wizard.action_convert_person(self.test_partner)

# check if there is a new FSM Person with name 'Test Partner'
self.wiz_person = self.env['fsm.person'].\
search([('name', '=', 'Test Partner')])

# check if 'Test Partner' creation successful and fields copied over
self.assertEqual(self.test_person.phone, self.wiz_person.phone)
self.assertEqual(self.test_person.email, self.wiz_person.email)

def test_convert_sublocation(self):
# create 4 Res Partners each with different type
s1 = self.env['res.partner'].create({
'name': 'sub partner 1',
'type': 'contact'
})
s2 = self.env['res.partner'].create({
'name': 'sub partner 2',
'type': 'invoice'
})
s3 = self.env['res.partner'].create({
'name': 'sub partner 3',
'type': 'delivery'
})
s4 = self.env['res.partner'].create({
'name': 'sub partner 4',
'type': 'private'
})

# create parent Res Partner and assign its children
children = [s1.id, s2.id, s3.id, s4.id]
parent = s1 = self.env['res.partner'].create({
'name': 'Parent Partner',
'child_ids': [(6, 0, children)]
})

# convert Parent Partner to FSM Location
self.test_wizard.action_convert_location(parent)

# check if 'Parent Partner' creation successful and fields copied over
wiz_parent = self.env['fsm.location'].\
search([('name', '=', 'Parent Partner')])

# check all children were assigned type 'other'
for child in wiz_parent.child_ids:
self.assertEqual(child.type, 'other')
2 changes: 1 addition & 1 deletion fieldservice/views/fsm_order.xml
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@
<field name="arch" type="xml">
<search string="Orders">
<field name="name"
filter_domain="['|', ('name', 'ilike', self), ('code', '=like', str(self) + '%')]"
filter_domain="['|', ('name', 'ilike', self), ('name', '=like', str(self) + '%')]"
string="FSM Order Name"/>
<field name="location_id"/>
<field name="branch_id"/>
Expand Down
5 changes: 5 additions & 0 deletions fieldservice/wizard/fsm_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def action_convert_location(self, partner):
'customer_id': partner.id}
self.env['fsm.location'].create(vals)
partner.write({'fsm_location': True})
self.action_other_address(partner)
else:
raise UserError(_('A Field Service Location related to that'
' partner already exists.'))
Expand All @@ -50,3 +51,7 @@ def action_convert_person(self, partner):
else:
raise UserError(_('A Field Service Worker related to that'
' partner already exists.'))

def action_other_address(self, partner):
for child in partner.child_ids:
child.type = 'other'

0 comments on commit cfbc31d

Please sign in to comment.