From dec6c201deab5038dcf42e9ed7c12ee19373f43d Mon Sep 17 00:00:00 2001 From: Steve Campbell Date: Mon, 10 Jun 2019 16:15:31 -0700 Subject: [PATCH] [FIX] fieldservice (PM #515 and #577) (#230) --- fieldservice/tests/__init__.py | 4 + fieldservice/tests/test_fsm_wizard.py | 111 ++++++++++++++++++++++++++ fieldservice/views/fsm_order.xml | 2 +- fieldservice/wizard/fsm_wizard.py | 5 ++ 4 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 fieldservice/tests/__init__.py create mode 100644 fieldservice/tests/test_fsm_wizard.py diff --git a/fieldservice/tests/__init__.py b/fieldservice/tests/__init__.py new file mode 100644 index 0000000000..279701564c --- /dev/null +++ b/fieldservice/tests/__init__.py @@ -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 diff --git a/fieldservice/tests/test_fsm_wizard.py b/fieldservice/tests/test_fsm_wizard.py new file mode 100644 index 0000000000..fd82b6900e --- /dev/null +++ b/fieldservice/tests/test_fsm_wizard.py @@ -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') diff --git a/fieldservice/views/fsm_order.xml b/fieldservice/views/fsm_order.xml index 244ebb5158..fb5a9535ed 100644 --- a/fieldservice/views/fsm_order.xml +++ b/fieldservice/views/fsm_order.xml @@ -308,7 +308,7 @@ diff --git a/fieldservice/wizard/fsm_wizard.py b/fieldservice/wizard/fsm_wizard.py index 36194b5d98..55ca585881 100644 --- a/fieldservice/wizard/fsm_wizard.py +++ b/fieldservice/wizard/fsm_wizard.py @@ -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.')) @@ -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'