diff --git a/bemade_fsm/models/task.py b/bemade_fsm/models/task.py index 7ee4a71..a751766 100644 --- a/bemade_fsm/models/task.py +++ b/bemade_fsm/models/task.py @@ -5,3 +5,7 @@ class Task(models.Model): _inherit = "project.task" equipment_id = fields.Many2one("bemade_fsm.equipment", string="Target Equipment") + + work_order_contacts = fields.Many2many(related='sale_line_id.order_id.work_order_contacts') + site_contacts = fields.Many2many(related='sale_line_id.order_id.site_contacts') + equipment_ids = fields.Many2many(related='sale_line_id.order_id.equipment_ids') diff --git a/bemade_fsm/tests/__init__.py b/bemade_fsm/tests/__init__.py index fc3738e..955686d 100644 --- a/bemade_fsm/tests/__init__.py +++ b/bemade_fsm/tests/__init__.py @@ -3,3 +3,4 @@ from . import test_task_template from . import test_task_template_sale_order from . import test_equipment from . import test_fsm_contact_setting +from . import test_so_task_contacts diff --git a/bemade_fsm/tests/test_so_task_contacts.py b/bemade_fsm/tests/test_so_task_contacts.py new file mode 100644 index 0000000..79d4a5b --- /dev/null +++ b/bemade_fsm/tests/test_so_task_contacts.py @@ -0,0 +1,37 @@ +from .test_task_template_sale_order import TestTaskTemplateSalesOrder +from odoo import Command + + +class TestSaleOrderTaskContacts(TestTaskTemplateSalesOrder): + @classmethod + def setUpClass(cls): + super().setUpClass() + Partner = cls.env['res.partner'] + cls.partner2 = Partner.create({ + 'name': 'New Partner', + 'company_type': 'company', + }) + cls.contact = Partner.create({ + 'name': 'Contact', + 'company_type': 'person', + 'parent_id': cls.partner2.id, + }) + + def _test_contacts(self, field): + def ga(obj): + return getattr(obj, field) + self.partner2.write({field: [Command.set([self.contact.id])]}) + self.sale_order1.write( + {'partner_id': self.partner2.id, field: [Command.set(ga(self.partner2).ids)]}) + so = self.sale_order1 + self.assertTrue(ga(so)) + so.action_confirm() + task = so.order_line[0].task_id + self.assertTrue(ga(task)) + self.assertTrue(ga(task) == ga(so)) + + def test_work_order_contacts_on_task(self): + self._test_contacts('work_order_contacts') + + def test_site_contacts_on_task(self): + self._test_contacts('site_contacts') \ No newline at end of file diff --git a/bemade_fsm/tests/test_task_template_sale_order.py b/bemade_fsm/tests/test_task_template_sale_order.py index e2fe05e..9fde384 100644 --- a/bemade_fsm/tests/test_task_template_sale_order.py +++ b/bemade_fsm/tests/test_task_template_sale_order.py @@ -84,4 +84,4 @@ class TestTaskTemplateSalesOrder(TestTaskTemplateCommon): sol2 = so.order_line[1] assert_structure(sol1) assert_structure(sol2) - + \ No newline at end of file