diff --git a/bemade_fsm/__manifest__.py b/bemade_fsm/__manifest__.py index f1d2daa..60e6672 100644 --- a/bemade_fsm/__manifest__.py +++ b/bemade_fsm/__manifest__.py @@ -36,13 +36,13 @@ "industry_fsm_stock", "industry_fsm_report", "industry_fsm_sale_report", + "fsm_equipment", "bemade_partner_root_ancestor", "mail", ], "data": [ "data/fsm_data.xml", "views/task_template_views.xml", - "views/equipment.xml", "security/ir.model.access.csv", "views/product_views.xml", "views/res_partner.xml", diff --git a/bemade_fsm/models/__init__.py b/bemade_fsm/models/__init__.py index a80bc37..5d52c07 100644 --- a/bemade_fsm/models/__init__.py +++ b/bemade_fsm/models/__init__.py @@ -2,9 +2,6 @@ from . import task_template from . import product_template from . import sale_order_line from . import sale_order -from . import equipment -from . import equipment_type -from . import equipment_tag from . import task from . import res_partner from . import fsm_visit diff --git a/bemade_fsm/models/equipment_type.py b/bemade_fsm/models/equipment_type.py deleted file mode 100644 index ccee230..0000000 --- a/bemade_fsm/models/equipment_type.py +++ /dev/null @@ -1,9 +0,0 @@ -from odoo import fields, models - - -class EquipmentType(models.Model): - _name = "bemade_fsm.equipment.type" - _description = "Field service equipment type" - _order = "id" - - name = fields.Char(string="Intervention Name", required=True, translate=True) diff --git a/bemade_fsm/models/fsm_visit.py b/bemade_fsm/models/fsm_visit.py index b10eeae..8a92042 100644 --- a/bemade_fsm/models/fsm_visit.py +++ b/bemade_fsm/models/fsm_visit.py @@ -40,7 +40,7 @@ class FSMVisit(models.Model): ) summarized_equipment_ids = fields.Many2many( - comodel_name="bemade_fsm.equipment", + comodel_name="fsm.equipment", string="Equipment to Service", compute="_compute_summarized_equipment_ids", ) diff --git a/bemade_fsm/models/res_partner.py b/bemade_fsm/models/res_partner.py index 6d0d143..4a09720 100644 --- a/bemade_fsm/models/res_partner.py +++ b/bemade_fsm/models/res_partner.py @@ -4,20 +4,6 @@ from odoo import api, fields, models class Partner(models.Model): _inherit = "res.partner" - equipment_count = fields.Integer(compute="_compute_equipment_count") - - owned_equipment_ids = fields.One2many( - comodel_name="bemade_fsm.equipment", - compute="_compute_owned_equipment_ids", - string="Owned Equipments", - ) - - equipment_ids = fields.One2many( - comodel_name="bemade_fsm.equipment", - inverse_name="partner_location_id", - string="Site Equipment", - ) - is_site_contact = fields.Boolean( string="Is a site contact", compute="_compute_is_site_contact", @@ -52,33 +38,11 @@ class Partner(models.Model): tracking=True, ) - is_service_site = fields.Boolean( - compute="_compute_is_service_site", - ) - - @api.depends("equipment_ids", "child_ids.company_type", "child_ids.equipment_ids") - def _compute_owned_equipment_ids(self): - for rec in self: - ids = rec.equipment_ids | rec.child_ids.mapped("equipment_ids") - rec.owned_equipment_ids = ids or False - @api.depends("site_ids") def _compute_is_site_contact(self): for rec in self: rec.is_site_contact = rec.site_ids - @api.depends("equipment_ids") - def _compute_equipment_count(self): - for rec in self: - all_equipment_ids = self.env["bemade_fsm.equipment"].search( - [("partner_location_id", "=", rec.id)] - ) - rec.equipment_count = len(all_equipment_ids) - @api.model def _search_is_site_contact(self, operator, value): return [("site_ids", "!=", False)] - - def _compute_is_service_site(self): - for rec in self: - rec.is_service_site = bool(rec.equipment_ids) diff --git a/bemade_fsm/models/sale_order.py b/bemade_fsm/models/sale_order.py index db45a40..665d0da 100644 --- a/bemade_fsm/models/sale_order.py +++ b/bemade_fsm/models/sale_order.py @@ -5,11 +5,11 @@ class SaleOrder(models.Model): _inherit = "sale.order" valid_equipment_ids = fields.One2many( - comodel_name="bemade_fsm.equipment", related="partner_id.owned_equipment_ids" + comodel_name="fsm.equipment", related="partner_id.owned_equipment_ids" ) default_equipment_ids = fields.Many2many( - comodel_name="bemade_fsm.equipment", + comodel_name="fsm.equipment", string="Default Equipment to Service", help="The default equipment to service for new sale order lines.", compute="_compute_default_equipment", @@ -18,7 +18,7 @@ class SaleOrder(models.Model): ) summary_equipment_ids = fields.Many2many( - comodel_name="bemade_fsm.equipment", + comodel_name="fsm.equipment", string="Equipment Being Serviced", compute="_compute_summary_equipment_ids", ) @@ -106,8 +106,9 @@ class SaleOrder(models.Model): return rec def _create_default_visit(self): - """Called when an order is confirmed with lines that will create an FSM task, in order to make sure there is - a visit line grouping all the service being done.""" + """Called when an order is confirmed with lines that will create an FSM task, + in order to make sure there is a visit line grouping all the service being done. + """ self.ensure_one() visit = self.env["bemade_fsm.visit"].create( { @@ -119,8 +120,8 @@ class SaleOrder(models.Model): visit.so_section_id.sequence = 0 def _create_or_organize_visits_if_needed(self): - """Adds a visit line to the top of the order if there are not already visit lines for an order with lines that - will create an FSM task.""" + """Adds a visit line to the top of the order if there are not already visit + lines for an order with lines that will create an FSM task.""" for order in self.filtered("company_id.create_default_fsm_visit"): if not order.visit_ids and order.is_fsm: order._create_default_visit() diff --git a/bemade_fsm/models/sale_order_line.py b/bemade_fsm/models/sale_order_line.py index e052786..a0ee0b4 100644 --- a/bemade_fsm/models/sale_order_line.py +++ b/bemade_fsm/models/sale_order_line.py @@ -4,7 +4,7 @@ from odoo import fields, models, api, _, Command class SaleOrderLine(models.Model): _inherit = "sale.order.line" valid_equipment_ids = fields.One2many( - comodel_name="bemade_fsm.equipment", related="order_id.valid_equipment_ids" + comodel_name="fsm.equipment", related="order_id.valid_equipment_ids" ) visit_ids = fields.One2many( @@ -42,7 +42,7 @@ class SaleOrderLine(models.Model): equipment_ids = fields.Many2many( string="Equipment to Service", - comodel_name="bemade_fsm.equipment", + comodel_name="fsm.equipment", relation="bemade_fsm_equipment_sale_order_line_rel", column1="sale_order_line_id", column2="equipment_id", diff --git a/bemade_fsm/models/task.py b/bemade_fsm/models/task.py index 29f7112..f673167 100644 --- a/bemade_fsm/models/task.py +++ b/bemade_fsm/models/task.py @@ -7,7 +7,7 @@ class Task(models.Model): _inherit = "project.task" equipment_ids = fields.Many2many( - comodel_name="bemade_fsm.equipment", + comodel_name="fsm.equipment", relation="bemade_fsm_task_equipment_rel", column1="task_id", column2="equipment_id", @@ -59,6 +59,11 @@ class Task(models.Model): compute="_compute_is_closed", ) + root_ancestor = fields.Many2one( + comodel_name="project.task", + compute="_compute_root_ancestor", + ) + def _compute_is_closed(self): for rec in self: rec.is_closed = rec.state in CLOSED_STATES @@ -213,6 +218,7 @@ class Task(models.Model): else: rec.name = title - @property - def root_ancestor(self): - return self.parent_id and self.parent_id.root_ancestor or self + @api.depends("parent_id", "parent_id.root_ancestor") + def _compute_root_ancestor(self): + for rec in self: + rec.root_ancestor = rec.parent_id and rec.parent_id.root_ancestor or self diff --git a/bemade_fsm/models/task_template.py b/bemade_fsm/models/task_template.py index 4d66f4f..8a9d453 100644 --- a/bemade_fsm/models/task_template.py +++ b/bemade_fsm/models/task_template.py @@ -58,7 +58,7 @@ class TaskTemplate(models.Model): planned_hours = fields.Float("Initially Planned Hours") equipment_ids = fields.Many2many( - comodel_name="bemade_fsm.equipment", + comodel_name="fsm.equipment", relation="bemade_fsm_task_template_equipment_rel", column1="task_template_id", column2="equipment_id", @@ -78,9 +78,7 @@ class TaskTemplate(models.Model): def _onchange_customer(self): for rec in self: new_equipment_ids = [ - eq.id - for eq in rec.equipment_ids - if eq.partner_location_id == rec.customer + eq.id for eq in rec.equipment_ids if eq.partner_id == rec.customer ] rec.write({"equipment_ids": [Command.set(new_equipment_ids)]}) @@ -107,7 +105,8 @@ class TaskTemplate(models.Model): return vals def create_task_from_self(self, project, name=False, parent_id=False): - """Create a project.task from this template and return it. Can be called on a RecordSet of multiple templates. + """Create a project.task from this template and return it. + Can be called on a RecordSet of multiple templates. :param project: project.project record the task should be added to :param name: name for the new task (defaults to template name) diff --git a/bemade_fsm/security/ir.model.access.csv b/bemade_fsm/security/ir.model.access.csv index 2c30345..12cb538 100644 --- a/bemade_fsm/security/ir.model.access.csv +++ b/bemade_fsm/security/ir.model.access.csv @@ -1,8 +1,5 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink access_bemade_fsm_task_template_manager,bemade_fsm_task_template,model_project_task_template,project.group_project_manager,1,1,1,1 access_bemade_fsm_task_template_user,bemade_fsm_task_template,model_project_task_template,project.group_project_user,1,1,1,1 -access_bemade_fsm_equipment,bemade_fsm_equipment,model_bemade_fsm_equipment,base.group_user,1,1,1,1 -access_bemade_fsm_equipment_tag,bemade_fsm_equipment_tag,model_bemade_fsm_equipment_tag,base.group_user,1,1,1,1 -access_bemade_fsm_equipment_type,access_bemade_fsm_equipment_type,model_bemade_fsm_equipment_type,base.group_user,1,0,0,0 access_bemade_fsm_visit,access_bemade_fsm_visit,model_bemade_fsm_visit,base.group_user,1,1,1,1 access_bemade_fsm_task_wizard,access_bemade_fsm_task_wizard,model_project_task_from_template_wizard,project.group_project_user,1,1,1,1 diff --git a/bemade_fsm/tests/__init__.py b/bemade_fsm/tests/__init__.py index 4aa75a5..1f3ec9c 100644 --- a/bemade_fsm/tests/__init__.py +++ b/bemade_fsm/tests/__init__.py @@ -1,7 +1,6 @@ from . import test_bemade_fsm_common from . import test_task_template from . import test_sale_order -from . import test_equipment from . import test_fsm_contact_setting from . import test_fsm_visit from . import test_task diff --git a/bemade_fsm/tests/test_bemade_fsm_common.py b/bemade_fsm/tests/test_bemade_fsm_common.py index 21cfca0..0c1fb31 100644 --- a/bemade_fsm/tests/test_bemade_fsm_common.py +++ b/bemade_fsm/tests/test_bemade_fsm_common.py @@ -69,7 +69,8 @@ class BemadeFSMBaseTest(TransactionCase): """Generates a partner with basic address filled in. :param name: The partner's name. - :param company_type: The type of partner, either 'company' or 'person' are accepted. + :param company_type: The type of partner, either 'company' or 'person' are + accepted. """ return cls.env["res.partner"].create( { @@ -119,10 +120,10 @@ class BemadeFSMBaseTest(TransactionCase): @classmethod def _generate_equipment(cls, name="test equipment", partner=None): - return cls.env["bemade_fsm.equipment"].create( + return cls.env["fsm.equipment"].create( { "name": name, - "partner_location_id": partner and partner.id or False, + "partner_id": partner and partner.id or False, } ) @@ -186,14 +187,18 @@ class BemadeFSMBaseTest(TransactionCase): ): """Generates a task template with the specified structure and naming. - :param parent: The parent task template for the top-level task template being generated - :param structure: A list of integers describing the number of tasks for each level of descendants. An empty - list represents only one top-level task template. If no structure is given, an empty list - will be used in its place. - :param names: The name prefixes to be given to the task templates at each level. Each prefix will be followed - by a sequential integer for its level. Child 1, Child 2, Grandchild 1, etc. If no names argument + :param parent: The parent task template for the top-level task template being + generated + :param structure: A list of integers describing the number of tasks for each + level of descendants. An empty list represents only one + top-level task template. If no structure is given, an empty + list will be used in its place. + :param names: The name prefixes to be given to the task templates at each level. + Each prefix will be followed by a sequential integer for its + level. Child 1, Child 2, Grandchild 1, etc. If no names argument is passed, a default ['Task Template'] argument will be used. - :param planned_hours: The number of planned hours for the top-level task template being generated. + :param planned_hours: The number of planned hours for the top-level task + template being generated. :param equipment: The equipment to add as linked equipment to the task template. """ if not names: diff --git a/bemade_fsm/tests/test_equipment.py b/bemade_fsm/tests/test_equipment.py deleted file mode 100644 index 8aa68e7..0000000 --- a/bemade_fsm/tests/test_equipment.py +++ /dev/null @@ -1,21 +0,0 @@ -from odoo.tests.common import tagged -from .test_bemade_fsm_common import BemadeFSMBaseTest -from odoo import Command -from odoo.exceptions import MissingError - - -@tagged("-at_install", "post_install") -class TestEquipment(BemadeFSMBaseTest): - def test_crud(self): - partner_company = self._generate_partner() - self._generate_partner("Site Contact", "person", partner_company) - equipment = self._generate_equipment("Test Equipment 1", partner_company) - - # Just make sure the basic ORM stuff is OK - self.assertTrue(equipment in partner_company.equipment_ids) - self.assertTrue(len(partner_company.equipment_ids) == 1) - - # Delete should cascade - partner_company.write({"equipment_ids": [Command.set([])]}) - with self.assertRaises(MissingError): - _ = equipment.name diff --git a/bemade_fsm/tests/test_fsm_contact_setting.py b/bemade_fsm/tests/test_fsm_contact_setting.py index 2344b10..670b90e 100644 --- a/bemade_fsm/tests/test_fsm_contact_setting.py +++ b/bemade_fsm/tests/test_fsm_contact_setting.py @@ -15,7 +15,8 @@ class SaleOrderFSMContactsCase(BemadeFSMBaseTest): so = self._generate_sale_order(parent_co) self.assertTrue(so.site_contacts == parent_co.site_contacts) - # Make sure updating the site contacts on the SO doesn't feed back to the partner + # Make sure updating the site contacts on the SO doesn't feed back to the + # partner so.write({"site_contacts": [Command.set([contact_1.id])]}) self.assertTrue(contact_1 in so.site_contacts) self.assertTrue(contact_2 not in so.site_contacts) @@ -39,7 +40,8 @@ class SaleOrderFSMContactsCase(BemadeFSMBaseTest): self.assertTrue(contact_1 in so.work_order_contacts) self.assertTrue(contact_2 in so.work_order_contacts) - # Make sure setting the work order contacts on the SO doesn't feed back to the partner + # Make sure setting the work order contacts on the SO doesn't feed back to the + # partner so.write({"work_order_contacts": [Command.set([contact_1.id])]}) self.assertTrue(contact_1 in so.work_order_contacts) self.assertTrue(contact_2 not in so.work_order_contacts) @@ -119,7 +121,8 @@ class SaleOrderFSMContactsCase(BemadeFSMBaseTest): self.assertFalse(so.work_order_contacts) self.assertFalse(so.site_contacts) - # Now set back to the location with the FSM contacts and make sure they get set on the SO + # Now set back to the location with the FSM contacts and make sure they get set + # on the SO form.partner_shipping_id = shipping_location form.save() self.assertEqual(so.work_order_contacts, shipping_location.work_order_contacts) diff --git a/bemade_fsm/tests/test_task.py b/bemade_fsm/tests/test_task.py index 156acbe..79f4a89 100644 --- a/bemade_fsm/tests/test_task.py +++ b/bemade_fsm/tests/test_task.py @@ -7,7 +7,8 @@ from odoo import Command class TaskTest(BemadeFSMBaseTest): @classmethod def setUpClass(cls): - # Chose to set up all tests the same way since this code was becoming very redundant + # Chose to set up all tests the same way since this code was becoming very + # redundant super().setUpClass() cls.user = cls._generate_project_manager_user("Bob", "Bob") @@ -62,7 +63,8 @@ class TaskTest(BemadeFSMBaseTest): self.assertFalse( any([t.propagate_assignment for t in task._get_all_subtasks()]) ) - # Then, test that assigning the parent only assigns its children, not its grandchildren + # Then, test that assigning the parent only assigns its children, not its + # grandchildren task.write({"user_ids": [Command.set([])]}) self.assertTrue(all([not t.user_ids for t in task | task.child_ids])) self.assertTrue( diff --git a/bemade_fsm/views/menus.xml b/bemade_fsm/views/menus.xml index 5ee0f1c..e9406c3 100644 --- a/bemade_fsm/views/menus.xml +++ b/bemade_fsm/views/menus.xml @@ -14,27 +14,4 @@ parent="industry_fsm.fsm_menu_root" groups="project.group_project_manager,industry_fsm.group_fsm_manager" /> - - - diff --git a/bemade_fsm/views/res_partner.xml b/bemade_fsm/views/res_partner.xml index df3b70e..7c04e8b 100644 --- a/bemade_fsm/views/res_partner.xml +++ b/bemade_fsm/views/res_partner.xml @@ -1,45 +1,15 @@ - - Equipments - bemade_fsm.equipment - tree,form - {'default_partner_location_id': active_id} - [("partner_location_id", "=", active_id)] - - - bemade_fsm.partner.equipment.location.form + partner.equipment.location.view.form res.partner - + - - - - - - - - - - - - - - - + + - - -
- -
- - - - - + + + + + + + + + +
@@ -91,21 +43,4 @@ - - bemade_fsm.equipment.tree - bemade_fsm.equipment - - - - - - + + + +