From 7bed94980deb9a0d4939f41e86ae1b54f6b82ff0 Mon Sep 17 00:00:00 2001 From: Maxime Chambreuil Date: Thu, 19 Dec 2019 16:56:54 -0600 Subject: [PATCH] [FIX] contract_fieldservice --- contract_fieldservice/models/__init__.py | 9 ++++++-- .../models/contract_contract.py | 22 +++++++++++++++++++ contract_fieldservice/models/contract_line.py | 5 +++-- contract_fieldservice/models/fsm_location.py | 13 +++++++++++ contract_fieldservice/views/sale_view.xml | 4 ++-- 5 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 contract_fieldservice/models/contract_contract.py create mode 100644 contract_fieldservice/models/fsm_location.py diff --git a/contract_fieldservice/models/__init__.py b/contract_fieldservice/models/__init__.py index 767c863a..67f2ed17 100644 --- a/contract_fieldservice/models/__init__.py +++ b/contract_fieldservice/models/__init__.py @@ -1,3 +1,8 @@ +# Copyright (C) 2019 Open Source Integrators +# Copyright (C) 2019 Serpent Consulting Services # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - -from . import contract_line +from . import ( + contract_contract, + contract_line, + fsm_location, +) diff --git a/contract_fieldservice/models/contract_contract.py b/contract_fieldservice/models/contract_contract.py new file mode 100644 index 00000000..323a99b0 --- /dev/null +++ b/contract_fieldservice/models/contract_contract.py @@ -0,0 +1,22 @@ +# Copyright (C) 2019 Open Source Integrators +# Copyright (C) 2019 Serpent Consulting Services +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import api, fields, models + + +class ContractContract(models.Model): + _inherit = 'contract.contract' + + fsm_location_ids = fields.Many2many( + 'fsm.location', 'contract_fsm_location', + 'contract_id', 'fsm_location_id', string='Service Locations', + compute='compute_fsm_locations', readonly=True, store=True, index=True) + + @api.depends('contract_line_ids.fsm_location_id') + @api.model + def compute_fsm_locations(self): + location_ids = [] + for line in self.contract_line_ids: + location_ids.append(line.fsm_location_id and + line.fsm_location_id.id) + self.fsm_location_ids = [(6, 0, location_ids)] diff --git a/contract_fieldservice/models/contract_line.py b/contract_fieldservice/models/contract_line.py index 6e6dd4b5..68739766 100644 --- a/contract_fieldservice/models/contract_line.py +++ b/contract_fieldservice/models/contract_line.py @@ -1,10 +1,11 @@ # Copyright (C) 2019 Open Source Integrators +# Copyright (C) 2019 Serpent Consulting Services # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - from odoo import fields, models class ContractLine(models.Model): _inherit = 'contract.line' - fsm_location_id = fields.Many2one('fsm.location', 'Service To') + fsm_location_id = fields.Many2one('fsm.location', string='Service To', + index=True) diff --git a/contract_fieldservice/models/fsm_location.py b/contract_fieldservice/models/fsm_location.py new file mode 100644 index 00000000..b9b4a516 --- /dev/null +++ b/contract_fieldservice/models/fsm_location.py @@ -0,0 +1,13 @@ +# Copyright (C) 2019 Open Source Integrators +# Copyright (C) 2019 Serpent Consulting Services +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import fields, models + + +class FsmLocation(models.Model): + _inherit = 'fsm.location' + + contract_ids = fields.Many2many( + 'contract.contract', 'contract_fsm_location', + 'fsm_location_id', 'contract_id', string='Contracts', + readonly=True, store=True, index=True) diff --git a/contract_fieldservice/views/sale_view.xml b/contract_fieldservice/views/sale_view.xml index b4b44c20..373642f5 100644 --- a/contract_fieldservice/views/sale_view.xml +++ b/contract_fieldservice/views/sale_view.xml @@ -3,10 +3,10 @@ sale.order.form sale.order - + - [('contract_ids', 'in', parent.contract_id)] + [('contract_ids', 'in', contract_id)]