Review follow-up: the base fusion.technician.task.description is required=True and non-in-store tasks require an address (_check_address_required). So: - action_book_from_wizard now defaults description to 'Service booking' when the payload carries neither description nor issue (avoids a required-field failure). - test_task_without_order_is_allowed now sets description + is_in_store=True so it exercises only the relaxed _check_order_link, not those unrelated base constraints. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
76 lines
3.3 KiB
Python
76 lines
3.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
from datetime import date
|
|
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(2026, 6, 3),
|
|
'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': '2026-06-03', '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)
|