# -*- coding: utf-8 -*- from datetime import date, timedelta from odoo.tests.common import TransactionCase, tagged @tagged('post_install', '-at_install') class TestServiceBooking(TransactionCase): @classmethod def setUpClass(cls): super().setUpClass() cls.Task = cls.env['fusion.technician.task'] # technician_id is required on a task (domain x_fc_is_field_staff=True). cls.tech = cls.env['res.users'].create({ 'name': 'Service Booking Tech', 'login': 'svcbook_tech', 'x_fc_is_field_staff': True, }) def test_task_without_order_is_allowed(self): # No SO/PO must NOT raise after the relax. description is required and a # non-in-store task needs an address, so set both here to isolate the test # to the order-link relaxation (not those unrelated base constraints). t = self.Task.create({ 'task_type': 'repair', 'technician_id': self.tech.id, 'scheduled_date': date.today() + timedelta(days=7), 'description': 'Test repair', 'is_in_store': True, }) self.assertTrue(t.id) def test_sale_order_has_service_repair_flag(self): so = self.env['sale.order'].new({}) self.assertIn('x_fc_is_service_repair', so._fields) def test_resolve_service_lines_standard_rush(self): Task = self.Task lines = Task._resolve_service_lines('standard', 'rush', in_shop=False, distance_km=10.0) # call-out $120 + per-km line qty 20 @ $0.70 callout = [l for l in lines if l['price_unit'] == 120.0] per_km = [l for l in lines if l['name_is_km']] self.assertTrue(callout) self.assertEqual(per_km[0]['product_uom_qty'], 20.0) self.assertEqual(per_km[0]['price_unit'], 0.70) def test_resolve_service_lines_in_shop_empty_callout(self): lines = self.Task._resolve_service_lines('standard', 'normal', in_shop=True, distance_km=5.0) self.assertEqual(lines, []) def test_build_service_so(self): partner = self.env['res.partner'].create({'name': 'Walk-in Wanda'}) so = self.Task._build_service_so(partner, 'standard', 'normal', False, 0.0) self.assertEqual(so.state, 'draft') self.assertTrue(so.x_fc_is_service_repair) self.assertEqual(so.partner_id, partner) self.assertEqual(so.order_line[0].price_unit, 95.0) def test_action_book_creates_contact_task_and_so(self): payload = { 'cust_mode': 'new', 'customer': {'name': 'Nina New', 'phone': '4165550199', 'email': 'nina@x.com', 'street': '88 Bloor St E', 'city': 'Toronto'}, 'category': 'standard', 'timing': 'normal', 'in_shop': False, 'device': 'scooter', 'issue': "won't power on", 'date': (date.today() + timedelta(days=7)).strftime('%Y-%m-%d'), 'time_start': 9.0, 'duration_hr': 1.0, 'technician_id': self.tech.id, 'description': 'check battery', } res = self.Task.action_book_from_wizard(payload) self.assertTrue(res['task_id'] and res['order_id']) task = self.Task.browse(res['task_id']) self.assertEqual(task.sale_order_id.id, res['order_id']) self.assertEqual(task.sale_order_id.order_line[0].price_unit, 95.0) partner = self.env['res.partner'].search([('email', '=ilike', 'nina@x.com')], limit=1) self.assertTrue(partner)