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.formres.partner
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
@@ -91,21 +43,4 @@
-
- bemade_fsm.equipment.tree
- bemade_fsm.equipment
-
-
-
-
-
-
-
-
-
diff --git a/bemade_fsm/views/task_template_views.xml b/bemade_fsm/views/task_template_views.xml
index aa61f5c..a5c40ec 100644
--- a/bemade_fsm/views/task_template_views.xml
+++ b/bemade_fsm/views/task_template_views.xml
@@ -23,8 +23,8 @@
diff --git a/bemade_fsm/views/task_views.xml b/bemade_fsm/views/task_views.xml
index 0a196b9..58ac808 100644
--- a/bemade_fsm/views/task_views.xml
+++ b/bemade_fsm/views/task_views.xml
@@ -19,8 +19,8 @@
).
+# Author: Marc Durepos (Contact : marc@bemade.org)
+#
+# This program is under the terms of the GNU Lesser General Public License,
+# version 3.
+#
+# For full license details, see https://www.gnu.org/licenses/lgpl-3.0.en.html.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+# DEALINGS IN THE SOFTWARE.
+#
+{
+ "name": "FSM Equipment",
+ "version": "17.0.0.1.0",
+ "summary": "Add the notion of client equipment for Field Service",
+ "category": "Services/Field Service",
+ "author": "Bemade Inc.",
+ "website": "http://www.bemade.org",
+ "license": "LGPL-3",
+ "depends": ["industry_fsm", "account"],
+ "data": [
+ "security/ir.model.access.csv",
+ "views/equipment_views.xml",
+ "views/res_partner_views.xml",
+ ],
+ "assets": {},
+ "installable": True,
+ "auto_install": False,
+}
diff --git a/fsm_equipment/models/__init__.py b/fsm_equipment/models/__init__.py
new file mode 100644
index 0000000..4ceb3a1
--- /dev/null
+++ b/fsm_equipment/models/__init__.py
@@ -0,0 +1,3 @@
+from . import equipment_tag
+from . import equipment
+from . import res_partner
diff --git a/bemade_fsm/models/equipment.py b/fsm_equipment/models/equipment.py
similarity index 55%
rename from bemade_fsm/models/equipment.py
rename to fsm_equipment/models/equipment.py
index 8743b55..ca55ac5 100644
--- a/bemade_fsm/models/equipment.py
+++ b/fsm_equipment/models/equipment.py
@@ -1,39 +1,39 @@
-from odoo import api, fields, models
+from odoo import models, fields, api, _
class Equipment(models.Model):
- _name = "bemade_fsm.equipment"
- _rec_name = "complete_name"
- _description = "Field service equipment"
+ _name = "fsm.equipment"
+ _description = "Partner-Owned Equipment"
_inherit = ["mail.thread", "mail.activity.mixin"]
- pid_tag = fields.Char(string="P&ID Tag", tracking=True)
-
- name = fields.Char(tracking=True, required=True)
-
- complete_name = fields.Char(
- string="Equipment Name", compute="_compute_complete_name", store=True
+ code = fields.Char(
+ tracking=True,
+ )
+ name = fields.Char(
+ tracking=True,
+ required=True,
)
tag_ids = fields.Many2many(
- comodel_name="bemade_fsm.equipment.tag",
- string="Application",
- help=(
- "Classify and analyze your equipment categories like: Boiler, Laboratory,"
- " Waste water, Pure water"
- ),
+ comodel_name="fsm.equipment.tag",
+ string="Tags",
)
description = fields.Text(tracking=True)
- partner_location_id = fields.Many2one(
+ partner_id = fields.Many2one(
comodel_name="res.partner",
string="Physical Address",
tracking=True,
ondelete="cascade",
)
- location_notes = fields.Text(string="Physical Location Notes", tracking=True)
+ location_notes = fields.Text(
+ string="Physical Location Notes",
+ tracking=True,
+ help="Any useful information about physical location "
+ "(door codes, directions, etc.).",
+ )
task_ids = fields.Many2many(
comodel_name="project.task",
@@ -45,13 +45,6 @@ class Equipment(models.Model):
active = fields.Boolean(default=True)
- @api.depends("partner_location_id")
- def _compute_partner(self):
- for rec in self:
- rec.partner_id = (
- rec.partner_location_id and rec.partner_location_id.root_ancestor
- )
-
@api.model
def name_search(self, name="", args=None, operator="ilike", limit=100):
args = args or []
@@ -60,9 +53,9 @@ class Equipment(models.Model):
[
"|",
"|",
- ("pid_tag", operator, name),
+ ("code", operator, name),
("name", operator, name),
- ("partner_location_id.name", operator, name),
+ ("partner_id.name", operator, name),
],
limit=limit,
)
@@ -77,13 +70,13 @@ class Equipment(models.Model):
"view_mode": "form",
"res_id": self.id,
"context": self.env.context,
- "res_model": "bemade_fsm.equipment",
+ "res_model": "fsm.equipment",
"type": "ir.actions.act_window",
}
- @api.depends("pid_tag", "name")
+ @api.depends("code", "name")
def _compute_complete_name(self):
for rec in self:
- tag_part = "[%s] " % rec.pid_tag if rec.pid_tag else ""
+ tag_part = "[%s] " % rec.code if rec.code else ""
name = rec.name or ""
rec.complete_name = tag_part + name
diff --git a/bemade_fsm/models/equipment_tag.py b/fsm_equipment/models/equipment_tag.py
similarity index 54%
rename from bemade_fsm/models/equipment_tag.py
rename to fsm_equipment/models/equipment_tag.py
index 8603901..678eb99 100644
--- a/bemade_fsm/models/equipment_tag.py
+++ b/fsm_equipment/models/equipment_tag.py
@@ -2,11 +2,17 @@ from odoo import fields, models
class EquipmentTag(models.Model):
- _name = "bemade_fsm.equipment.tag"
+ _name = "fsm.equipment.tag"
_description = "Field service equipment category"
- name = fields.Char(required=True, translate=True)
- color = fields.Integer("Color Index", default=10)
+ name = fields.Char(
+ required=True,
+ translate=True,
+ )
+ color = fields.Integer(
+ "Color Index",
+ default=10,
+ )
_sql_constraints = [
("name_uniq", "unique (name)", "Tag name already exists !"),
diff --git a/fsm_equipment/models/res_partner.py b/fsm_equipment/models/res_partner.py
new file mode 100644
index 0000000..48af4da
--- /dev/null
+++ b/fsm_equipment/models/res_partner.py
@@ -0,0 +1,47 @@
+from odoo import models, fields, api
+
+
+class Partner(models.Model):
+ _inherit = "res.partner"
+
+ equipment_count = fields.Integer(compute="_compute_equipment_count")
+
+ owned_equipment_ids = fields.One2many(
+ comodel_name="fsm.equipment",
+ compute="_compute_owned_equipment_ids",
+ string="Owned Equipments",
+ )
+
+ equipment_ids = fields.One2many(
+ comodel_name="fsm.equipment",
+ inverse_name="partner_id",
+ string="Site Equipment",
+ )
+
+ is_service_site = fields.Boolean(
+ compute="_compute_is_service_site",
+ help="A partner is a service site if it has one or more equipments.",
+ )
+
+ @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("equipment_ids")
+ def _compute_equipment_count(self):
+ for rec in self:
+ all_equipment_ids = self.env["fsm.equipment"].search(
+ [("partner_id", "=", rec.id)]
+ )
+ rec.equipment_count = len(all_equipment_ids)
+
+ @api.depends("equipment_ids")
+ def _compute_is_service_site(self):
+ for rec in self:
+ rec.is_service_site = bool(rec.equipment_ids)
diff --git a/fsm_equipment/security/ir.model.access.csv b/fsm_equipment/security/ir.model.access.csv
new file mode 100644
index 0000000..1a784e3
--- /dev/null
+++ b/fsm_equipment/security/ir.model.access.csv
@@ -0,0 +1,3 @@
+id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
+access_fsm_equipment,fsm_equipment,model_fsm_equipment,base.group_user,1,1,1,1
+access_fsm_equipment_tag,fsm_equipment_tag,model_fsm_equipment_tag,base.group_user,1,1,1,1
diff --git a/bemade_fsm/views/equipment.xml b/fsm_equipment/views/equipment_views.xml
similarity index 52%
rename from bemade_fsm/views/equipment.xml
rename to fsm_equipment/views/equipment_views.xml
index fca156f..63c95eb 100644
--- a/bemade_fsm/views/equipment.xml
+++ b/fsm_equipment/views/equipment_views.xml
@@ -2,23 +2,26 @@
- bemade_fsm.equipment.form
- bemade_fsm.equipment
+ fsm.equipment.form
+ fsm.equipment
- bemade_fsm.equipment.tree
- bemade_fsm.equipment
+ fsm.equipment.tree
+ fsm.equipment
-
+
-
+ Equipment
- bemade_fsm.equipment
+ fsm.equipmenttree,formEquipment Tag
- bemade_fsm.equipment.tag
+ fsm.equipment.tagtree,form
-
+
+
+
diff --git a/fsm_equipment/views/res_partner_views.xml b/fsm_equipment/views/res_partner_views.xml
new file mode 100644
index 0000000..c41b0bb
--- /dev/null
+++ b/fsm_equipment/views/res_partner_views.xml
@@ -0,0 +1,62 @@
+
+
+
+ Partner Equipment
+ fsm.equipment
+ tree,form
+ {'default_partner_location_id': active_id}
+ [("partner_id", "=", active_id)]
+
+
+ fsm.equipment.tree
+ fsm.equipment
+
+
+
+
+
+
+
+
+
+
+ bemade_fsm.partner.equipment.location.form
+ res.partner
+
+
+
+
+
+
+
+
+