size
int64
0
304k
ext
stringclasses
1 value
lang
stringclasses
1 value
branch
stringclasses
1 value
content
stringlengths
0
304k
avg_line_length
float64
0
238
max_line_length
int64
0
304k
712
py
PYTHON
15.0
# Copyright (C) 2018 Brian McMaster # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import models class StockRule(models.Model): _inherit = "stock.rule" def _get_stock_move_values( self, product_id, product_qty, product_uom, location_id, name, origin, company_id, values, ): vals = super()._get_stock_move_values( product_id, product_qty, product_uom, location_id, name, origin, company_id, values, ) vals.update({"fsm_order_id": values.get("fsm_order_id")}) return vals
22.967742
712
909
py
PYTHON
15.0
# Copyright (C) 2019 - TODAY, Open Source Integrators, Brian McMaster # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "Field Service - Sub-Status", "summary": "Add sub-statuses to Field Service orders", "version": "15.0.1.0.0", "category": "Field Service", "author": "Open Source Integrators, " "Brian McMaster, " "Odoo Community Association (OCA)", "website": "https://github.com/OCA/field-service", "depends": [ "fieldservice", ], "data": [ "data/fsm_stage_status.xml", "data/fsm_stage.xml", "data/mail_data.xml", "security/ir.model.access.csv", "views/fsm_stage_status.xml", "views/fsm_stage.xml", "views/fsm_order.xml", ], "installable": True, "license": "AGPL-3", "development_status": "Beta", "maintainers": ["max3903", "brian10048", "bodedra"], }
31.344828
909
2,297
py
PYTHON
15.0
# Copyright (C) 2021 - TODAY, Open Source Integrators # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) from datetime import timedelta from odoo import fields from odoo.tests.common import TransactionCase class FSMSubstatusCase(TransactionCase): def setUp(self): super(FSMSubstatusCase, self).setUp() self.WorkOrder = self.env["fsm.order"] self.stage_id = self.WorkOrder._default_stage_id() self.init_values = {"sub_stage_id": self.stage_id.sub_stage_id.id} self.StageStatus = self.env["fsm.stage.status"] # create a Res Partner to be converted to FSM Location/Person self.test_loc_partner = self.env["res.partner"].create( {"name": "Test Loc Partner", "phone": "ABC", "email": "[email protected]"} ) # create expected FSM Location to compare to converted FSM Location self.test_location = self.env["fsm.location"].create( { "name": "Test Location", "phone": "123", "email": "[email protected]", "partner_id": self.test_loc_partner.id, "owner_id": self.test_loc_partner.id, } ) self.stage = self.env["fsm.stage"].create( { "name": "Stage 1", "sequence": 2, "stage_type": "order", "sub_stage_id": self.stage_id.sub_stage_id.id, } ) def test_fsm_orders(self): """Test creating new workorders, and test following functions.""" # Create an Orders hours_diff = 100 date_start = fields.Datetime.today() order = self.WorkOrder.create( { "location_id": self.test_location.id, "date_start": date_start, "date_end": date_start + timedelta(hours=hours_diff), "request_early": fields.Datetime.today(), } ) order._track_subtype(self.init_values) order._track_subtype({}) self.stage.onchange_sub_stage_id() stage_status_id = self.StageStatus.with_context( fsm_order_stage_id=self.stage_id.id ).create({"name": "Test"}) stage_status_id.search([]) order.stage_id = self.stage.id
38.932203
2,297
990
py
PYTHON
15.0
# Copyright (C) 2019 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class FSMOrder(models.Model): _inherit = "fsm.order" sub_stage_id = fields.Many2one( "fsm.stage.status", string="Sub-Status", required=True, tracking=True, default=lambda self: self._default_stage_id().sub_stage_id, ) def write(self, vals): if "stage_id" in vals: sub_stage_id = ( self.env["fsm.stage"].browse(vals.get("stage_id")).sub_stage_id ) if sub_stage_id: vals.update({"sub_stage_id": sub_stage_id.id}) return super(FSMOrder, self).write(vals) def _track_subtype(self, init_values): self.ensure_one() if "sub_stage_id" in init_values: return self.env.ref("fieldservice_substatus.fso_substatus_changed") return super()._track_subtype(init_values)
31.935484
990
981
py
PYTHON
15.0
# Copyright (C) 2019 - TODAY, Open Source Integrators, Brian McMaster # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models class FSMStageStatus(models.Model): _name = "fsm.stage.status" _description = "Order Sub-Status" name = fields.Char(required=True) @api.model def _search( self, args, offset=0, limit=None, order=None, count=False, access_rights_uid=None, ): context = self._context or {} if context.get("fsm_order_stage_id"): stage_id = self.env["fsm.stage"].browse(context.get("fsm_order_stage_id")) sub_stage_ids = stage_id.sub_stage_id + stage_id.sub_stage_ids if sub_stage_ids: args = [("id", "in", sub_stage_ids.ids)] return super(FSMStageStatus, self)._search( args, offset, limit, order, count=count, access_rights_uid=access_rights_uid )
31.645161
981
866
py
PYTHON
15.0
# Copyright (C) 2019 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models class FSMStage(models.Model): _inherit = "fsm.stage" @api.model def _default_sub_stage(self): return self.env["fsm.stage.status"].search([("name", "=", "Default")]) sub_stage_id = fields.Many2one( "fsm.stage.status", string="Default Sub-Status", store=True, default=_default_sub_stage, ) sub_stage_ids = fields.Many2many( "fsm.stage.status", "fsm_sub_stage_rel", "fsm_stage_id", "sub_stage_id", string="Potential Sub-Statuses", ) @api.onchange("sub_stage_id") def onchange_sub_stage_id(self): if self.sub_stage_id: self.sub_stage_ids = [(6, 0, [self.sub_stage_id.id])]
27.935484
866
788
py
PYTHON
15.0
# Copyright (C) 2019, Open Source Integrators # # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). { "name": "Field Service - Stage Server Action", "summary": "Execute server actions when reaching a Field Service stage", "version": "15.0.1.0.1", "category": "Field Service", "author": "Open Source Integrators, Odoo Community Association (OCA)", "website": "https://github.com/OCA/field-service", "depends": ["fieldservice", "base_automation"], "data": [ "data/ir_server_action.xml", "data/fsm_stage.xml", "data/base_automation.xml", "views/fsm_stage.xml", ], "installable": True, "license": "AGPL-3", "development_status": "Beta", "maintainers": ["wolfhall", "max3903", "osi-scampbell"], }
37.52381
788
280
py
PYTHON
15.0
# Copyright (C) 2019, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class FSMStage(models.Model): _inherit = "fsm.stage" action_id = fields.Many2one("ir.actions.server", string="Server Action")
28
280
711
py
PYTHON
15.0
# Copyright (C) 2018 - TODAY, Brian McMaster # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "Field Service Partner Relations", "summary": "Manage relations between contacts, companies and locations", "version": "15.0.1.0.1", "category": "Field Service", "author": "Open Source Integrators, Odoo Community Association (OCA)", "website": "https://github.com/OCA/field-service", "complexity": "normal", "license": "AGPL-3", "depends": ["partner_multi_relation", "fieldservice"], "data": ["views/fsm_location.xml", "views/menu.xml"], "demo": [ "data/demo.xml", ], "development_status": "Beta", "maintainers": ["max3903"], }
37.421053
711
18,398
py
PYTHON
15.0
# Copyright (C) 2021 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields from odoo.exceptions import ValidationError from odoo.addons.partner_multi_relation.tests.test_partner_relation_common import ( TestPartnerRelationCommon, ) class TestPartnerRelation(TestPartnerRelationCommon): def setUp(self): super(TestPartnerRelation, self).setUp() self.fsm_location_01 = self.partner_model.create( {"name": "Test FSM Location - 1", "fsm_location": True, "ref": "FSM01"} ) self.fsm_location_02 = self.partner_model.create( {"name": "Test FSM Location - 2", "fsm_location": True, "ref": "FSM02"} ) self.fsm_company_03 = self.partner_model.create( {"name": "Test FSM Company - 2", "company_type": "", "ref": "FSM03"} ) self.fsm_person_03 = self.partner_model.create( {"name": "Test FSM Person", "company_type": "person", "ref": "FSM04"} ) self.fsm_location_03 = self.partner_model.create( {"name": "Test FSM Location - 3", "fsm_location": True, "ref": "FSM05"} ) self.fsm_location_obj = self.env["fsm.location"] # Create a new FSM > FSM relation type: ( self.type_fsm_loc2fsm_loc, self.fsm_location2fsm_location, self.selection_fsm_loc3fsm_loc, ) = self._create_relation_type_selection( { "name": "FSM -> FSM", "name_inverse": "FSM <- FSM", "contact_type_left": "fsm-location", "contact_type_right": "fsm-location", } ) # Create a new FSM > Person relation type: ( self.type_fsm_loc2person, self.selection_fsm_loc2person, self.selection_person4fsm_loc, ) = self._create_relation_type_selection( { "name": "FSM -> Person", "name_inverse": "Person <- FSM", "contact_type_left": "fsm-location", "contact_type_right": "p", } ) # Create a new FSM > Person relation type: ( self.type_person2company, self.selection_person2company, self.selection_comapany2person, ) = self._create_relation_type_selection( { "name": "Person -> Company", "name_inverse": "Company <- Person", "contact_type_left": "c", "contact_type_right": "p", } ) def test_validate_fsm_get_cat(self): relation = self.relation_all_model.new( { "this_partner_id": self.fsm_person_03.id, "type_selection_id": self.selection_person2company.id, "other_partner_id": self.fsm_company_03.id, } ) relation.get_cat(self.fsm_person_03) relation.get_cat(self.fsm_company_03) def test_validate_fsm_location_01(self): self.fsm_location = self.fsm_location_obj.create( { "name": "Test FSM Location - 1", "owner_id": self.fsm_location_01.id, } ) self.fsm_location._compute_relation_count() self.fsm_location.action_view_relations() def test_validate_fsm_location_02(self): """Test create overlapping with start / end dates.""" self.fsm_location_01.get_partner_type() relation = self.relation_all_model.create( { "this_partner_id": self.fsm_location_01.id, "type_selection_id": self.fsm_location2fsm_location.id, "other_partner_id": self.fsm_location_02.id, "date_start": fields.Date.today(), "date_end": fields.Date.today(), } ) relation.onchange_this_partner_id() relation.onchange_other_partner_id() relation.onchange_type_selection_id() # New relation with overlapping start / end should give error with self.assertRaises(ValidationError): self.relation_all_model.create( { "this_partner_id": relation.this_partner_id.id, "type_selection_id": relation.type_selection_id.id, "other_partner_id": relation.other_partner_id.id, "date_start": fields.Date.today(), "date_end": fields.Date.today(), } ) def test_validate_fsm_location_03(self): relation = self.relation_all_model.create( { "this_partner_id": self.partner_01_person.id, "type_selection_id": self.fsm_location2fsm_location.id, "other_partner_id": self.fsm_location_02.id, } ) with self.assertRaises(ValidationError): relation.onchange_type_selection_id() def test_validate_fsm_location_04(self): relation = self.relation_all_model.create( { "this_partner_id": self.partner_02_company.id, "type_selection_id": self.selection_fsm_loc2person.id, "other_partner_id": self.fsm_location_02.id, } ) with self.assertRaises(ValidationError): relation.onchange_type_selection_id() def test_validate_fsm_location_05(self): relation = self.relation_all_model.new( { "this_partner_id": self.partner_02_company.id, "type_selection_id": self.selection_fsm_loc2person.id, "other_partner_id": self.partner_01_person.id, } ) with self.assertRaises(ValidationError): relation.onchange_type_selection_id() def test_validate_fsm_location_06(self): relation = self.relation_all_model.new( { "this_partner_id": self.fsm_location_01.id, "type_selection_id": self.fsm_location2fsm_location.id, } ) relation.onchange_type_selection_id() relation.onchange_this_partner_id() def test_validate_fsm_location_07(self): relation = self.relation_all_model.new( { "other_partner_id": self.fsm_location_02.id, "type_selection_id": self.fsm_location2fsm_location.id, } ) relation.onchange_type_selection_id() relation.onchange_other_partner_id() def test_validate_fsm_location_08(self): relation = self.relation_all_model.new( { "type_selection_id": self.fsm_location2fsm_location.id, } ) relation.onchange_type_selection_id() def test_validate_fsm_location_09(self): relation = self.relation_all_model.new( { "this_partner_id": self.fsm_location_02.id, } ) relation.onchange_this_partner_id() relation.onchange_type_selection_id() def test_validate_fsm_location_10(self): relation = self.relation_all_model.new( { "other_partner_id": self.fsm_location_01.id, } ) relation.onchange_other_partner_id() relation.onchange_type_selection_id() def test_validate_fsm_location_11(self): relation = self.relation_all_model.new( { "this_partner_id": self.fsm_location_01.id, "other_partner_id": self.fsm_location_02.id, } ) relation.onchange_this_partner_id() relation.onchange_other_partner_id() def test_validate_fsm_location_12(self): relation = self.relation_all_model.new( { "this_partner_id": self.fsm_person_03.id, "type_selection_id": self.selection_person2company.id, } ) with self.assertRaises(ValidationError): relation.try_type() def test_validate_fsm_location_13(self): relation = self.relation_all_model.new( { "this_partner_id": self.fsm_person_03.id, "type_selection_id": self.selection_person2company.id, "other_partner_id": self.partner_02_company.id, } ) relation.set_domain_left() relation.set_domain_right() def test_validate_fsm_location_14(self): relation = self.relation_all_model.new( { "this_partner_id": self.partner_02_company.id, "type_selection_id": self.selection_person2company.id, "other_partner_id": self.partner_02_company.id, } ) relation.set_domain_left() relation.set_domain_right() def test_validate_fsm_location_15(self): """Test create overlapping with start / end dates.""" self.fsm_location_01.get_partner_type() relation = self.relation_all_model.create( { "this_partner_id": self.fsm_location_03.id, "type_selection_id": self.fsm_location2fsm_location.id, "other_partner_id": self.fsm_location_02.id, "date_start": fields.Date.today(), "date_end": fields.Date.today(), } ) relation.onchange_this_partner_id() relation.onchange_other_partner_id() relation.onchange_type_selection_id() # New relation with overlapping start / end should give error with self.assertRaises(ValidationError): self.relation_all_model.create( { "this_partner_id": relation.this_partner_id.id, "type_selection_id": relation.type_selection_id.id, "other_partner_id": relation.other_partner_id.id, "date_start": fields.Date.today(), "date_end": fields.Date.today(), } ) def test_onchange_type_selection_id(self): relation = self.relation_all_model.new( { "this_partner_id": self.partner_02_company.id, "type_selection_id": self.selection_person2company.id, "other_partner_id": self.partner_02_company.id, } ) relation.onchange_type_selection_id() def test_onchange_type_selection_id_check(self): relation = self.relation_all_model.new( { "this_partner_id": self.partner_02_company.id, "other_partner_id": self.partner_02_company.id, } ) relation.onchange_type_selection_id() def test_try_type_check(self): self.fsm_person_type = self.partner_model.new( {"name": "Test FSM Person - 1", "company_type": "company", "ref": "FSM10"} ) ( self.type_fsm_loc2fsm_loc_test, self.fsm_location2fsm_location_test, self.selection_fsm_loc3fsm_loc_test, ) = self._create_relation_type_selection( { "name": "Person -> Company 1", "name_inverse": "Company <- Person 1", "contact_type_left": "p", "contact_type_right": "c", } ) relation = self.relation_all_model.new( { "this_partner_id": self.fsm_person_type.id, "type_selection_id": self.fsm_location2fsm_location_test.id, } ) with self.assertRaises(ValidationError): relation.try_type() self.fsm_person_type_01 = self.partner_model.new( {"name": "Test FSM Person - 01", "company_type": "company", "ref": "FSM101"} ) ( self.type_fsm_loc2fsm_loc_test, self.fsm_location2fsm_location_test, self.selection_fsm_loc3fsm_loc_test, ) = self._create_relation_type_selection( { "name": "Person -> Company 2", "name_inverse": "Company <- Person 2", "contact_type_left": "p", "contact_type_right": "p", } ) relation = self.relation_all_model.new( { "this_partner_id": self.fsm_person_type_01.id, "type_selection_id": self.fsm_location2fsm_location_test.id, } ) with self.assertRaises(ValidationError): relation.try_type() relation = self.relation_all_model.new( { "this_partner_id": self.fsm_person_type.id, "type_selection_id": self.fsm_location2fsm_location_test.id, } ) with self.assertRaises(ValidationError): relation.try_type() relation = self.relation_all_model.new( { "this_partner_id": self.partner_02_company.id, "type_selection_id": self.selection_person2company.id, } ) with self.assertRaises(ValidationError): relation.try_type() with self.assertRaises(ValidationError): relation = self.relation_all_model.new( { "this_partner_id": self.partner_02_company.id, "type_selection_id": self.selection_person2company.id, "other_partner_id": self.partner_02_company.id, } ) relation.try_type() self.fsm_person_type_02 = self.partner_model.new( {"name": "Test FSM Person - 02", "company_type": "person", "ref": "FSM111"} ) ( self.type_fsm_loc3fsm_loc_test, self.fsm_location3fsm_location_test, self.selection_fsm_loc4fsm_loc_test, ) = self._create_relation_type_selection( { "name": "Person -> Company 3", "name_inverse": "Company <- Person 3", "contact_type_right": "c", } ) with self.assertRaises(ValidationError): relation = self.relation_all_model.new( { "this_partner_id": self.fsm_person_type_02.id, "type_selection_id": self.fsm_location3fsm_location_test.id, "other_partner_id": self.fsm_person_type_02.id, } ) relation.try_type() ( self.type_fsm_loc4fsm_loc_test, self.fsm_location4fsm_location_test, self.selection_fsm_loc5fsm_loc_test, ) = self._create_relation_type_selection( { "name": "Person -> Company 4", "name_inverse": "Company <- Person 4", "contact_type_right": "fsm-location", } ) with self.assertRaises(ValidationError): relation = self.relation_all_model.new( { "this_partner_id": self.fsm_person_type_02.id, "type_selection_id": self.fsm_location4fsm_location_test.id, "other_partner_id": self.fsm_person_type_02.id, } ) relation.try_type() def test_set_domain_left_right_check(self): relation = self.relation_all_model.new( { "this_partner_id": self.partner_02_company.id, } ) relation.set_domain_right() relation.set_domain_left() def test_set_domain_type(self): relation = self.relation_all_model.new( { "this_partner_id": self.partner_02_company.id, "type_selection_id": self.selection_person2company.id, "other_partner_id": self.partner_02_company.id, } ) relation.set_domain_type() def test_build_domain(self): relation = self.relation_all_model.new( { "this_partner_id": self.partner_02_company.id, "type_selection_id": self.selection_person2company.id, "other_partner_id": self.partner_02_company.id, } ) relation.build_domain(1, "c") relation.build_domain(0, "c") relation.build_domain(1, "p") relation.build_domain(0, "p") relation.build_domain(1, "fsm-location") relation.build_domain(0, "fsm-location") def test_get_cat(self): relation = self.relation_all_model.new( { "this_partner_id": self.partner_02_company.id, "type_selection_id": self.selection_person2company.id, "other_partner_id": self.partner_02_company.id, } ) relation.get_cat(self.fsm_location_03) def test_onchange_this_partner_id_check(self): relation = self.relation_all_model.new( { "type_selection_id": self.selection_person2company.id, "other_partner_id": self.partner_02_company.id, } ) relation.onchange_this_partner_id() def test_onchange_other_partner_id_check(self): relation = self.relation_all_model.new( { "this_partner_id": self.partner_02_company.id, "type_selection_id": self.selection_person2company.id, } ) relation.onchange_other_partner_id() def test_onchange_this_partner_id(self): relation = self.relation_all_model.new( { "this_partner_id": self.partner_02_company.id, "type_selection_id": self.selection_person2company.id, "other_partner_id": self.partner_02_company.id, } ) relation.this_partner_id = self.fsm_person_03.id if relation.this_partner_id: relation.onchange_this_partner_id() def test_onchange_other_partner_id(self): relation = self.relation_all_model.new( { "this_partner_id": self.partner_02_company.id, "type_selection_id": self.selection_person2company.id, "other_partner_id": self.partner_02_company.id, } ) if relation.other_partner_id: relation.onchange_other_partner_id()
37.092742
18,398
1,120
py
PYTHON
15.0
# Copyright (C) 2018 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class FSMLocation(models.Model): _inherit = "fsm.location" rel_count = fields.Integer(string="Relations", compute="_compute_relation_count") def _compute_relation_count(self): for location in self: location.rel_count = self.env["res.partner.relation.all"].search_count( [("this_partner_id", "=", location.name)] ) def action_view_relations(self): """ This function returns an action that display existing partner relations of a given fsm location id. """ for location in self: relations = self.env["res.partner.relation.all"].search( [("this_partner_id", "=", location.name)] ) action = self.env["ir.actions.act_window"]._for_xml_id( "partner_multi_relation.action_res_partner_relation_all" ) action["domain"] = [("id", "in", relations.ids)] return action
36.129032
1,120
470
py
PYTHON
15.0
# Copyright (C) 2018 - TODAY, Brian McMaster # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import _, models class ResPartnerRelationType(models.Model): _inherit = "res.partner.relation.type" def get_partner_types(self): super(ResPartnerRelationType, self).get_partner_types() return [ ("c", _("Organisation")), ("p", _("Person")), ("fsm-location", _("FSM Location")), ]
29.375
470
8,588
py
PYTHON
15.0
# Copyright (C) 2019 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import _, api, models from odoo.exceptions import ValidationError class ResPartnerRelationAll(models.AbstractModel): _inherit = "res.partner.relation.all" @api.onchange("this_partner_id") def onchange_this_partner_id(self): if self.this_partner_id: type_id = self.env["res.partner.relation.type"].search( [("name", "=", self.type_selection_id.name)] ) if ( type_id.contact_type_left == "fsm-location" or type_id.contact_type_right == "fsm-location" or self.this_partner_id.fsm_location or self.other_partner_id.fsm_location ): if not self.type_selection_id: return self.set_domain_type() else: super(ResPartnerRelationAll, self).onchange_partner_id() else: # Remove left_cat domain on type return self.set_domain_type() @api.onchange("other_partner_id") def onchange_other_partner_id(self): if self.other_partner_id: type_id = self.env["res.partner.relation.type"].search( [("name", "=", self.type_selection_id.name)] ) if ( type_id.contact_type_left == "fsm-location" or type_id.contact_type_right == "fsm-location" or self.this_partner_id.fsm_location or self.other_partner_id.fsm_location ): if not type_id: return self.set_domain_type() else: super(ResPartnerRelationAll, self).onchange_partner_id() else: # Remove right_cat domain on type self.set_domain_type() @api.onchange("type_selection_id") def onchange_type_selection_id(self): # Clear any prexisting domains if not self.type_selection_id: return { "domain": { "this_partner_id": [("id", "!=", None)], "other_partner_id": [("id", "!=", None)], } } type_id = self.env["res.partner.relation.type"].search( [("name", "=", self.type_selection_id.name)] ) if ( type_id.contact_type_left == "fsm-location" or type_id.contact_type_right == "fsm-location" or self.this_partner_id.fsm_location or self.other_partner_id.fsm_location ): if self.this_partner_id and self.other_partner_id: # Check self.try_type() elif self.this_partner_id: # Set domain Right return self.set_domain_right() elif self.other_partner_id: # Set domain Left return self.set_domain_left() else: res = self.set_domain_left() res2 = self.set_domain_right() res.update(res2["domain"]) return res else: super(ResPartnerRelationAll, self).onchange_type_selection_id() def try_type(self): type_id = self.env["res.partner.relation.type"].search( [("name", "=", self.type_selection_id.name)] ) # From Type left_cat = type_id.contact_type_left right_cat = type_id.contact_type_right # Left Partner left_to_test = self.this_partner_id # Right Partner right_to_test = self.other_partner_id # Compare if left_cat == "p": if left_to_test.company_type != "person": raise ValidationError(_("Left Partner not type Person")) if left_cat == "c": if left_to_test.company_type != "company": raise ValidationError(_("Left Partner not type Company")) if left_cat == "fsm-location": if not left_to_test.fsm_location: raise ValidationError(_("Left Partner not type FSM Location")) if right_cat == "p": if right_to_test.company_type != "person": raise ValidationError(_("Right Partner not type Person")) if right_cat == "c": if right_to_test.company_type != "company": raise ValidationError(_("Right Partner not type Company")) if right_cat == "fsm-location": if not right_to_test.fsm_location: raise ValidationError(_("Right Partner not type FSM Location")) def set_domain_left(self): type_id = self.env["res.partner.relation.type"].search( [("name", "=", self.type_selection_id.name)] ) # From Type res = {} # With a Relation Type if type_id: left_cat = type_id.contact_type_left # Create domain for Left based on Type Left Category res = self.build_domain(1, left_cat) return res # Without a Relation Type else: res = {"domain": {"this_partner_id": ""}} def set_domain_right(self): type_id = self.env["res.partner.relation.type"].search( [("name", "=", self.type_selection_id.name)] ) # From Type res = {} # With a Relation Type if type_id: right_cat = type_id.contact_type_right # Create domain for Right based on Type Right Category res = self.build_domain(0, right_cat) return res # Wtihout a Relation Type else: res = {"domain": {"other_partner_id": ""}} def set_domain_type(self): res = {} # If Left & Right then Type must match both if self.this_partner_id and self.other_partner_id: left_cat = self.get_cat(self.this_partner_id) right_cat = self.get_cat(self.other_partner_id) type_ids = self.env["res.partner.relation.type"].search( [ ("contact_type_left", "=", left_cat), ("contact_type_right", "=", right_cat), ] ) type_names = [] for type_id in type_ids: type_names.append(type_id.name) # From Type res = {"domain": {"type_selection_id": [("name", "in", type_names)]}} # If Left Type must match Left elif self.this_partner_id: left_cat = self.get_cat(self.this_partner_id) type_ids = self.env["res.partner.relation.type"].search( [("contact_type_left", "=", left_cat)] ) type_names = [] for type_id in type_ids: type_names.append(type_id.name) res = {"domain": {"type_selection_id": [("name", "in", type_names)]}} # If Right Type must match Right elif self.other_partner_id: right_cat = self.get_cat(self.other_partner_id) type_ids = self.env["res.partner.relation.type"].search( [("contact_type_right", "=", right_cat)] ) type_names = [] for type_id in type_ids: type_names.append(type_id.name) res = {"domain": {"type_selection_id": [("name", "in", type_names)]}} return res def build_domain(self, side, cat): build = {} if cat == "p": if side: build = { "domain": {"this_partner_id": [("company_type", "=", "person")]} } else: build = { "domain": {"other_partner_id": [("company_type", "=", "person")]} } if cat == "c": if side: build = { "domain": {"this_partner_id": [("company_type", "=", "company")]} } else: build = { "domain": {"other_partner_id": [("company_type", "=", "company")]} } if cat == "fsm-location": if side: build = {"domain": {"this_partner_id": [("fsm_location", "=", True)]}} else: build = {"domain": {"other_partner_id": [("fsm_location", "=", True)]}} return build def get_cat(self, partner): if partner.fsm_location: return "fsm-location" elif partner.company_type == "person": return "p" else: return "c"
38.339286
8,588
564
py
PYTHON
15.0
# Copyright (C) 2018 - TODAY, Brian McMaster # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import models class ResPartner(models.Model): _inherit = "res.partner" def get_partner_type(self): """ Get partner type for relation. :return: 'c' for company or 'p' for person or 'fsm-location' for FSM Location :rtype: str """ self.ensure_one() if self.fsm_location: return "fsm-location" return super(ResPartner, self).get_partner_type()
28.2
564
1,815
py
PYTHON
15.0
# Copyright (C) 2018 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "Field Service", "summary": "Manage Field Service Locations, Workers and Orders", "version": "15.0.1.2.0", "license": "AGPL-3", "category": "Field Service", "author": "Open Source Integrators, Odoo Community Association (OCA)", "website": "https://github.com/OCA/field-service", "depends": ["base_territory", "base_geolocalize", "resource", "contacts"], "data": [ "data/ir_sequence.xml", "data/mail_message_subtype.xml", "data/module_category.xml", "data/fsm_stage.xml", "data/fsm_team.xml", "security/res_groups.xml", "security/ir.model.access.csv", "security/ir_rule.xml", "report/fsm_order_report_template.xml", "views/res_config_settings.xml", "views/res_territory.xml", "views/fsm_stage.xml", "views/fsm_tag.xml", "views/res_partner.xml", "views/fsm_location.xml", "views/fsm_location_person.xml", "views/fsm_person.xml", "views/fsm_order.xml", "views/fsm_order_type.xml", "views/fsm_category.xml", "views/fsm_equipment.xml", "views/fsm_template.xml", "views/fsm_team.xml", "views/fsm_order_type.xml", "views/menu.xml", "wizard/fsm_wizard.xml", ], "demo": [ "demo/fsm_demo.xml", "demo/fsm_equipment.xml", "demo/fsm_location.xml", "demo/fsm_person.xml", ], "application": True, "development_status": "Production/Stable", "maintainers": ["wolfhall", "max3903"], "assets": { "web.assets_backend": [ "fieldservice/static/src/scss/team_dashboard.scss", ] }, }
33.611111
1,815
3,958
py
PYTHON
15.0
# Copyright (C) 2019 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo.exceptions import UserError from odoo.tests.common import TransactionCase class FSMWizard(TransactionCase): """ Test used to check that the base functionalities of Field Service. - test_convert_location: tests that a res.partner can be converted into a fsm.location. - test_convert_person: tests that a res.partner can be converted into a fsm.person. - test_convert_sublocation: tests that the sub-contacts on a res.partner are converted into Other Addresses. """ def setUp(self): super().setUp() self.Wizard = self.env["fsm.wizard"] self.test_partner = self.env.ref("fieldservice.test_partner") self.test_parent_partner = self.env.ref("fieldservice.test_parent_partner") self.test_loc_partner = self.env.ref("fieldservice.test_loc_partner") self.test_location = self.env.ref("fieldservice.test_location") self.test_person = self.env.ref("fieldservice.test_person") def test_convert_location(self): ctx = { "active_model": "res.partner", "active_id": self.test_parent_partner.id, "active_ids": self.test_parent_partner.ids, } ctx1 = { "active_model": "res.partner", "active_id": self.test_loc_partner.id, "active_ids": self.test_loc_partner.ids, } wiz_1 = self.Wizard.with_context(**ctx).create( { "fsm_record_type": "person", } ) wiz_2 = self.Wizard.with_context(**ctx).create( { "fsm_record_type": "location", } ) wiz_3 = self.Wizard.with_context(**ctx1).create( { "fsm_record_type": "location", } ) wiz_1.action_convert() wiz_2.action_convert() with self.assertRaises(UserError): wiz_3.action_convert() # convert test_partner to FSM Location self.Wizard.action_convert_location(self.test_partner) # check if there is a new FSM Location with name 'Test Partner' self.wiz_location = self.env["fsm.location"].search( [("name", "=", "Test Partner")] ) # check if 'Test Partner' creation successful and fields copied over self.assertEqual(self.test_location.phone, self.wiz_location.phone) self.assertEqual(self.test_location.email, self.wiz_location.email) def test_convert_person(self): # convert test_partner to FSM Person ctx2 = { "active_model": "res.partner", "active_id": self.test_partner.id, "active_ids": self.test_partner.ids, } wiz = self.Wizard.with_context(**ctx2).create( { "fsm_record_type": "person", } ) wiz.action_convert() with self.assertRaises(UserError): self.Wizard.action_convert_person(self.test_partner) # check if there is a new FSM Person with name 'Test Partner' self.wiz_person = self.env["fsm.person"].search([("name", "=", "Test Partner")]) # check if 'Test Partner' creation successful and fields copied over self.assertEqual(self.test_person.phone, self.wiz_person.phone) self.assertEqual(self.test_person.email, self.wiz_person.email) def test_convert_sublocation(self): # convert Parent Partner to FSM Location self.Wizard.action_convert_location(self.test_parent_partner) # check if 'Parent Partner' creation successful and fields copied over wiz_parent = self.env["fsm.location"].search([("name", "=", "Parent Partner")]) # check all children were assigned type 'other' for child in wiz_parent.child_ids: self.assertEqual(child.type, "other")
38.427184
3,958
1,688
py
PYTHON
15.0
# Copyright (C) 2019 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields from odoo.tests.common import Form, TransactionCase class FSMTeam(TransactionCase): def setUp(self): super().setUp() self.Order = self.env["fsm.order"] self.Team = self.env["fsm.team"] self.test_location = self.env.ref("fieldservice.test_location") self.test_team = self.Team.create({"name": "Test Team"}) def test_fsm_order(self): """Test creating new workorders - Active orders - Unassigned orders - Unscheduled orders """ # Create 5 Orders, which are, # - 2 assigned (3 unassigned) # - 4 scheduled (1 unscheduled) todo = {"orders": 5, "assigned": [3, 4], "scheduled": [0, 1, 2, 3]} view_id = "fieldservice.fsm_order_form" orders = self.Order for i in range(todo["orders"]): with Form(self.Order, view=view_id) as f: f.location_id = self.test_location f.team_id = self.test_team order = f.save() orders += order order.person_id = ( i in todo["assigned"] and self.env.ref("fieldservice.person_1") or False ) order.scheduled_date_start = ( i in todo["scheduled"] and fields.Datetime.now() or False ) self.assertEqual( ( self.test_team.order_count, self.test_team.order_need_assign_count, self.test_team.order_need_schedule_count, ), (5, 3, 1), )
35.914894
1,688
1,183
py
PYTHON
15.0
# Copyright (C) 2019 Brian McMaster <[email protected]> # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo.exceptions import UserError from . import test_fsm_order class TestFsmCategory(test_fsm_order.TestFSMOrder): def setUp(self): super().setUp() fsm_category = self.env["fsm.category"] self.fsm_category_a = fsm_category.create({"name": "Category A"}) self.fsm_category_b = fsm_category.create( {"name": "Category B", "parent_id": self.fsm_category_a.id} ) self.fsm_category_c = fsm_category.create( {"name": "Category C", "parent_id": self.fsm_category_b.id} ) def test_fsm_order_category(self): self.assertEqual(self.fsm_category_a.full_name, self.fsm_category_a.name) self.assertEqual( self.fsm_category_b.full_name, "%s / %s" % (self.fsm_category_a.name, self.fsm_category_b.name), ) def test_fsm_category_recursion(self): self.assertTrue(self.fsm_category_c._check_recursion()) with self.assertRaises(UserError): self.fsm_category_a.write({"parent_id": self.fsm_category_c.id})
38.16129
1,183
11,380
py
PYTHON
15.0
# Copyright (C) 2019 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo.exceptions import ValidationError from odoo.tests.common import Form, TransactionCase class FSMLocation(TransactionCase): def setUp(self): super().setUp() self.Location = self.env["fsm.location"] self.Equipment = self.env["fsm.equipment"] self.test_location = self.env.ref("fieldservice.test_location") self.location_1 = self.env.ref("fieldservice.location_1") self.location_2 = self.env.ref("fieldservice.location_2") self.location_3 = self.env.ref("fieldservice.location_3") self.test_territory = self.env.ref("base_territory.test_territory") self.test_loc_partner = self.env.ref("fieldservice.test_loc_partner") self.location_partner_1 = self.env.ref("fieldservice.location_partner_1") self.location_partner_2 = self.env.ref("fieldservice.location_partner_2") self.location_partner_3 = self.env.ref("fieldservice.location_partner_3") def test_fsm_location(self): """Test createing new location - Onchange parent, will get all parent info - Default stage - Change stage - Create fsm.location.person if auto_populate_persons_on_location """ # Create an equipment view_id = "fieldservice.fsm_location_form_view" with Form(self.Location, view=view_id) as f: f.name = "Child Location" f.fsm_parent_id = self.test_location location = f.save() # Test child location equal to parent location for x in [ "owner_id", "contact_id", "direction", "street", "street2", "city", "zip", "state_id", "country_id", "tz", "territory_id", ]: self.assertEqual(location[x], self.test_location[x]) # Test initial stage self.assertEqual( location.stage_id, self.env.ref("fieldservice.location_stage_1") ) # Test change state location.next_stage() self.assertEqual( location.stage_id, self.env.ref("fieldservice.location_stage_2") ) location.stage_id = self.env.ref("fieldservice.location_stage_3") location.next_stage() self.assertEqual( location.stage_id, self.env.ref("fieldservice.location_stage_3") ) self.assertFalse(location.hide) # hide as max stage location.stage_id = self.env.ref("fieldservice.location_stage_2") location.previous_stage() self.assertEqual( location.stage_id, self.env.ref("fieldservice.location_stage_1") ) # Test create fsm.location.person, when has if territory has person_ids self.env.company.auto_populate_persons_on_location = True person_ids = [ self.env.ref("fieldservice.person_1").id, self.env.ref("fieldservice.person_2").id, self.env.ref("fieldservice.person_3").id, ] self.test_territory.write({"person_ids": [(6, 0, person_ids)]}) location.territory_id = self.test_territory self.assertEqual(len(location.person_ids), 0) location._onchange_territory_id() self.assertEqual(len(location.person_ids), 3) res = location.owner_id.action_open_owned_locations() self.assertIn(location.id, res["domain"][0][2]) self.location_1.fsm_parent_id = self.test_location self.location_1.ref = "Test Ref" self.location_3.ref = "Test Ref3" self.location_1._compute_complete_name() self.location_2._compute_complete_name() self.location_3._compute_complete_name() self.location_3.geo_localize() loc = self.env["fsm.location"].name_search("Child Location") self.env.user.company_id.search_on_complete_name = True loc = self.env["fsm.location"].name_search("Child Location") self.assertEqual(len(loc), 1, "name_search should have 1 item") self.location_2.state_id = self.env.ref("base.state_au_1").id self.location_2.country_id = self.env.ref("base.af").id self.location_2._onchange_country_id() self.location_1.state_id = self.env.ref("base.state_au_1").id self.location_1._onchange_state() self.assertEqual( self.location_1.country_id.id, self.location_1.state_id.country_id.id ) data = ( self.env["fsm.location"] .with_user(self.env.user) .read_group( [("id", "=", location.id)], fields=["stage_id"], groupby="stage_id" ) ) self.assertTrue(data, "It should be able to read group") def test_fsm_multi_sublocation(self): """Test create location with many sub locations - Test recursion exceptoin - Test count all equipments, contacts, sublocations """ # Test Location > Location 1 > Location 2 > Location 3 self.location_3.fsm_parent_id = self.location_2 self.location_2.fsm_parent_id = self.location_1 self.location_1.fsm_parent_id = self.test_location # Test sublocation_count of each level self.assertEqual( ( self.test_location.sublocation_count, self.location_1.sublocation_count, self.location_2.sublocation_count, self.location_3.sublocation_count, ), (3, 2, 1, 0), ) loc_ids = self.test_location.action_view_sublocation()["domain"][0][2] loc_1_ids = self.location_1.action_view_sublocation()["domain"][0][2] loc_2_ids = [self.location_2.action_view_sublocation()["res_id"]] loc_3_ids = self.location_3.action_view_sublocation()["domain"][0][2] self.assertEqual( (len(loc_ids), len(loc_1_ids), len(loc_2_ids), len(loc_3_ids)), (3, 2, 1, 0) ) # Test recursion exception with self.assertRaises(ValidationError): self.test_location.fsm_parent_id = self.location_3 self.test_location.fsm_parent_id = False # Set back # Add equipments on each locations, and test counting location_vs_num_eq = { self.test_location.id: 1, # Topup = 9 self.location_1.id: 1, # Topup = 8 self.location_2.id: 5, # Topup = 7 self.location_3.id: 1, } # Topup = 2 for loc_id, num_eq in location_vs_num_eq.items(): for i in range(num_eq): self.Equipment.create( { "name": "Eq-{}-{}".format(str(loc_id), str(i + 1)), "location_id": loc_id, "current_location_id": loc_id, } ) # Test valid equipments at each location self.assertEqual( ( self.test_location.equipment_count, self.location_1.equipment_count, self.location_2.equipment_count, self.location_3.equipment_count, ), (8, 7, 6, 1), ) # !! # Test smart button to open equipment loc_eq_ids = self.test_location.action_view_equipment()["domain"][0][2] loc_1_eq_ids = self.location_1.action_view_equipment()["domain"][0][2] loc_2_eq_ids = self.location_2.action_view_equipment()["domain"][0][2] loc_3_eq_ids = self.location_3.action_view_equipment()["res_id"] self.assertEqual( ( len(loc_eq_ids), len(loc_1_eq_ids), len(loc_2_eq_ids), len([loc_3_eq_ids]), ), (8, 7, 6, 1), ) self.test_loc_partner._compute_owned_location_count() # Set service_location_id, on relavant res.partner, test contact count self.test_loc_partner.service_location_id = self.test_location self.location_partner_1.service_location_id = self.location_1 self.location_partner_2.service_location_id = self.location_2 self.location_partner_3.service_location_id = self.location_3 # Test valid contacts at each location self.assertEqual( ( self.test_location.contact_count, self.location_1.contact_count, self.location_2.contact_count, self.location_3.contact_count, ), (4, 3, 2, 1), ) # Test smart button to open contacts cont_ids = self.test_location.action_view_contacts()["domain"][0][2] cont_1_ids = self.location_1.action_view_contacts()["domain"][0][2] cont_2_ids = self.location_2.action_view_contacts()["domain"][0][2] cont_3_ids = [self.location_3.action_view_contacts()["res_id"]] self.assertEqual( (len(cont_ids), len(cont_1_ids), len(cont_2_ids), len(cont_3_ids)), (4, 3, 2, 1), ) def test_convert_partner_to_fsm_location(self): """ FSM Location can be created from the res.partner form like invoice addresses or delivery addresses. child of partner with type = fsm_location """ self.test_partner = self.env.ref("fieldservice.test_partner") # ensure no regression on classic types contact = self.env["res.partner"].create( { "parent_id": self.test_partner.id, "name": "A contact", "type": "contact", } ) self.assertFalse(contact.fsm_location) no_type = self.env["res.partner"].create( { "parent_id": self.test_partner.id, "name": "A contact", } ) self.assertFalse(no_type.fsm_location) # test with type = fsm_location vals = { "parent_id": self.test_partner.id, "name": "A location", "type": "fsm_location", } child_loc = self.env["res.partner"].create(vals) self.assertTrue(child_loc.fsm_location, "fsm_location Flag should be set") self.assertTrue( child_loc.fsm_location_id.exists(), "fsm.location should exists" ) self.assertEqual( child_loc.fsm_location_id.partner_id, child_loc, "ensure circular references", ) def test_convert_partner_to_fsm_location_multi(self): """ Ensure behavior in create_multi """ self.test_partner = self.env.ref("fieldservice.test_partner") vals = [ {"parent_id": self.test_partner.id, "type": "invoice", "name": "contact"}, { "parent_id": self.test_partner.id, "type": "fsm_location", "name": "location", }, ] children_loc = self.env["res.partner"].create(vals) self.assertEqual(len(children_loc.filtered("fsm_location")), 1) # ensure archive is still possible children_loc.action_archive() self.assertTrue( self.env["res.partner"].search( [("active", "=", False), ("id", "in", children_loc.ids)] ) )
41.231884
11,380
2,863
py
PYTHON
15.0
# Copyright (C) 2019 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo.tests.common import Form, TransactionCase class FSMPerson(TransactionCase): def setUp(self): super().setUp() self.Worker = self.env["fsm.person"] def test_fsm_person(self): """Test creating new person - Default stage - Change stage - _search """ # Create a person view_id = "fieldservice.fsm_person_form" with Form(self.Worker, view=view_id) as f: f.name = "Worker A" worker = f.save() location_owner = self.env.ref("fieldservice.location_partner_1") location = self.env["fsm.location"].create( {"name": "test location", "owner_id": location_owner.id} ) parent_partner = self.env.ref("fieldservice.test_parent_partner") sub_p = self.env.ref("fieldservice.s1") sub_p1 = self.env.ref("fieldservice.s2") self.env["fsm.location"].create({"name": "test location", "owner_id": sub_p.id}) parent_partner.action_open_owned_locations() self.env["fsm.location"].create( {"name": "test location", "owner_id": sub_p1.id} ) parent_partner.action_open_owned_locations() self.test_team = self.env["fsm.team"].create({"name": "Test Team"}) person_id = self.env.ref("fieldservice.person_1").id self.env["fsm.location.person"].create( { "location_id": location.id, "person_id": person_id, } ) search_domain = [("location_ids", "=", location.id)] data = ( self.env["fsm.person"] .with_user(self.env.user) .read_group( [("id", "=", location.id)], fields=["stage_id"], groupby="stage_id" ) ) self.assertTrue(data, "It should be able to read group") p1 = self.Worker.search(search_domain) search_domain = [("location_ids", "=", "Test")] self.Worker.search(search_domain) self.assertEqual(p1.id, person_id) # Test change state worker.stage_id = self.env.ref("fieldservice.worker_stage_1") worker.next_stage() self.assertEqual(worker.stage_id, self.env.ref("fieldservice.worker_stage_2")) worker.stage_id = self.env.ref("fieldservice.worker_stage_3") worker.next_stage() self.assertEqual(worker.stage_id, self.env.ref("fieldservice.worker_stage_3")) self.assertFalse(worker.hide) # hide as max stage worker.stage_id = self.env.ref("fieldservice.worker_stage_2") worker.previous_stage() self.assertEqual(worker.stage_id, self.env.ref("fieldservice.worker_stage_1")) # TODO: https://github.com/OCA/field-service/issues/265
41.492754
2,863
2,764
py
PYTHON
15.0
# Copyright (C) 2019 Brian McMaster <[email protected]> # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields from . import test_fsm_order class TestTemplateOnchange(test_fsm_order.TestFSMOrderBase): def setUp(self): super().setUp() self.fsm_category_a = self.env["fsm.category"].create({"name": "Category A"}) self.fsm_category_b = self.env["fsm.category"].create({"name": "Category B"}) self.fsm_type_a = self.env["fsm.order.type"].create( {"name": "FSM Order Type A"} ) self.fsm_team_a = self.env["fsm.team"].create({"name": "FSM Team A"}) def test_fsm_order_onchange_template(self): """Test the onchange function for FSM Template - Category IDs, Scheduled Duration,and Type should update - The copy_notes() method should be called and instructions copied """ categories = [] categories.append(self.fsm_category_a.id) categories.append(self.fsm_category_b.id) self.fsm_template_1 = self.env["fsm.template"].create( { "name": "Test FSM Template #1", "instructions": "<p>These are the instructions for Template #1</p>", "category_ids": [(6, 0, categories)], "duration": 2.25, "type_id": self.fsm_type_a.id, } ) self.fsm_template_2 = self.env["fsm.template"].create( { "name": "Test FSM Template #1", "instructions": "<p>These are the instructions for Template #1</p>", "category_ids": [(6, 0, categories)], "duration": 2.25, "team_id": self.fsm_team_a.id, } ) self.fso = self.Order.create( { "location_id": self.test_location.id, "template_id": self.fsm_template_1.id, "scheduled_date_start": fields.Datetime.today(), } ) self.fso2 = self.Order.create( { "location_id": self.test_location.id, "template_id": self.fsm_template_2.id, "scheduled_date_start": fields.Datetime.today(), } ) self.fso._onchange_template_id() self.fso2._onchange_template_id() self.assertEqual( self.fso.category_ids.ids, self.fsm_template_1.category_ids.ids ) self.assertEqual(self.fso.scheduled_duration, self.fsm_template_1.duration) self.assertEqual(self.fso.type.id, self.fsm_template_1.type_id.id) self.assertEqual(str(self.fso.todo), self.fsm_template_1.instructions) self.assertEqual(self.fso2.team_id.id, self.fsm_team_a.id)
41.878788
2,764
11,356
py
PYTHON
15.0
# Copyright (C) 2019 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from datetime import timedelta from freezegun import freeze_time from odoo import fields from odoo.exceptions import UserError, ValidationError from odoo.tests.common import Form, TransactionCase @freeze_time("2023-02-01") class TestFSMOrderBase(TransactionCase): def setUp(self): super().setUp() self.Order = self.env["fsm.order"] self.test_location = self.env.ref("fieldservice.test_location") self.stage1 = self.env.ref("fieldservice.fsm_stage_completed") self.stage2 = self.env.ref("fieldservice.fsm_stage_cancelled") self.init_values = { "stage_id": self.env.ref("fieldservice.fsm_stage_completed").id } self.init_values_2 = { "stage_id": self.env.ref("fieldservice.fsm_stage_cancelled").id } today = fields.Datetime.today() start_date = today + timedelta(days=1) date_end = start_date.replace(hour=23, minute=59, second=59) self.location_1 = self.env.ref("fieldservice.location_1") self.p_leave = self.env["resource.calendar.leaves"].create( { "date_from": start_date, "date_to": date_end, } ) self.tag = self.env["fsm.tag"].create({"name": "Test Tag"}) self.tag1 = self.env["fsm.tag"].create( {"name": "Test Tag1", "parent_id": self.tag.id} ) def test_fsm_order_default_stage(self): view_id = "fieldservice.fsm_order_form" stage_ids = self.env["fsm.stage"].search( [ ("stage_type", "=", "order"), ("is_default", "=", True), ("company_id", "in", (self.env.user.company_id.id, False)), ], order="sequence asc", ) for stage in stage_ids: stage.unlink() with self.assertRaises(ValidationError): Form(self.Order, view=view_id) def test_fsm_order_default_team(self): view_id = "fieldservice.fsm_order_form" with self.assertRaises(ValidationError): team_ids = self.env["fsm.team"].search( [("company_id", "in", (self.env.user.company_id.id, False))], order="sequence asc", ) for team in team_ids: team.unlink() Form(self.Order, view=view_id) def test_fsm_order_create(self): priority_vs_late_days = {"0": 3, "1": 2, "2": 1, "3": 1 / 3} vals = { "location_id": self.test_location.id, "stage_id": self.stage1.id, } for priority, _late_days in priority_vs_late_days.items(): vals.update({"priority": priority}) self.env["fsm.order"].create(vals) vals2 = { "request_early": fields.Datetime.today(), "location_id": self.test_location.id, "priority": priority, "scheduled_date_start": fields.Datetime.today().replace( hour=0, minute=0, second=0 ), } order_vals = { "request_early": fields.Datetime.today(), "location_id": self.test_location.id, "priority": priority, "scheduled_date_start": fields.Datetime.today().replace( hour=0, minute=0, second=0 ), } self.env["fsm.order"].create(order_vals) order = self.env["fsm.order"].create(vals2) order.write( { "scheduled_date_start": order.request_early.replace( hour=0, minute=0, second=0 ), "scheduled_date_end": order.scheduled_date_start + timedelta(hours=10), } ) with self.assertRaises(ValidationError): order.write( { "scheduled_date_start": order.request_early.replace( hour=0, minute=0, second=0 ), "scheduled_date_end": order.scheduled_date_start + timedelta(hours=100), } ) # report res = ( self.env["ir.actions.report"] ._get_report_from_name("fieldservice.report_fsm_order") ._render_qweb_text(order.ids, False) ) self.assertRegex(str(res[0]), order.name) class TestFSMOrder(TestFSMOrderBase): def test_fsm_order(self): """Test creating new workorders, and test following functions, - _compute_duration() in hrs - _compute_request_late() - Set scheduled_date_start using request_early w/o time - scheduled_date_end = scheduled_date_start + duration (hrs) """ # Create an Orders view_id = "fieldservice.fsm_order_form" hours_diff = 100 with Form(self.Order, view=view_id) as f: f.location_id = self.test_location f.date_start = fields.Datetime.today() f.date_end = f.date_start + timedelta(hours=hours_diff) f.request_early = fields.Datetime.today() order = f.save() with Form(self.Order, view=view_id) as f: f.location_id = self.test_location f.date_start = fields.Datetime.today() f.date_end = f.date_start + timedelta(hours=80) f.request_early = fields.Datetime.today() order2 = f.save() order._get_stage_color() view_id = "fieldservice.fsm_equipment_form_view" with Form(self.env["fsm.equipment"], view=view_id) as f: f.name = "Equipment 1" f.current_location_id = self.test_location f.location_id = self.test_location f.notes = "test" equipment = f.save() order3 = self.Order.create( { "location_id": self.test_location.id, "stage_id": self.stage1.id, } ) order4 = self.Order.create( { "location_id": self.test_location.id, "stage_id": self.stage2.id, } ) self.init_values2 = {} self.tag._compute_full_name() self.tag1._compute_full_name() config = self.env["res.config.settings"].create({}) config.module_fieldservice_repair = True config._onchange_group_fsm_equipment() config._onchange_module_fieldservice_repair() order3._track_subtype(self.init_values) order4._track_subtype(self.init_values) order3._track_subtype(self.init_values_2) order4._track_subtype(self.init_values_2) order4._track_subtype(self.init_values2) order4.action_complete() order3.action_cancel() self.env.user.company_id.auto_populate_equipments_on_order = True order._onchange_location_id_customer() self.assertEqual(order.custom_color, order.stage_id.custom_color) # Test _compute_duration self.assertEqual(order.duration, hours_diff) # Test request_late priority_vs_late_days = {"0": 3, "1": 2, "2": 1, "3": 1 / 3} for priority, late_days in priority_vs_late_days.items(): order_test = self.Order.create( { "location_id": self.test_location.id, "request_early": fields.Datetime.today(), "priority": priority, } ) self.assertEqual( order_test.request_late, order.request_early + timedelta(days=late_days) ) # Test scheduled_date_start is not automatically set self.assertFalse(order.scheduled_date_start) # Test scheduled_date_end = scheduled_date_start + duration (hrs) # Set date start order.scheduled_date_start = fields.Datetime.now().replace( hour=0, minute=0, second=0 ) # Set duration duration = 10 order.scheduled_duration = duration order.onchange_scheduled_duration() # Check date end self.assertEqual( order.scheduled_date_end, fields.Datetime.from_string("2023-02-01 10:00:00") ) # Set new date end order.scheduled_date_end = order.scheduled_date_end.replace( hour=1, minute=1, second=0 ) order.onchange_scheduled_date_end() # Check date start self.assertEqual( order.scheduled_date_start, fields.Datetime.from_string("2023-01-31 15:01:00"), ) view_id = "fieldservice.fsm_location_form_view" with Form(self.env["fsm.location"], view=view_id) as f: f.name = "Child Location" f.fsm_parent_id = self.test_location location = f.save() self.test_team = self.env["fsm.team"].create({"name": "Test Team"}) order_type = self.env["fsm.order.type"].create( {"name": "Test Type", "internal_type": "fsm"} ) order.type = order_type.id stage = self.env["fsm.stage"] stage.get_color_information() with self.assertRaises(ValidationError): self.stage2.custom_color = "ECF0F1" with self.assertRaises(ValidationError): stage.create( { "name": "Test", "stage_type": "order", "sequence": 10, } ) order.description = "description" order.copy_notes() order.description = False order.copy_notes() order.type = False order.equipment_id = equipment.id order.copy_notes() order.type = False order.description = False self.location_1.direction = "Test Direction" order2.location_id.fsm_parent_id = self.location_1.id order.copy_notes() data = ( self.env["fsm.order"] .with_context(**{"default_team_id": self.test_team.id}) .with_user(self.env.user) .read_group( [("id", "=", location.id)], fields=["stage_id"], groupby="stage_id" ) ) self.assertTrue(data, "It should be able to read group") self.Order.write( { "location_id": self.test_location.id, "stage_id": self.stage1.id, "is_button": True, } ) with self.assertRaises(UserError): self.Order.write( { "location_id": self.test_location.id, "stage_id": self.stage1.id, } ) order.can_unlink() order.unlink() def test_order_unlink(self): with self.assertRaises(ValidationError): order = self.Order.create( { "location_id": self.test_location.id, "stage_id": self.stage1.id, } ) order.stage_id.stage_type = "location" order.can_unlink() order.unlink()
38.757679
11,356
2,632
py
PYTHON
15.0
# Copyright (C) 2019 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo.tests.common import Form, TransactionCase class FSMEquipment(TransactionCase): def setUp(self): super().setUp() self.Equipment = self.env["fsm.equipment"] self.test_location = self.env.ref("fieldservice.test_location") self.test_territory = self.env.ref("base_territory.test_territory") self.test_branch = self.env.ref("base_territory.test_branch") self.test_district = self.env.ref("base_territory.test_district") self.test_region = self.env.ref("base_territory.test_region") self.current_location = self.env.ref("fieldservice.location_1") def test_fsm_equipment(self): """Test createing new equipment - Default stage - Onchange location - Change stage """ # Create an equipment view_id = "fieldservice.fsm_equipment_form_view" with Form(self.Equipment, view=view_id) as f: f.name = "Equipment 1" f.current_location_id = self.current_location f.location_id = self.test_location equipment = f.save() # Test onchange location self.assertEqual(self.test_territory, equipment.territory_id) self.assertEqual(self.test_branch, equipment.branch_id) self.assertEqual(self.test_district, equipment.district_id) self.assertEqual(self.test_region, equipment.region_id) # Test initial stage self.assertEqual( equipment.stage_id, self.env.ref("fieldservice.equipment_stage_1") ) # Test change state equipment.next_stage() self.assertEqual( equipment.stage_id, self.env.ref("fieldservice.equipment_stage_2") ) equipment.stage_id = self.env.ref("fieldservice.equipment_stage_3") equipment.next_stage() self.assertEqual( equipment.stage_id, self.env.ref("fieldservice.equipment_stage_3") ) self.assertFalse(equipment.hide) # hide as max stage equipment.stage_id = self.env.ref("fieldservice.equipment_stage_2") equipment.previous_stage() self.assertEqual( equipment.stage_id, self.env.ref("fieldservice.equipment_stage_1") ) data = ( self.env["fsm.equipment"] .with_user(self.env.user) .read_group( [("id", "=", equipment.id)], fields=["stage_id"], groupby="stage_id" ) ) self.assertTrue(data, "It should be able to read group")
41.125
2,632
2,050
py
PYTHON
15.0
# Copyright (C) 2018 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import _, fields, models from odoo.exceptions import UserError class FSMWizard(models.TransientModel): """ A wizard to convert a res.partner record to a fsm.person or fsm.location """ _name = "fsm.wizard" _description = "FSM Record Conversion" fsm_record_type = fields.Selection( [("person", "Worker"), ("location", "Location")], "Record Type" ) def action_convert(self): partners = self.env["res.partner"].browse(self._context.get("active_ids", [])) for partner in partners: if self.fsm_record_type == "person": self.action_convert_person(partner) if self.fsm_record_type == "location": self.action_convert_location(partner) return {"type": "ir.actions.act_window_close"} def _prepare_fsm_location(self, partner): return {"partner_id": partner.id, "owner_id": partner.id} def action_convert_location(self, partner): fl_model = self.env["fsm.location"] if fl_model.search_count([("partner_id", "=", partner.id)]) == 0: fl_model.create(self._prepare_fsm_location(partner)) partner.write({"fsm_location": True}) self.action_other_address(partner) else: raise UserError( _("A Field Service Location related to that" " partner already exists.") ) def action_convert_person(self, partner): fp_model = self.env["fsm.person"] if fp_model.search_count([("partner_id", "=", partner.id)]) == 0: fp_model.create({"partner_id": partner.id}) partner.write({"fsm_person": True}) else: raise UserError( _("A Field Service Worker related to that" " partner already exists.") ) def action_other_address(self, partner): for child in partner.child_ids: child.type = "other"
36.607143
2,050
3,386
py
PYTHON
15.0
# Copyright (C) 2018 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models class FSMPerson(models.Model): _name = "fsm.person" _inherits = {"res.partner": "partner_id"} _inherit = ["mail.thread.blacklist", "fsm.model.mixin"] _description = "Field Service Worker" _stage_type = "worker" partner_id = fields.Many2one( "res.partner", string="Related Partner", required=True, ondelete="restrict", delegate=True, auto_join=True, ) category_ids = fields.Many2many("fsm.category", string="Categories") calendar_id = fields.Many2one("resource.calendar", string="Working Schedule") mobile = fields.Char() territory_ids = fields.Many2many("res.territory", string="Territories") active = fields.Boolean(default=True) active_partner = fields.Boolean( related="partner_id.active", readonly=True, string="Partner is Active" ) def toggle_active(self): for person in self: if not person.active and not person.partner_id.active: person.partner_id.toggle_active() return super().toggle_active() @api.model def _search( self, args, offset=0, limit=None, order=None, count=False, access_rights_uid=None, ): res = super()._search( args=args, offset=offset, limit=limit, order=order, count=count, access_rights_uid=access_rights_uid, ) # Check for args first having location_ids as default filter for arg in args: if isinstance(args, (list)): if arg[0] == "location_ids": # If given int search ID, else search name if isinstance(arg[2], int): self.env.cr.execute( "SELECT person_id " "FROM fsm_location_person " "WHERE location_id=%s", (arg[2],), ) else: arg_2 = "%" + arg[2] + "%" self.env.cr.execute( "SELECT id " "FROM fsm_location " "WHERE complete_name like %s", (arg_2,), ) location_ids = self.env.cr.fetchall() if location_ids: location_ids = [location[0] for location in location_ids] self.env.cr.execute( "SELECT DISTINCT person_id " "FROM fsm_location_person " "WHERE location_id in %s", [tuple(location_ids)], ) workers_ids = self.env.cr.fetchall() if workers_ids: preferred_workers_list = [worker[0] for worker in workers_ids] return preferred_workers_list return res @api.model def create(self, vals): vals.update({"fsm_person": True}) return super().create(vals)
36.408602
3,386
13,331
py
PYTHON
15.0
# Copyright (C) 2018 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import _, api, fields, models from odoo.exceptions import ValidationError class FSMLocation(models.Model): _name = "fsm.location" _inherits = {"res.partner": "partner_id"} _inherit = ["mail.thread", "mail.activity.mixin", "fsm.model.mixin"] _description = "Field Service Location" _stage_type = "location" direction = fields.Char() partner_id = fields.Many2one( "res.partner", string="Related Partner", required=True, ondelete="restrict", delegate=True, auto_join=True, ) owner_id = fields.Many2one( "res.partner", string="Related Owner", required=True, ondelete="restrict", auto_join=True, ) contact_id = fields.Many2one( "res.partner", string="Primary Contact", domain="[('is_company', '=', False)," " ('fsm_location', '=', False)]", index=True, ) description = fields.Char() territory_id = fields.Many2one("res.territory", string="Territory") branch_id = fields.Many2one("res.branch", string="Branch") district_id = fields.Many2one("res.district", string="District") region_id = fields.Many2one("res.region", string="Region") territory_manager_id = fields.Many2one( string="Primary Assignment", related="territory_id.person_id" ) district_manager_id = fields.Many2one( string="District Manager", related="district_id.partner_id" ) region_manager_id = fields.Many2one( string="Region Manager", related="region_id.partner_id" ) branch_manager_id = fields.Many2one( string="Branch Manager", related="branch_id.partner_id" ) calendar_id = fields.Many2one("resource.calendar", string="Office Hours") fsm_parent_id = fields.Many2one("fsm.location", string="Parent", index=True) notes = fields.Text(string="Location Notes") person_ids = fields.One2many("fsm.location.person", "location_id", string="Workers") contact_count = fields.Integer( string="Contacts Count", compute="_compute_contact_ids" ) equipment_count = fields.Integer( string="Equipment", compute="_compute_equipment_ids" ) sublocation_count = fields.Integer( string="Sub Locations", compute="_compute_sublocation_ids" ) complete_name = fields.Char( compute="_compute_complete_name", recursive=True, store=True ) @api.model def create(self, vals): res = super().create(vals) res.update({"fsm_location": True}) return res @api.depends("partner_id.name", "fsm_parent_id.complete_name", "ref") def _compute_complete_name(self): for loc in self: if loc.fsm_parent_id: if loc.ref: loc.complete_name = "{} / [{}] {}".format( loc.fsm_parent_id.complete_name, loc.ref, loc.partner_id.name ) else: loc.complete_name = "{} / {}".format( loc.fsm_parent_id.complete_name, loc.partner_id.name ) else: if loc.ref: loc.complete_name = "[{}] {}".format(loc.ref, loc.partner_id.name) else: loc.complete_name = loc.partner_id.name def name_get(self): results = [] for rec in self: results.append((rec.id, rec.complete_name)) return results @api.model def name_search(self, name, args=None, operator="ilike", limit=100): args = args or [] recs = self.browse() if name: recs = self.search([("ref", "ilike", name)] + args, limit=limit) if not recs and self.env.company.search_on_complete_name: recs = self.search([("complete_name", operator, name)] + args, limit=limit) if not recs and not self.env.company.search_on_complete_name: recs = self.search([("name", operator, name)] + args, limit=limit) return recs.name_get() @api.onchange("fsm_parent_id") def _onchange_fsm_parent_id(self): self.owner_id = self.fsm_parent_id.owner_id or False self.contact_id = self.fsm_parent_id.contact_id or False self.direction = self.fsm_parent_id.direction or False self.street = self.fsm_parent_id.street or False self.street2 = self.fsm_parent_id.street2 or False self.city = self.fsm_parent_id.city or False self.zip = self.fsm_parent_id.zip or False self.state_id = self.fsm_parent_id.state_id or False self.country_id = self.fsm_parent_id.country_id or False self.tz = self.fsm_parent_id.tz or False self.territory_id = self.fsm_parent_id.territory_id or False @api.onchange("territory_id") def _onchange_territory_id(self): self.territory_manager_id = self.territory_id.person_id or False self.branch_id = self.territory_id.branch_id or False if self.env.company.auto_populate_persons_on_location: person_vals_list = [] for person in self.territory_id.person_ids: person_vals_list.append( (0, 0, {"person_id": person.id, "sequence": 10}) ) self.person_ids = self.territory_id and person_vals_list or False @api.onchange("branch_id") def _onchange_branch_id(self): self.branch_manager_id = self.territory_id.branch_id.partner_id or False self.district_id = self.branch_id.district_id or False @api.onchange("district_id") def _onchange_district_id(self): self.district_manager_id = self.branch_id.district_id.partner_id or False self.region_id = self.district_id.region_id or False @api.onchange("region_id") def _onchange_region_id(self): self.region_manager_id = self.region_id.partner_id or False def comp_count(self, contact, equipment, loc): if equipment: for child in loc: child_locs = self.env["fsm.location"].search( [("fsm_parent_id", "=", child.id)] ) equip = self.env["fsm.equipment"].search_count( [("location_id", "=", child.id)] ) if child_locs: for loc in child_locs: equip += loc.comp_count(0, 1, loc) return equip elif contact: for child in loc: child_locs = self.env["fsm.location"].search( [("fsm_parent_id", "=", child.id)] ) con = self.env["res.partner"].search_count( [("service_location_id", "=", child.id)] ) if child_locs: for loc in child_locs: con += loc.comp_count(1, 0, loc) return con else: for child in loc: child_locs = self.env["fsm.location"].search( [("fsm_parent_id", "=", child.id)] ) subloc = self.env["fsm.location"].search_count( [("fsm_parent_id", "=", child.id)] ) if child_locs: for loc in child_locs: subloc += loc.comp_count(0, 0, loc) return subloc def get_action_views(self, contact, equipment, loc): if equipment: for child in loc: child_locs = self.env["fsm.location"].search( [("fsm_parent_id", "=", child.id)] ) equip = self.env["fsm.equipment"].search( [("location_id", "=", child.id)] ) if child_locs: for loc in child_locs: equip += loc.get_action_views(0, 1, loc) return equip elif contact: for child in loc: child_locs = self.env["fsm.location"].search( [("fsm_parent_id", "=", child.id)] ) con = self.env["res.partner"].search( [("service_location_id", "=", child.id)] ) if child_locs: for loc in child_locs: con += loc.get_action_views(1, 0, loc) return con else: for child in loc: child_locs = self.env["fsm.location"].search( [("fsm_parent_id", "=", child.id)] ) subloc = child_locs if child_locs: for loc in child_locs: subloc += loc.get_action_views(0, 0, loc) return subloc def action_view_contacts(self): """ This function returns an action that display existing contacts of given fsm location id and its child locations. It can either be a in a list or in a form view, if there is only one contact to show. """ for location in self: action = self.env["ir.actions.act_window"]._for_xml_id( "contacts.action_contacts" ) contacts = self.get_action_views(1, 0, location) action["context"] = self.env.context.copy() action["context"].update({"group_by": ""}) action["context"].update({"default_service_location_id": self.id}) if len(contacts) == 0 or len(contacts) > 1: action["domain"] = [("id", "in", contacts.ids)] else: action["views"] = [ (self.env.ref("base." + "view_partner_form").id, "form") ] action["res_id"] = contacts.id return action def _compute_contact_ids(self): for loc in self: contacts = self.comp_count(1, 0, loc) loc.contact_count = contacts def action_view_equipment(self): """ This function returns an action that display existing equipment of given fsm location id. It can either be a in a list or in a form view, if there is only one equipment to show. """ for location in self: action = self.env["ir.actions.act_window"]._for_xml_id( "fieldservice.action_fsm_equipment" ) equipment = self.get_action_views(0, 1, location) action["context"] = self.env.context.copy() action["context"].update({"group_by": ""}) action["context"].update({"default_location_id": self.id}) if len(equipment) == 0 or len(equipment) > 1: action["domain"] = [("id", "in", equipment.ids)] else: action["views"] = [ ( self.env.ref("fieldservice." + "fsm_equipment_form_view").id, "form", ) ] action["res_id"] = equipment.id return action def _compute_sublocation_ids(self): for loc in self: loc.sublocation_count = self.comp_count(0, 0, loc) def action_view_sublocation(self): """ This function returns an action that display existing sub-locations of a given fsm location id. It can either be a in a list or in a form view, if there is only one sub-location to show. """ for location in self: action = self.env["ir.actions.act_window"]._for_xml_id( "fieldservice.action_fsm_location" ) sublocation = self.get_action_views(0, 0, location) action["context"] = self.env.context.copy() action["context"].update({"group_by": ""}) action["context"].update({"default_fsm_parent_id": self.id}) if len(sublocation) > 1 or len(sublocation) == 0: action["domain"] = [("id", "in", sublocation.ids)] else: action["views"] = [ ( self.env.ref("fieldservice." + "fsm_location_form_view").id, "form", ) ] action["res_id"] = sublocation.id return action def geo_localize(self): return self.partner_id.geo_localize() def _compute_equipment_ids(self): for loc in self: loc.equipment_count = self.comp_count(0, 1, loc) @api.constrains("fsm_parent_id") def _check_location_recursion(self): if not self._check_recursion(parent="fsm_parent_id"): raise ValidationError(_("You cannot create recursive location.")) return True @api.onchange("country_id") def _onchange_country_id(self): if self.country_id and self.country_id != self.state_id.country_id: self.state_id = False @api.onchange("state_id") def _onchange_state(self): if self.state_id.country_id: self.country_id = self.state_id.country_id class FSMPerson(models.Model): _inherit = "fsm.person" location_ids = fields.One2many( "fsm.location.person", "person_id", string="Linked Locations" )
38.979532
13,331
838
py
PYTHON
15.0
# Copyright (C) 2018 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class FSMTemplate(models.Model): _name = "fsm.template" _description = "Field Service Order Template" name = fields.Char(required=True) instructions = fields.Text() category_ids = fields.Many2many("fsm.category", string="Categories") duration = fields.Float(help="Default duration in hours") company_id = fields.Many2one( "res.company", string="Company", index=True, help="Company related to this template", ) type_id = fields.Many2one("fsm.order.type", string="Type") team_id = fields.Many2one( "fsm.team", string="Team", help="Choose a team to be set on orders of this template", )
32.230769
838
15,882
py
PYTHON
15.0
# Copyright (C) 2018 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from datetime import datetime, timedelta from odoo import _, api, fields, models from odoo.exceptions import UserError, ValidationError from . import fsm_stage class FSMOrder(models.Model): _name = "fsm.order" _description = "Field Service Order" _inherit = ["mail.thread", "mail.activity.mixin"] def _default_stage_id(self): stage = self.env["fsm.stage"].search( [ ("stage_type", "=", "order"), ("is_default", "=", True), ("company_id", "in", (self.env.company.id, False)), ], order="sequence asc", limit=1, ) if stage: return stage raise ValidationError(_("You must create an FSM order stage first.")) def _default_team_id(self): team = self.env["fsm.team"].search( [("company_id", "in", (self.env.company.id, False))], order="sequence asc", limit=1, ) if team: return team raise ValidationError(_("You must create an FSM team first.")) @api.depends("date_start", "date_end") def _compute_duration(self): for rec in self: duration = 0.0 if rec.date_start and rec.date_end: start = fields.Datetime.from_string(rec.date_start) end = fields.Datetime.from_string(rec.date_end) delta = end - start duration = delta.total_seconds() / 3600 rec.duration = duration @api.depends("stage_id") def _get_stage_color(self): """Get stage color""" self.custom_color = self.stage_id.custom_color or "#FFFFFF" def _track_subtype(self, init_values): self.ensure_one() if "stage_id" in init_values: if self.stage_id.id == self.env.ref("fieldservice.fsm_stage_completed").id: return self.env.ref("fieldservice.mt_order_completed") elif ( self.stage_id.id == self.env.ref("fieldservice.fsm_stage_cancelled").id ): return self.env.ref("fieldservice.mt_order_cancelled") return super()._track_subtype(init_values) stage_id = fields.Many2one( "fsm.stage", string="Stage", tracking=True, index=True, copy=False, group_expand="_read_group_stage_ids", default=lambda self: self._default_stage_id(), ) priority = fields.Selection( fsm_stage.AVAILABLE_PRIORITIES, index=True, default=fsm_stage.AVAILABLE_PRIORITIES[0][0], ) tag_ids = fields.Many2many( "fsm.tag", "fsm_order_tag_rel", "fsm_order_id", "tag_id", string="Tags", help="Classify and analyze your orders", ) color = fields.Integer("Color Index", default=0) team_id = fields.Many2one( "fsm.team", string="Team", default=lambda self: self._default_team_id(), index=True, required=True, tracking=True, ) # Request name = fields.Char( required=True, index=True, copy=False, default=lambda self: _("New"), ) location_id = fields.Many2one( "fsm.location", string="Location", index=True, required=True ) location_directions = fields.Char() request_early = fields.Datetime( string="Earliest Request Date", default=datetime.now() ) color = fields.Integer("Color Index") company_id = fields.Many2one( "res.company", string="Company", required=True, index=True, default=lambda self: self.env.company, help="Company related to this order", ) request_late = fields.Datetime(string="Latest Request Date") description = fields.Text() person_ids = fields.Many2many("fsm.person", string="Field Service Workers") @api.onchange("location_id") def _onchange_location_id_customer(self): if self.location_id: self.territory_id = self.location_id.territory_id or False self.branch_id = self.location_id.branch_id or False self.district_id = self.location_id.district_id or False self.region_id = self.location_id.region_id or False self.copy_notes() if self.company_id.auto_populate_equipments_on_order: fsm_equipment_rec = self.env["fsm.equipment"].search( [("current_location_id", "=", self.location_id.id)] ) self.equipment_ids = [(6, 0, fsm_equipment_rec.ids)] # Planning person_id = fields.Many2one("fsm.person", string="Assigned To", index=True) person_phone = fields.Char(related="person_id.phone", string="Worker Phone") scheduled_date_start = fields.Datetime(string="Scheduled Start (ETA)") scheduled_duration = fields.Float(help="Scheduled duration of the work in" " hours") scheduled_date_end = fields.Datetime(string="Scheduled End") sequence = fields.Integer(default=10) todo = fields.Html(string="Instructions") # Execution resolution = fields.Text() date_start = fields.Datetime(string="Actual Start") date_end = fields.Datetime(string="Actual End") duration = fields.Float( string="Actual duration", compute=_compute_duration, help="Actual duration in hours", ) current_date = fields.Datetime(default=fields.Datetime.now, store=True) # Location territory_id = fields.Many2one( "res.territory", string="Territory", related="location_id.territory_id", store=True, ) branch_id = fields.Many2one( "res.branch", string="Branch", related="location_id.branch_id", store=True ) district_id = fields.Many2one( "res.district", string="District", related="location_id.district_id", store=True ) region_id = fields.Many2one( "res.region", string="Region", related="location_id.region_id", store=True ) # Fields for Geoengine Identify display_name = fields.Char(related="name", string="Order") street = fields.Char(related="location_id.street") street2 = fields.Char(related="location_id.street2") zip = fields.Char(related="location_id.zip") city = fields.Char(related="location_id.city") state_name = fields.Char(related="location_id.state_id.name", string="State") country_name = fields.Char(related="location_id.country_id.name", string="Country") phone = fields.Char(related="location_id.phone", string="Location Phone") mobile = fields.Char(related="location_id.mobile") stage_name = fields.Char(related="stage_id.name", string="Stage Name") # Field for Stage Color custom_color = fields.Char(related="stage_id.custom_color", string="Stage Color") # Template template_id = fields.Many2one("fsm.template", string="Template") category_ids = fields.Many2many("fsm.category", string="Categories") # Equipment used for Maintenance and Repair Orders equipment_id = fields.Many2one("fsm.equipment", string="Equipment") # Equipment used for all other Service Orders equipment_ids = fields.Many2many("fsm.equipment", string="Equipments") type = fields.Many2one("fsm.order.type") internal_type = fields.Selection(related="type.internal_type") @api.model def _read_group_stage_ids(self, stages, domain, order): search_domain = [("stage_type", "=", "order")] if self.env.context.get("default_team_id"): search_domain = [ "&", ("team_ids", "in", self.env.context["default_team_id"]), ] + search_domain return stages.search(search_domain, order=order) @api.model def create(self, vals): if vals.get("name", _("New")) == _("New"): vals["name"] = self.env["ir.sequence"].next_by_code("fsm.order") or _("New") self._calc_scheduled_dates(vals) if not vals.get("request_late"): if vals.get("priority") == "0": if vals.get("request_early"): vals["request_late"] = fields.Datetime.from_string( vals.get("request_early") ) + timedelta(days=3) else: vals["request_late"] = datetime.now() + timedelta(days=3) elif vals.get("request_early") and vals.get("priority") == "1": vals["request_late"] = fields.Datetime.from_string( vals.get("request_early") ) + timedelta(days=2) elif vals.get("request_early") and vals.get("priority") == "2": vals["request_late"] = fields.Datetime.from_string( vals.get("request_early") ) + timedelta(days=1) elif vals.get("request_early") and vals.get("priority") == "3": vals["request_late"] = fields.Datetime.from_string( vals.get("request_early") ) + timedelta(hours=8) return super().create(vals) is_button = fields.Boolean(default=False) def write(self, vals): if vals.get("stage_id", False) and vals.get("is_button", False): vals["is_button"] = False else: stage_id = self.env["fsm.stage"].browse(vals.get("stage_id")) if stage_id == self.env.ref("fieldservice.fsm_stage_completed"): raise UserError(_("Cannot move to completed from Kanban")) self._calc_scheduled_dates(vals) res = super().write(vals) return res def can_unlink(self): """:return True if the order can be deleted, False otherwise""" return self.stage_id == self._default_stage_id() def unlink(self): if all(order.can_unlink() for order in self): return super().unlink() raise ValidationError(_("You cannot delete this order.")) def _calc_scheduled_dates(self, vals): """Calculate scheduled dates and duration""" if ( vals.get("scheduled_duration") is not None or vals.get("scheduled_date_start") or vals.get("scheduled_date_end") ): if vals.get("scheduled_date_start") and vals.get("scheduled_date_end"): new_date_start = fields.Datetime.from_string( vals.get("scheduled_date_start", False) ) new_date_end = fields.Datetime.from_string( vals.get("scheduled_date_end", False) ) hours = new_date_end.replace(second=0) - new_date_start.replace( second=0 ) hrs = hours.total_seconds() / 3600 vals["scheduled_duration"] = float(hrs) elif vals.get("scheduled_date_end"): hrs = ( vals.get("scheduled_duration", False) or self.scheduled_duration or 0 ) date_to_with_delta = fields.Datetime.from_string( vals.get("scheduled_date_end", False) ) - timedelta(hours=hrs) vals["scheduled_date_start"] = str(date_to_with_delta) elif ( vals.get("scheduled_duration", False) is not None and vals.get("scheduled_date_start", self.scheduled_date_start) and ( self.scheduled_date_start != vals.get("scheduled_date_start", False) ) ): hours = vals.get("scheduled_duration", False) start_date_val = vals.get( "scheduled_date_start", self.scheduled_date_start ) start_date = fields.Datetime.from_string(start_date_val) date_to_with_delta = start_date + timedelta(hours=hours) vals["scheduled_date_end"] = str(date_to_with_delta) elif vals.get("scheduled_date_start") is not None: vals["scheduled_date_end"] = False def action_complete(self): return self.write( { "stage_id": self.env.ref("fieldservice.fsm_stage_completed").id, "is_button": True, } ) def action_cancel(self): return self.write( {"stage_id": self.env.ref("fieldservice.fsm_stage_cancelled").id} ) @api.onchange("scheduled_date_end") def onchange_scheduled_date_end(self): if self.scheduled_date_end: date_to_with_delta = fields.Datetime.from_string( self.scheduled_date_end ) - timedelta(hours=self.scheduled_duration) self.date_start = str(date_to_with_delta) @api.onchange("scheduled_date_start", "scheduled_duration") def onchange_scheduled_duration(self): if self.scheduled_duration and self.scheduled_date_start: date_to_with_delta = fields.Datetime.from_string( self.scheduled_date_start ) + timedelta(hours=self.scheduled_duration) self.scheduled_date_end = str(date_to_with_delta) else: self.scheduled_date_end = self.scheduled_date_start def copy_notes(self): old_desc = self.description self.location_directions = "" if self.type and self.type.name not in ["repair", "maintenance"]: for equipment_id in self.equipment_ids.filtered(lambda eq: eq.notes): desc = self.description if self.description else "" self.description = desc + equipment_id.notes + "\n " else: if self.equipment_id.notes: desc = self.description if self.description else "" self.description = desc + self.equipment_id.notes + "\n " if self.location_id: self.location_directions = self._get_location_directions(self.location_id) if self.template_id: self.todo = self.template_id.instructions if old_desc: self.description = old_desc @api.onchange("equipment_ids") def onchange_equipment_ids(self): self.copy_notes() @api.onchange("template_id") def _onchange_template_id(self): if self.template_id: self.category_ids = self.template_id.category_ids self.scheduled_duration = self.template_id.duration self.copy_notes() if self.template_id.type_id: self.type = self.template_id.type_id if self.template_id.team_id: self.team_id = self.template_id.team_id def _get_location_directions(self, location_id): self.location_directions = "" s = self.location_id.direction or "" parent_location = self.location_id.fsm_parent_id # ps => Parent Location Directions # s => String to Return while parent_location.id is not False: ps = parent_location.direction if ps: s += parent_location.direction parent_location = parent_location.fsm_parent_id return s @api.constrains("scheduled_date_start") def check_day(self): for rec in self: if rec.scheduled_date_start: holidays = self.env["resource.calendar.leaves"].search( [ ("date_from", ">=", rec.scheduled_date_start), ("date_to", "<=", rec.scheduled_date_end), ] ) if holidays: msg = "{} is a holiday {}".format( rec.scheduled_date_start.date(), holidays[0].name ) raise ValidationError(_(msg))
38.926471
15,882
1,006
py
PYTHON
15.0
# Copyright (C) 2018 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class FSMTag(models.Model): _name = "fsm.tag" _description = "Field Service Tag" name = fields.Char(required=True) parent_id = fields.Many2one("fsm.tag", string="Parent") color = fields.Integer("Color Index", default=10) full_name = fields.Char(compute="_compute_full_name") company_id = fields.Many2one( "res.company", string="Company", required=True, index=True, default=lambda self: self.env.user.company_id, help="Company related to this tag", ) _sql_constraints = [("name_uniq", "unique (name)", "Tag name already exists!")] def _compute_full_name(self): for record in self: record.full_name = ( record.parent_id.name + "/" + record.name if record.parent_id else record.name )
31.4375
1,006
396
py
PYTHON
15.0
# Copyright (C) 2019 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class FSMOrderType(models.Model): _name = "fsm.order.type" _description = "Field Service Order Type" name = fields.Char(required=True) internal_type = fields.Selection( selection=[("fsm", "FSM")], default="fsm", )
24.75
396
1,354
py
PYTHON
15.0
# Copyright (C) 2018 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models class FSMCategory(models.Model): _name = "fsm.category" _description = "Field Service Worker Category" _parent_name = "parent_id" _parent_store = True _rec_name = "full_name" _order = "full_name" name = fields.Char(required="True") full_name = fields.Char(compute="_compute_full_name", store=True, recursive=True) parent_id = fields.Many2one("fsm.category", string="Parent", index=True) parent_path = fields.Char(index=True) child_id = fields.One2many("fsm.category", "parent_id", "Child Categories") color = fields.Integer("Color Index", default=10) description = fields.Char() company_id = fields.Many2one( "res.company", string="Company", required=False, index=True, help="Company related to this category", ) _sql_constraints = [("name_uniq", "unique (name)", "Category name already exists!")] @api.depends("name", "parent_id.full_name") def _compute_full_name(self): for record in self: record.full_name = ( record.parent_id.full_name + " / " + record.name if record.parent_id else record.name )
34.717949
1,354
374
py
PYTHON
15.0
# Copyright (C) 2018 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class ResTerritory(models.Model): _inherit = "res.territory" person_ids = fields.Many2many("fsm.person", string="Field Service Workers") person_id = fields.Many2one("fsm.person", string="Primary Assignment")
34
374
742
py
PYTHON
15.0
# Copyright (C) 2020 Brian McMaster # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class FSMPersonCalendarFilter(models.Model): """Assigned Worker Calendar Filter""" _name = "fsm.person.calendar.filter" _description = "FSM Person Calendar Filter" user_id = fields.Many2one( "res.users", "Me", required=True, default=lambda self: self.env.user ) fsm_person_id = fields.Many2one("fsm.person", "FSM Worker", required=True) active = fields.Boolean(default=True) _sql_constraints = [ ( "user_id_fsm_person_id_unique", "UNIQUE(user_id,fsm_person_id)", "You cannot have the same worker twice.", ) ]
30.916667
742
562
py
PYTHON
15.0
# Copyright (C) 2019 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class ResCompany(models.Model): _inherit = "res.company" auto_populate_persons_on_location = fields.Boolean( string="Auto-populate Workers on Location based on Territory" ) auto_populate_equipments_on_order = fields.Boolean( string="Auto-populate Equipments on Order based on Location" ) search_on_complete_name = fields.Boolean(string="Search Location By Hierarchy")
35.125
562
1,071
py
PYTHON
15.0
# Copyright (C) 2018 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class FSMLocationPerson(models.Model): _name = "fsm.location.person" _description = "Field Service Location Person Info" _rec_name = "location_id" _order = "sequence" location_id = fields.Many2one( "fsm.location", string="Location", required=True, index=True ) person_id = fields.Many2one( "fsm.person", string="Worker", required=True, index=True ) sequence = fields.Integer(required=True, default="10") phone = fields.Char(related="person_id.phone") email = fields.Char(related="person_id.email") owner_id = fields.Many2one(related="location_id.owner_id", string="Owner") contact_id = fields.Many2one(related="location_id.contact_id", string="Contact") _sql_constraints = [ ( "location_person_uniq", "unique(location_id,person_id)", "The worker is already linked to this location.", ) ]
34.548387
1,071
4,241
py
PYTHON
15.0
# Copyright (C) 2018 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models class ResConfigSettings(models.TransientModel): _inherit = "res.config.settings" # Groups group_fsm_team = fields.Boolean( string="Manage Teams", implied_group="fieldservice.group_fsm_team" ) group_fsm_category = fields.Boolean( string="Manage Categories", implied_group="fieldservice.group_fsm_category" ) group_fsm_tag = fields.Boolean( string="Manage Tags", implied_group="fieldservice.group_fsm_tag" ) group_fsm_equipment = fields.Boolean( string="Manage Equipment", implied_group="fieldservice.group_fsm_equipment" ) group_fsm_template = fields.Boolean( string="Manage Template", implied_group="fieldservice.group_fsm_template" ) # Modules module_fieldservice_account = fields.Boolean(string="Invoice your FSM orders") module_fieldservice_activity = fields.Boolean(string="Manage FSM Activities") module_fieldservice_agreement = fields.Boolean(string="Manage Agreements") module_fieldservice_change_management = fields.Boolean(string="Change Management") module_fieldservice_crm = fields.Boolean(string="CRM") module_fieldservice_distribution = fields.Boolean(string="Manage Distribution") module_fieldservice_fleet = fields.Boolean( string="Link FSM vehicles to Fleet vehicles" ) module_fieldservice_geoengine = fields.Boolean(string="Use GeoEngine") module_fieldservice_google_map = fields.Boolean( string="Allow Field Service Google Map" ) module_fieldservice_location_builder = fields.Boolean( string="Use FSM Location Builder" ) module_fieldservice_maintenance = fields.Boolean( string="Link FSM orders to maintenance requests" ) module_fieldservice_project = fields.Boolean(string="Projects and Tasks") module_fieldservice_purchase = fields.Boolean( string="Manage subcontractors and their pricelists" ) module_fieldservice_recurring = fields.Boolean(string="Manage Recurring Orders") module_fieldservice_repair = fields.Boolean( string="Link FSM orders to MRP Repair orders" ) module_fieldservice_route = fields.Boolean(string="Manage routes") module_fieldservice_route_account = fields.Boolean( string="Check the amount collected during the route" ) module_fieldservice_route_stock = fields.Boolean( string="Check the inventory of the vehicle at the end of the route" ) module_fieldservice_sale = fields.Boolean(string="Sell FSM orders") module_fieldservice_size = fields.Boolean( string="Manage sizes for orders and locations" ) module_fieldservice_skill = fields.Boolean(string="Manage Skills") module_fieldservice_stock = fields.Boolean(string="Use Odoo Logistics") module_fieldservice_vehicle = fields.Boolean(string="Manage Vehicles") module_fieldservice_substatus = fields.Boolean(string="Manage Sub-Statuses") module_fieldservice_web_timeline_view = fields.Boolean( string="Allow Field Service Web Timeline View" ) # Companies auto_populate_persons_on_location = fields.Boolean( string="Auto-populate Workers on Location based on Territory", related="company_id.auto_populate_persons_on_location", readonly=False, ) auto_populate_equipments_on_order = fields.Boolean( string="Auto-populate equipments on Order based on the Location", related="company_id.auto_populate_equipments_on_order", readonly=False, ) search_on_complete_name = fields.Boolean( string="Search Location By Hierarchy", related="company_id.search_on_complete_name", readonly=False, ) # Dependencies @api.onchange("group_fsm_equipment") def _onchange_group_fsm_equipment(self): if not self.group_fsm_equipment: self.auto_populate_equipments_on_order = False @api.onchange("module_fieldservice_repair") def _onchange_module_fieldservice_repair(self): if self.module_fieldservice_repair: self.group_fsm_equipment = True
42.41
4,241
3,069
py
PYTHON
15.0
# Copyright (C) 2018 Brian McMaster # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class FSMTeam(models.Model): _name = "fsm.team" _description = "Field Service Team" _inherit = ["mail.thread", "mail.activity.mixin"] def _default_stages(self): return self.env["fsm.stage"].search([("is_default", "=", True)]) def _compute_order_count(self): order_data = self.env["fsm.order"].read_group( [("team_id", "in", self.ids), ("stage_id.is_closed", "=", False)], ["team_id"], ["team_id"], ) result = {data["team_id"][0]: int(data["team_id_count"]) for data in order_data} for team in self: team.order_count = result.get(team.id, 0) def _compute_order_need_assign_count(self): order_data = self.env["fsm.order"].read_group( [ ("team_id", "in", self.ids), ("person_id", "=", False), ("stage_id.is_closed", "=", False), ], ["team_id"], ["team_id"], ) result = {data["team_id"][0]: int(data["team_id_count"]) for data in order_data} for team in self: team.order_need_assign_count = result.get(team.id, 0) def _compute_order_need_schedule_count(self): order_data = self.env["fsm.order"].read_group( [ ("team_id", "in", self.ids), ("scheduled_date_start", "=", False), ("stage_id.is_closed", "=", False), ], ["team_id"], ["team_id"], ) result = {data["team_id"][0]: int(data["team_id_count"]) for data in order_data} for team in self: team.order_need_schedule_count = result.get(team.id, 0) name = fields.Char(required=True, translate=True) description = fields.Text(translate=True) color = fields.Integer("Color Index") stage_ids = fields.Many2many( "fsm.stage", "order_team_stage_rel", "team_id", "stage_id", string="Stages", default=_default_stages, ) order_ids = fields.One2many( "fsm.order", "team_id", string="Orders", domain=[("stage_id.is_closed", "=", False)], ) order_count = fields.Integer(compute="_compute_order_count", string="Orders Count") order_need_assign_count = fields.Integer( compute="_compute_order_need_assign_count", string="Orders to Assign" ) order_need_schedule_count = fields.Integer( compute="_compute_order_need_schedule_count", string="Orders to Schedule" ) sequence = fields.Integer(default=1, help="Used to sort teams. Lower is better.") company_id = fields.Many2one( "res.company", string="Company", required=True, index=True, default=lambda self: self.env.company, help="Company related to this team", ) _sql_constraints = [("name_uniq", "unique (name)", "Team name already exists!")]
35.275862
3,069
2,101
py
PYTHON
15.0
# Copyright (C) 2018 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models class FSMEquipment(models.Model): _name = "fsm.equipment" _description = "Field Service Equipment" _inherit = ["mail.thread", "mail.activity.mixin", "fsm.model.mixin"] _stage_type = "equipment" name = fields.Char(required="True") person_id = fields.Many2one("fsm.person", string="Assigned Operator") location_id = fields.Many2one("fsm.location", string="Assigned Location") notes = fields.Text() territory_id = fields.Many2one("res.territory", string="Territory") branch_id = fields.Many2one("res.branch", string="Branch") district_id = fields.Many2one("res.district", string="District") region_id = fields.Many2one("res.region", string="Region") current_location_id = fields.Many2one("fsm.location", string="Current Location") managed_by_id = fields.Many2one("res.partner", string="Managed By") owned_by_id = fields.Many2one("res.partner", string="Owned By") parent_id = fields.Many2one("fsm.equipment", string="Parent") child_ids = fields.One2many("fsm.equipment", "parent_id", string="Children") color = fields.Integer("Color Index") company_id = fields.Many2one( "res.company", string="Company", required=True, index=True, default=lambda self: self.env.company, help="Company related to this equipment", ) _sql_constraints = [ ("name_uniq", "unique (name)", "Equipment name already exists!") ] @api.onchange("location_id") def _onchange_location_id(self): self.territory_id = self.location_id.territory_id @api.onchange("territory_id") def _onchange_territory_id(self): self.branch_id = self.territory_id.branch_id @api.onchange("branch_id") def _onchange_branch_id(self): self.district_id = self.branch_id.district_id @api.onchange("district_id") def _onchange_district_id(self): self.region_id = self.district_id.region_id
38.907407
2,101
3,507
py
PYTHON
15.0
# Copyright (C) 2018 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import _, api, fields, models from odoo.exceptions import ValidationError AVAILABLE_PRIORITIES = [("0", "Normal"), ("1", "Low"), ("2", "High"), ("3", "Urgent")] class FSMStage(models.Model): _name = "fsm.stage" _description = "Field Service Stage" _order = "sequence, name, id" def _default_team_ids(self): default_team_id = self.env.context.get("default_team_id") return [default_team_id] if default_team_id else None active = fields.Boolean(default=True) name = fields.Char(required=True) sequence = fields.Integer(default=1, help="Used to order stages. Lower is better.") legend_priority = fields.Text( "Priority Management Explanation", translate=True, help="Explanation text to help users using" " the star and priority mechanism on" " stages or orders that are in this" " stage.", ) fold = fields.Boolean( "Folded in Kanban", help="This stage is folded in the kanban view when " "there are no record in that stage to display.", ) is_closed = fields.Boolean( "Is a close stage", help="Services in this stage are considered " "as closed." ) is_default = fields.Boolean("Is a default stage", help="Used a default stage") custom_color = fields.Char( "Color Code", default="#FFFFFF", help="Use Hex Code only Ex:-#FFFFFF" ) description = fields.Text(translate=True) stage_type = fields.Selection( [ ("order", "Order"), ("equipment", "Equipment"), ("location", "Location"), ("worker", "Worker"), ], "Type", required=True, ) company_id = fields.Many2one( "res.company", string="Company", default=lambda self: self.env.user.company_id.id, ) team_ids = fields.Many2many( "fsm.team", "order_team_stage_rel", "stage_id", "team_id", string="Teams", default=lambda self: self._default_team_ids(), ) def get_color_information(self): # get stage ids stage_ids = self.search([]) color_information_dict = [] for stage in stage_ids: color_information_dict.append( { "color": stage.custom_color, "field": "stage_id", "opt": "==", "value": stage.name, } ) return color_information_dict @api.model def create(self, vals): stages = self.search([]) for stage in stages: if ( stage.stage_type == vals["stage_type"] and stage.sequence == vals["sequence"] ): raise ValidationError( _( "Cannot create FSM Stage because " "it has the same Type and Sequence " "of an existing FSM Stage." ) ) return super().create(vals) @api.constrains("custom_color") def _check_custom_color_hex_code(self): if ( self.custom_color and not self.custom_color.startswith("#") or len(self.custom_color) != 7 ): raise ValidationError(_("Color code should be Hex Code. Ex:-#FFFFFF"))
33.084906
3,507
2,618
py
PYTHON
15.0
# Copyright (C) 2018 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class ResPartner(models.Model): _inherit = "res.partner" type = fields.Selection(selection_add=[("fsm_location", "Location")]) fsm_location = fields.Boolean("Is a FS Location") fsm_person = fields.Boolean("Is a FS Worker") fsm_location_id = fields.One2many( comodel_name="fsm.location", string="Related FS Location", inverse_name="partner_id", readonly=1, limit=1, ) service_location_id = fields.Many2one( "fsm.location", string="Primary Service Location" ) owned_location_ids = fields.One2many( "fsm.location", "owner_id", string="Owned Locations", domain=[("fsm_parent_id", "=", False)], ) owned_location_count = fields.Integer( compute="_compute_owned_location_count", string="# of Owned Locations" ) def _compute_owned_location_count(self): for partner in self: partner.owned_location_count = self.env["fsm.location"].search_count( [("owner_id", "child_of", partner.id)] ) def action_open_owned_locations(self): for partner in self: owned_location_ids = self.env["fsm.location"].search( [("owner_id", "child_of", partner.id)] ) action = self.env.ref("fieldservice.action_fsm_location").sudo().read()[0] action["context"] = {} if len(owned_location_ids) > 1: action["domain"] = [("id", "in", owned_location_ids.ids)] elif len(owned_location_ids) == 1: action["views"] = [ (self.env.ref("fieldservice.fsm_location_form_view").id, "form") ] action["res_id"] = owned_location_ids.ids[0] return action def _convert_fsm_location(self): wiz = self.env["fsm.wizard"] partners_with_loc_ids = ( self.env["fsm.location"] .sudo() .search([("active", "in", [False, True]), ("partner_id", "in", self.ids)]) .mapped("partner_id") ).ids partners_to_convert = self.filtered( lambda p: p.type == "fsm_location" and p.id not in partners_with_loc_ids ) for partner_to_convert in partners_to_convert: wiz.action_convert_location(partner_to_convert) def write(self, value): res = super().write(value) self._convert_fsm_location() return res
35.863014
2,618
1,737
py
PYTHON
15.0
# Copyright 2022 Tecnativa - Víctor Martínez # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models class FsmModelMixin(models.AbstractModel): _name = "fsm.model.mixin" _description = "Fsm Model Mixin" _stage_type = "" stage_id = fields.Many2one( "fsm.stage", string="Stage", tracking=True, index=True, copy=False, group_expand="_read_group_stage_ids", default=lambda self: self._default_stage_id(), ) hide = fields.Boolean() @api.model def _read_group_stage_ids(self, stages, domain, order): return self.env["fsm.stage"].search([("stage_type", "=", self._stage_type)]) def _default_stage_id(self): return self.env["fsm.stage"].search( [("stage_type", "=", self._stage_type)], limit=1 ) def new_stage(self, operator): seq = self.stage_id.sequence order_by = "asc" if operator == ">" else "desc" new_stage = self.env["fsm.stage"].search( [("stage_type", "=", self._stage_type), ("sequence", operator, seq)], order="sequence %s" % order_by, limit=1, ) if new_stage: self.stage_id = new_stage self._onchange_stage_id() def next_stage(self): self.new_stage(">") def previous_stage(self): self.new_stage("<") @api.onchange("stage_id") def _onchange_stage_id(self): # get last stage heighest_stage = self.env["fsm.stage"].search( [("stage_type", "=", self._stage_type)], order="sequence desc", limit=1 ) self.hide = True if self.stage_id.name == heighest_stage.name else False
30.982143
1,735
947
py
PYTHON
15.0
# Copyright (C) 2020 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "Base Territory", "summary": "This module allows you to define territories, branches," " districts and regions to be used for Field Service operations or Sales.", "version": "15.0.1.0.0", "category": "Hidden", "author": "Open Source Integrators, Odoo Community Association (OCA)", "website": "https://github.com/OCA/field-service", "depends": ["base"], "data": [ "security/ir.model.access.csv", "views/res_territory.xml", "views/res_branch.xml", "views/res_district.xml", "views/res_region.xml", "views/res_country.xml", "views/menu.xml", ], "demo": ["demo/base_territory_demo.xml"], "application": True, "license": "AGPL-3", "development_status": "Production/Stable", "maintainers": ["wolfhall", "max3903"], }
35.074074
947
443
py
PYTHON
15.0
# Copyright (C) 2020 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class ResDistrict(models.Model): _name = "res.district" _description = "District" name = fields.Char(required=True) region_id = fields.Many2one("res.region", string="Region") partner_id = fields.Many2one("res.partner", string="District Manager") description = fields.Char()
31.642857
443
443
py
PYTHON
15.0
# Copyright (C) 2020 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class ResCountry(models.Model): _inherit = "res.country" territory_id = fields.Many2one("res.territory", string="Territory") region_ids = fields.Many2many( "res.region", "res_country_region_rel", "country_id", "region_id", string="Regions", )
27.6875
443
798
py
PYTHON
15.0
# Copyright (C) 2020 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class ResTerritory(models.Model): _name = "res.territory" _description = "Territory" name = fields.Char(required=True) branch_id = fields.Many2one("res.branch", string="Branch") district_id = fields.Many2one(related="branch_id.district_id", string="District") region_id = fields.Many2one( related="branch_id.district_id.region_id", string="Region" ) description = fields.Char() type = fields.Selection( [("zip", "Zip"), ("state", "State"), ("country", "Country")], ) zip_codes = fields.Char("ZIP Codes") country_ids = fields.One2many("res.country", "territory_id", string="Country Names")
36.272727
798
441
py
PYTHON
15.0
# Copyright (C) 2020 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class ResBranch(models.Model): _name = "res.branch" _description = "branch" name = fields.Char(required=True) partner_id = fields.Many2one("res.partner", string="Branch Manager") district_id = fields.Many2one("res.district", string="District") description = fields.Char()
31.5
441
372
py
PYTHON
15.0
# Copyright (C) 2020 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class ResRegion(models.Model): _name = "res.region" _description = "Region" name = fields.Char(required=True) description = fields.Char() partner_id = fields.Many2one("res.partner", string="Region Manager")
28.615385
372
702
py
PYTHON
15.0
# Copyright (C) 2019, Patrick Wilson # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "Field Service - CRM", "version": "15.0.1.0.0", "summary": "Create Field Service orders from the CRM", "category": "Field Service", "author": "Patrick Wilson, Odoo Community Association (OCA)", "website": "https://github.com/OCA/field-service", "depends": ["fieldservice", "crm"], "data": [ "views/crm_lead.xml", "views/fsm_location.xml", "views/fsm_order.xml", "security/ir.model.access.csv", ], "license": "AGPL-3", "development_status": "Beta", "maintainers": ["patrickrwilson"], "installable": True, }
31.909091
702
914
py
PYTHON
15.0
from odoo.tests import common class TestFieldserviceCrm(common.TransactionCase): def test_fieldservicecrm(self): location_1 = self.env["fsm.location"].create( { "name": "Summer's House", "owner_id": self.env["res.partner"] .create({"name": "Summer's Parents"}) .id, } ) crm_1 = self.env["crm.lead"].create( { "name": "Test CRM", "fsm_location_id": location_1.id, } ) self.env["fsm.order"].create( { "location_id": location_1.id, "opportunity_id": crm_1.id, } ) crm_1._compute_fsm_order_count() self.assertEqual(crm_1.fsm_order_count, 1) location_1._compute_opportunity_count() self.assertEqual(location_1.opportunity_count, 1)
30.466667
914
548
py
PYTHON
15.0
# Copyright (C) 2019, Patrick Wilson # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class FSMLocation(models.Model): _inherit = "fsm.location" opportunity_count = fields.Integer( compute="_compute_opportunity_count", string="# Opportunities" ) def _compute_opportunity_count(self): for fsm_location in self: fsm_location.opportunity_count = self.env["crm.lead"].search_count( [("fsm_location_id", "=", fsm_location.id)] )
30.444444
548
280
py
PYTHON
15.0
# Copyright (C) 2019, Patrick Wilson # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class FSMOrder(models.Model): _inherit = "fsm.order" opportunity_id = fields.Many2one("crm.lead", string="Opportunity", tracking=True)
28
280
706
py
PYTHON
15.0
# Copyright (C) 2019, Patrick Wilson # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class Lead(models.Model): _inherit = "crm.lead" fsm_order_ids = fields.One2many( "fsm.order", "opportunity_id", string="Service Orders" ) fsm_location_id = fields.Many2one("fsm.location", string="FSM Location") fsm_order_count = fields.Integer( compute="_compute_fsm_order_count", string="# FSM Orders" ) def _compute_fsm_order_count(self): for opportunity in self: opportunity.fsm_order_count = self.env["fsm.order"].search_count( [("opportunity_id", "=", opportunity.id)] )
32.090909
706
856
py
PYTHON
15.0
# Copyright (C) 2018 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "Field Service - Sales - Recurring", "version": "15.0.2.0.0", "summary": "Sell recurring field services.", "category": "Field Service", "author": "Open Source Integrators, Odoo Community Association (OCA)", "website": "https://github.com/OCA/field-service", "depends": [ "fieldservice_recurring", "fieldservice_sale", ], "data": [ "security/ir.model.access.csv", "views/fsm_recurring.xml", "views/product_template.xml", "views/sale_order.xml", ], "license": "AGPL-3", "development_status": "Beta", "maintainers": [ "wolfhall", "max3903", "brian10048", ], "installable": True, "auto_install": True, }
28.533333
856
6,990
py
PYTHON
15.0
# Copyright (C) 2019 Brian McMaster <[email protected]> # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo.addons.fieldservice_sale.tests.test_fsm_sale_order import TestFSMSale class TestFSMSaleRecurring(TestFSMSale): @classmethod def setUpClass(cls): super(TestFSMSaleRecurring, cls).setUpClass() cls.test_location = cls.env.ref("fieldservice.test_location") # Setup products that when sold will create some FSM orders cls.setUpFSMProducts() cls.partner_customer_usd = cls.env["res.partner"].create( { "name": "partner_a", "company_id": False, } ) cls.pricelist_usd = cls.env["product.pricelist"].search( [("currency_id.name", "=", "USD")], limit=1 ) SaleOrder = cls.env["sale.order"].with_context(tracking_disable=True) cls.sale_order_recur = SaleOrder.create( { "partner_id": cls.partner_customer_usd.id, "fsm_location_id": cls.test_location.id, "pricelist_id": cls.pricelist_usd.id, } ) cls.sale_order_recur2 = SaleOrder.create( { "partner_id": cls.partner_customer_usd.id, "fsm_location_id": cls.test_location.id, "pricelist_id": cls.pricelist_usd.id, } ) cls.sale_order = SaleOrder.create( { "partner_id": cls.partner_customer_usd.id, "fsm_location_id": cls.test_location.id, "pricelist_id": cls.pricelist_usd.id, } ) # Product that creates FSM Recurring Order cls.product_fsm_recur = cls.env["product.product"].create( { "name": "FSM Recurring Order Product", "categ_id": cls.env.ref("product.product_category_3").id, "standard_price": 425.0, "list_price": 500.0, "type": "service", "uom_id": cls.env.ref("uom.product_uom_unit").id, "uom_po_id": cls.env.ref("uom.product_uom_unit").id, "invoice_policy": "order", "field_service_tracking": "recurring", "fsm_recurring_template_id": cls.env.ref( "fieldservice_recurring.recur_template_weekdays" ).id, } ) cls.product_fsm_recur2 = cls.env["product.product"].create( { "name": "FSM Recurring Order Product Test", "categ_id": cls.env.ref("product.product_category_3").id, "standard_price": 425.0, "list_price": 500.0, "type": "service", "uom_id": cls.env.ref("uom.product_uom_unit").id, "uom_po_id": cls.env.ref("uom.product_uom_unit").id, "invoice_policy": "order", "field_service_tracking": "recurring", "fsm_recurring_template_id": cls.env.ref( "fieldservice_recurring.recur_template_weekdays" ).id, } ) cls.product_fsm = cls.env["product.product"].create( { "name": "FSM Order Product", "categ_id": cls.env.ref("product.product_category_3").id, "standard_price": 425.0, "list_price": 500.0, "type": "service", "uom_id": cls.env.ref("uom.product_uom_unit").id, "uom_po_id": cls.env.ref("uom.product_uom_unit").id, "invoice_policy": "order", "field_service_tracking": "no", } ) cls.sale_line_recurring = cls.env["sale.order.line"].create( { "name": cls.product_fsm_recur.name, "product_id": cls.product_fsm_recur.id, "product_uom_qty": 1, "product_uom": cls.product_fsm_recur.uom_id.id, "price_unit": cls.product_fsm_recur.list_price, "order_id": cls.sale_order_recur.id, "tax_id": False, } ) cls.sale_line_recurring2 = cls.env["sale.order.line"].create( { "name": cls.product_fsm_recur2.name, "product_id": cls.product_fsm_recur2.id, "product_uom_qty": 1, "product_uom": cls.product_fsm_recur2.uom_id.id, "price_unit": cls.product_fsm_recur2.list_price, "order_id": cls.sale_order_recur2.id, "tax_id": False, } ) cls.sale_line_recurring3 = cls.env["sale.order.line"].create( { "name": cls.product_fsm_recur.name, "product_id": cls.product_fsm_recur.id, "product_uom_qty": 1, "product_uom": cls.product_fsm_recur.uom_id.id, "price_unit": cls.product_fsm_recur.list_price, "order_id": cls.sale_order_recur2.id, "tax_id": False, } ) cls.sale_line_recurring4 = cls.env["sale.order.line"].create( { "name": cls.product_fsm.name, "product_id": cls.product_fsm.id, "product_uom_qty": 1, "product_uom": cls.product_fsm.uom_id.id, "price_unit": cls.product_fsm.list_price, "order_id": cls.sale_order.id, "tax_id": False, } ) def test_fsm_sale_order_recurring(self): """Test the flow for a Sale Order that will generate FSM Recurring Orders. """ sol_recur = self.sale_line_recurring # Confirm the sale order that was setup self.sale_order_recur.action_confirm() self.sale_order_recur2.action_confirm() self.sale_order.action_confirm() # FSM Recurring Order linked to Sale Order Line count_recurring = self.env["fsm.recurring"].search_count( [("id", "=", sol_recur.fsm_recurring_id.id)] ) self.assertEqual( count_recurring, 1, """FSM Sale Recurring: Recurring Order should be linked to the Sale Order Line""", ) sol_recur.fsm_recurring_id.action_view_sales() self.product_fsm.product_tmpl_id._onchange_field_service_tracking() self.product_fsm_recur.product_tmpl_id._onchange_field_service_tracking() self.sale_order_recur.action_view_fsm_recurring() self.sale_order_recur2.action_view_fsm_recurring() self.sale_order.action_view_fsm_recurring() # FSM Recurring Order linked to Sale Order self.assertEqual( len(self.sale_order_recur.fsm_recurring_ids.ids), 1, """FSM Sale Recurring: Sale Order should create 1 FSM Recurring Order""", )
40.639535
6,990
1,938
py
PYTHON
15.0
# Copyright (C) 2019 Brian McMaster # Copyright (C) 2019 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models class SaleOrder(models.Model): _inherit = "sale.order" fsm_recurring_ids = fields.Many2many( "fsm.recurring", compute="_compute_fsm_recurring_ids", string="Field Service Recurring orders associated to this sale", ) fsm_recurring_count = fields.Float( string="FSM Recurring Orders", compute="_compute_fsm_recurring_ids" ) @api.depends("order_line.product_id") def _compute_fsm_recurring_ids(self): for order in self: order.fsm_recurring_ids = self.env["fsm.recurring"].search( [("sale_line_id", "in", order.order_line.ids)] ) order.fsm_recurring_count = len(order.fsm_recurring_ids) def action_view_fsm_recurring(self): fsm_recurrings = self.mapped("fsm_recurring_ids") action = self.env.ref("fieldservice_recurring.action_fsm_recurring").read()[0] if len(fsm_recurrings) > 1: action["domain"] = [("id", "in", fsm_recurrings.ids)] elif len(fsm_recurrings) == 1: action["views"] = [ ( self.env.ref("fieldservice_recurring.fsm_recurring_form_view").id, "form", ) ] action["res_id"] = fsm_recurrings.id else: action = {"type": "ir.actions.act_window_close"} return action def _action_confirm(self): """On SO confirmation, some lines generate field service recurrings.""" result = super(SaleOrder, self)._action_confirm() self.order_line.filtered( lambda l: l.product_id.field_service_tracking == "recurring" and not l.fsm_recurring_id )._field_create_fsm_recurring() return result
37.269231
1,938
2,693
py
PYTHON
15.0
# Copyright (C) 2019 Brian McMaster # Copyright (C) 2019 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import _, fields, models class SaleOrderLine(models.Model): _inherit = "sale.order.line" fsm_recurring_id = fields.Many2one( "fsm.recurring", "Recurring Order", index=True, help="Field Service Recurring Order generated by the sale order line", ) def _field_create_fsm_recurring_prepare_values(self): self.ensure_one() template = self.product_id.fsm_recurring_template_id product = self.product_id note = self.name if template.description: note += "\n " + template.description return { "location_id": self.order_id.fsm_location_id.id, "start_date": self.order_id.expected_date, "fsm_recurring_template_id": template.id, "description": note, "max_orders": template.max_orders, "fsm_frequency_set_id": template.fsm_frequency_set_id.id, "fsm_order_template_id": product.fsm_order_template_id.id or template.fsm_order_template_id.id, "sale_line_id": self.id, "company_id": self.company_id.id, } def _field_create_fsm_recurring(self): """Generate fsm_recurring for the given so line, and link it. :return a mapping with the so line id and its linked fsm_recurring :rtype dict """ result = {} for so_line in self: # create fsm_recurring values = so_line._field_create_fsm_recurring_prepare_values() fsm_recurring = self.env["fsm.recurring"].sudo().create(values) fsm_recurring.action_start() so_line.write({"fsm_recurring_id": fsm_recurring.id}) # post message on SO msg_body = _( """Field Service recurring Created ({}): <a href= # data-oe-model=fsm.recurring data-oe-id={}>{}</a> """ ).format(so_line.product_id.name, fsm_recurring.id, fsm_recurring.name) so_line.order_id.message_post(body=msg_body) # post message on fsm_recurring fsm_recurring_msg = _( """This recurring has been created from: <a href= # data-oe-model=sale.order data-oe-id={}>{}</a> ({}) """ ).format( so_line.order_id.id, so_line.order_id.name, so_line.product_id.name ) fsm_recurring.message_post(body=fsm_recurring_msg) result[so_line.id] = fsm_recurring return result
40.19403
2,693
862
py
PYTHON
15.0
# Copyright (C) 2019 Brian McMaster # Copyright (C) 2019 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models class ProductTemplate(models.Model): _inherit = "product.template" field_service_tracking = fields.Selection( selection_add=[("recurring", "Create a recurring order")] ) fsm_recurring_template_id = fields.Many2one( "fsm.recurring.template", "Field Service Recurring Template", help="Select a field service recurring order template to be created", ) @api.onchange("field_service_tracking") def _onchange_field_service_tracking(self): if self.field_service_tracking != "recurring": self.fsm_recurring_template_id = False else: return super()._onchange_field_service_tracking()
34.48
862
648
py
PYTHON
15.0
# Copyright (C) 2019 Brian McMaster # Copyright (C) 2019 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import _, fields, models class FSMRecurring(models.Model): _inherit = "fsm.recurring" sale_line_id = fields.Many2one("sale.order.line") def action_view_sales(self): self.ensure_one() return { "type": "ir.actions.act_window", "res_model": "sale.order", "views": [[False, "form"]], "res_id": self.sale_line_id.order_id.id, "context": {"create": False}, "name": _("Sales Orders"), }
29.454545
648
766
py
PYTHON
15.0
# Copyright (C) 2018 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "Field Service - Vehicles", "summary": "Manage Field Service vehicles and assign drivers", "version": "15.0.1.0.1", "category": "Field Service", "author": "Open Source Integrators, Odoo Community Association (OCA)", "website": "https://github.com/OCA/field-service", "depends": ["fieldservice"], "data": [ "security/res_groups.xml", "security/ir.model.access.csv", "views/fsm_vehicle.xml", "views/fsm_person.xml", "views/fsm_order.xml", "views/menu.xml", ], "license": "AGPL-3", "development_status": "Beta", "maintainers": ["wolfhall", "max3903"], }
34.818182
766
1,530
py
PYTHON
15.0
# Copyright (C) 2022 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from datetime import datetime, timedelta from odoo.tests.common import TransactionCase class FSMVehicleCase(TransactionCase): def setUp(self): super(FSMVehicleCase, self).setUp() self.test_partner = self.env["res.partner"].create( {"name": "Test Partner", "phone": "123", "email": "[email protected]"} ) self.test_vehicle = self.env["fsm.vehicle"].create({"name": "Test Vehicle"}) self.test_worker = self.env["fsm.person"].create( { "name": "Test Wokrer", "email": "[email protected]", "vehicle_id": self.test_vehicle.id, } ) self.test_location = self.env["fsm.location"].create( { "name": "Test Location", "phone": "123", "email": "[email protected]", "partner_id": self.test_partner.id, "owner_id": self.test_partner.id, } ) def test_vehicle(self): self.test_order = self.env["fsm.order"].create( { "location_id": self.test_location.id, "date_start": datetime.today(), "date_end": datetime.today() + timedelta(hours=2), "request_early": datetime.today(), "person_id": self.test_worker.id, } ) self.test_order._onchange_person_id()
34.772727
1,530
277
py
PYTHON
15.0
# Copyright (C) 2019 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class FSMPerson(models.Model): _inherit = "fsm.person" vehicle_id = fields.Many2one("fsm.vehicle", string="Default Vehicle")
30.777778
277
877
py
PYTHON
15.0
# Copyright (C) 2019 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models class FSMOrder(models.Model): _inherit = "fsm.order" @api.model def _get_default_vehicle(self): return self.person_id.vehicle_id.id or False vehicle_id = fields.Many2one( "fsm.vehicle", string="Vehicle", default=_get_default_vehicle ) @api.model def create(self, vals): res = super(FSMOrder, self).create(vals) if not vals.get("vehicle_id") and vals.get("person_id"): self._onchange_person_id() return res @api.onchange("person_id") def _onchange_person_id(self): self.vehicle_id = ( self.person_id and self.person_id.vehicle_id and self.person_id.vehicle_id.id or False )
28.290323
877
452
py
PYTHON
15.0
# Copyright (C) 2018 Brian McMaster # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class FSMVehicle(models.Model): _name = "fsm.vehicle" _description = "Field Service Vehicle" name = fields.Char(required="True") person_id = fields.Many2one("fsm.person", string="Assigned Driver") _sql_constraints = [ ("name_uniq", "unique (name)", "Vehicle name already exists!"), ]
30.133333
452
729
py
PYTHON
15.0
# Copyright (C) 2021 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "Field Service - Repair", "summary": "Integrate Field Service orders with MRP repair orders", "version": "15.0.1.0.0", "category": "Field Service", "author": "Open Source Integrators, Odoo Community Association (OCA)", "website": "https://github.com/OCA/field-service", "depends": [ "fieldservice_equipment_stock", "repair", ], "data": ["data/fsm_order_type.xml", "views/fsm_order_view.xml"], "license": "AGPL-3", "development_status": "Beta", "maintainers": [ "smangukiya", "max3903", ], "installable": True, }
31.695652
729
2,426
py
PYTHON
15.0
# Copyright (C) 2021 - TODAY, Open Source Integrators # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) from datetime import timedelta from odoo import fields from odoo.exceptions import ValidationError from odoo.tests.common import TransactionCase class TestFSMRepairCommon(TransactionCase): def setUp(self): super(TestFSMRepairCommon, self).setUp() self.test_location = self.env.ref("fieldservice.test_location") self.stock_location = self.env.ref("stock.stock_location_customers") self.FSMOrder = self.env["fsm.order"] self.OrderType = self.env["fsm.order.type"].create( {"name": "Test1", "internal_type": "repair"} ) self.product1 = self.env["product.product"].create( {"name": "Product A", "type": "product"} ) self.lot1 = self.env["stock.production.lot"].create( { "name": "sn11", "product_id": self.product1.id, "company_id": self.env.company.id, } ) self.equipment = self.env["fsm.equipment"].create( { "name": "test equipment", "product_id": self.product1.id, "lot_id": self.lot1.id, } ) def test_fsm_orders(self): """Test creating new workorders, and test following functions.""" # Create an Orders hours_diff = 100 date_start = fields.Datetime.today() with self.assertRaises(ValidationError): self.FSMOrder.create( { "type": self.OrderType.id, "location_id": self.test_location.id, "equipment_id": self.equipment.id, "date_start": date_start, "date_end": date_start + timedelta(hours=hours_diff), "request_early": fields.Datetime.today(), } ) self.equipment.current_stock_location_id = self.stock_location.id self.FSMOrder.create( { "type": self.OrderType.id, "location_id": self.test_location.id, "equipment_id": self.equipment.id, "date_start": date_start, "date_end": date_start + timedelta(hours=hours_diff), "request_early": fields.Datetime.today(), } )
37.90625
2,426
1,976
py
PYTHON
15.0
# Copyright (C) 2021 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import _, api, fields, models from odoo.exceptions import ValidationError class FSMOrder(models.Model): _inherit = "fsm.order" repair_id = fields.Many2one("repair.order", string="Repair Order") @api.model def create(self, vals): # if FSM order with type repair is created then # create a repair order order = super(FSMOrder, self).create(vals) if order.type.internal_type == "repair": if order.equipment_id and order.equipment_id.current_stock_location_id: equipment = order.equipment_id repair_id = self.env["repair.order"].create( { "name": order.name or "", "product_id": equipment.product_id.id or False, "product_uom": equipment.product_id.uom_id.id or False, "location_id": equipment.current_stock_location_id and equipment.current_stock_location_id.id or False, "lot_id": equipment.lot_id.id or "", "product_qty": 1, "invoice_method": "none", "internal_notes": order.description, "partner_id": order.location_id.partner_id and order.location_id.partner_id.id or False, } ) order.repair_id = repair_id elif not order.equipment_id.current_stock_location_id: raise ValidationError( _( "Cannot create Repair Order because " "Equipment does not have a Current " "Inventory Location." ) ) return order
42.042553
1,976
310
py
PYTHON
15.0
# Copyright 2021 - TODAY, Marcel Savegnago - Escodoo # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class FsmOrderType(models.Model): _inherit = "fsm.order.type" internal_type = fields.Selection( selection_add=[("repair", "Repair")], )
23.846154
310
766
py
PYTHON
15.0
# Copyright (C) 2020 Brian McMaster <[email protected]> # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "Field Service Sizes", "summary": "Manage Sizes for Field Service Locations and Orders", "version": "15.0.1.0.0", "category": "Field Service", "author": "Brian McMaster, Odoo Community Association (OCA)", "website": "https://github.com/OCA/field-service", "depends": [ "fieldservice", "uom", ], "data": [ "security/ir.model.access.csv", "views/fsm_size.xml", "views/fsm_location.xml", "views/fsm_order.xml", "views/menu.xml", ], "license": "AGPL-3", "development_status": "Beta", "maintainers": [ "brian10048", ], }
29.461538
766
2,059
py
PYTHON
15.0
# Copyright (C) 2020 - Brian McMaster # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo.exceptions import ValidationError from odoo.tests.common import TransactionCase class TestFSMSize(TransactionCase): def setUp(self): super(TestFSMSize, self).setUp() self.Size = self.env["fsm.size"] self.Location_size = self.env["fsm.location.size"] self.Type = self.env["fsm.order.type"] self.Order = self.env["fsm.order"] self.UOM = self.env.ref("uom.product_uom_unit") self.type_a = self.Type.create({"name": "Type A"}) self.size_a = self.Size.create( { "name": "Size A 1", "type_id": self.type_a.id, "uom_id": self.UOM.id, "is_order_size": True, } ) self.test_location = self.env.ref("fieldservice.test_location") def test_one_size_per_type(self): with self.assertRaises(ValidationError) as e: self.Size.create( { "name": "Size A 2", "type_id": self.type_a.id, "uom_id": self.UOM.id, "is_order_size": True, } ) self.assertEqual( e.exception.args[0], "Only one default order size per type is allowed." ) def test_order_onchange_location(self): self.Location_size.create( { "size_id": self.size_a.id, "quantity": 24.5, "location_id": self.test_location.id, } ) order = self.Order.create( { "type": self.type_a.id, "location_id": self.test_location.id, } ) order._onchange_location_id_customer() order.onchange_type() order.onchange_size_id() self.assertTrue(order.size_id, self.size_a.id) self.assertTrue(order.size_value, 24.5) self.assertTrue(order.size_uom, self.size_a.uom_id)
34.898305
2,059
850
py
PYTHON
15.0
# Copyright (C) 2020 Brian McMaster <[email protected]> # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class FSMLocationSize(models.Model): _name = "fsm.location.size" _description = "Size for FSM Location" size_id = fields.Many2one("fsm.size", required=True, index=True) type_id = fields.Many2one("fsm.order.type", index=True, related="size_id.type_id") quantity = fields.Float(required=True) uom_id = fields.Many2one("uom.uom", index=True, related="size_id.uom_id") location_id = fields.Many2one( "fsm.location", string="Location", required=True, index=True ) _sql_constraints = [ ( "one_size_per_location", "unique(location_id, size_id)", "Only one size of same type allowed per location", ) ]
35.416667
850
333
py
PYTHON
15.0
# Copyright (C) 2020 Brian McMaster <[email protected]> # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class FSMLocation(models.Model): _inherit = "fsm.location" location_size_ids = fields.One2many( "fsm.location.size", "location_id", string="Location Sizes" )
30.272727
333
1,913
py
PYTHON
15.0
# Copyright (C) 2020 Brian McMaster <[email protected]> # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models class FSMOrder(models.Model): _inherit = "fsm.order" def _default_size_id(self): size = False if self.type: size = self.env["fsm.size"].search( [("type_id", "=", self.type.id), ("is_order_size", "=", True)], limit=1 ) return size def _default_size_value(self): size_value = 0 if self.size_id: size = self.env["fsm.location.size"].search( [ ("location_id", "=", self.location_id.id), ("size_id", "=", self.size_id.id), ], limit=1, ) if size: size_value = size.quantity return size_value def _default_size_uom(self): return self.size_id.uom_id if self.size_id else False size_id = fields.Many2one("fsm.size", default=_default_size_id) size_value = fields.Float(string="Order Size", default=_default_size_value) size_uom = fields.Many2one( "uom.uom", string="Unit of Measure", default=_default_size_uom ) @api.onchange("location_id") def _onchange_location_id_customer(self): res = super()._onchange_location_id_customer() self.size_id = self._default_size_id() self.size_value = self._default_size_value() self.size_uom = self._default_size_uom() return res @api.onchange("type") def onchange_type(self): self.size_id = self._default_size_id() self.size_value = self._default_size_value() self.size_uom = self._default_size_uom() @api.onchange("size_id") def onchange_size_id(self): self.size_value = self._default_size_value() self.size_uom = self._default_size_uom()
33.561404
1,913
1,108
py
PYTHON
15.0
# Copyright (C) 2020 Brian McMaster <[email protected]> # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import _, api, fields, models from odoo.exceptions import ValidationError class FSMSize(models.Model): _name = "fsm.size" _description = "Field Service Size" name = fields.Char(required="True") type_id = fields.Many2one("fsm.order.type", string="Order Type") parent_id = fields.Many2one("fsm.size", string="Parent Size", index=True) uom_id = fields.Many2one("uom.uom", string="Unit of Measure") is_order_size = fields.Boolean( string="Is the Order Size?", help="The default size for orders of this type" ) _sql_constraints = [ ("name_uniq", "unique (name)", "Size name already exists!"), ] @api.constrains("is_order_size", "type_id") def _one_size_per_type(self): size_count = self.search_count( [("type_id", "=", self.type_id.id), ("is_order_size", "=", True)] ) if size_count >= 2: raise ValidationError(_("Only one default order size per type is allowed."))
38.206897
1,108
592
py
PYTHON
15.0
# Copyright (C) 2020 Brian McMaster <[email protected]> # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "FSM Stage Validation", "summary": "Validate input data when reaching a Field Service stage", "version": "15.0.1.0.0", "category": "Field Service", "author": "Brian McMaster, Odoo Community Association (OCA)", "website": "https://github.com/OCA/field-service", "depends": ["fieldservice"], "data": ["views/fsm_stage.xml"], "license": "AGPL-3", "development_status": "Beta", "maintainers": ["brian10048", "max3903"], }
39.466667
592
7,783
py
PYTHON
15.0
# Copyright 2020, Brian McMaster <[email protected]> # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) from odoo import fields from odoo.exceptions import ValidationError from odoo.tests.common import TransactionCase class TestFSMStageValidation(TransactionCase): def setUp(self): super().setUp() self.env = self.env(context=dict(self.env.context, tracking_disable=True)) self.stage = self.env["fsm.stage"] self.fsm_order = self.env["fsm.order"] self.fsm_person = self.env["fsm.person"] self.fsm_location = self.env["fsm.location"] self.fsm_equipment = self.env["fsm.equipment"] self.ir_model_fields = self.env["ir.model.fields"] # Get some fields to use in the stages self.order_field = self.ir_model_fields.search( [("model", "=", "fsm.order"), ("name", "=", "description")] ) self.person_field = self.ir_model_fields.search( [("model", "=", "fsm.person"), ("name", "=", "mobile")] ) self.location_field = self.ir_model_fields.search( [("model", "=", "fsm.location"), ("name", "=", "direction")] ) self.equipment_field = self.ir_model_fields.search( [("model", "=", "fsm.equipment"), ("name", "=", "notes")] ) # For each model type, create a default stage and a stage # which will apply field validation # Order Stages self.stage_order_default = self.stage.create( { "name": "Order Stage Default", "stage_type": "order", "is_default": True, "sequence": "10", } ) self.stage_order = self.stage.create( { "name": "Order Stage Validate", "stage_type": "order", "validate_field_ids": [(6, 0, [self.order_field.id])], "sequence": "11", } ) # Person Stages self.stage_person_default = self.stage.create( { "name": "Person Stage Default", "stage_type": "worker", "is_default": True, "sequence": "10", } ) self.stage_person = self.stage.create( { "name": "Person Stage Validate", "stage_type": "worker", "validate_field_ids": [(6, 0, [self.person_field.id])], "sequence": "11", } ) # Location Stages self.stage_location_default = self.stage.create( { "name": "Location Stage Default", "stage_type": "location", "is_default": True, "sequence": "10", } ) self.stage_location = self.stage.create( { "name": "Location Stage Validate", "stage_type": "location", "validate_field_ids": [(6, 0, [self.location_field.id])], "sequence": "11", } ) # Equipment Stages self.stage_equipment_default = self.stage.create( { "name": "Equipment Stage Default", "stage_type": "equipment", "is_default": True, "sequence": "10", } ) self.stage_equipment = self.stage.create( { "name": "Equipment Stage Validate", "stage_type": "equipment", "validate_field_ids": [(6, 0, [self.equipment_field.id])], "sequence": "11", } ) # Create a person self.person_01 = self.fsm_person.create( { "name": "FSM Worker 01", "partner_id": self.env["res.partner"] .create({"name": "Worker 01 Partner"}) .id, "stage_id": self.stage_person_default.id, } ) # Create a location self.location_01 = self.fsm_location.create( { "name": "Location 01", "owner_id": self.env["res.partner"] .create({"name": "Location 01 Partner"}) .id, "stage_id": self.stage_location_default.id, } ) # Create an Equipment self.equipment_01 = self.fsm_equipment.create( { "name": "Equipment 01", "current_location_id": self.location_01.id, "stage_id": self.stage_equipment_default.id, } ) # Create an Order self.order_01 = self.fsm_order.create({"location_id": self.location_01.id}) def get_validate_message(self, stage): stage_name = stage.name field_name = fields.first(stage.validate_field_ids).name return 'Cannot move to stage "%s" until the "%s" field is set.' % ( stage_name, field_name, ) def test_fsm_stage_validation(self): # Validate the stage computes the correct model type self.assertEqual( self.stage_order.stage_type_model_id, self.env["ir.model"].search([("model", "=", "fsm.order")]), "FSM Stage model is not computed correctly", ) validate_message = self.get_validate_message(self.stage_equipment) # Validate the Equipment cannot move to next stage with self.assertRaisesRegex(ValidationError, validate_message): self.equipment_01.next_stage() # Update the Equipment notes field and validate it goes to next stage self.equipment_01.notes = "Equipment service note" self.equipment_01.next_stage() self.assertEqual( self.equipment_01.stage_id, self.stage_equipment, "FSM Equipment did not progress to correct stage", ) validate_message = self.get_validate_message(self.stage_location) # Validate the Location cannot move to next stage with self.assertRaisesRegex(ValidationError, validate_message): self.location_01.next_stage() # Update the Location directions field and validate it goes to next stage self.location_01.direction = "Location direction note" self.location_01.next_stage() self.assertEqual( self.location_01.stage_id, self.stage_location, "FSM Location did not progress to correct stage", ) validate_message = self.get_validate_message(self.stage_person) # Validate the Person cannot move to next stage with self.assertRaisesRegex(ValidationError, validate_message): self.person_01.next_stage() # Update the Person mobile field and validate it goes to next stage self.person_01.mobile = "1-888-888-8888" self.person_01.next_stage() self.assertEqual( self.person_01.stage_id, self.stage_person, "FSM Person did not progress to correct stage", ) validate_message = self.get_validate_message(self.stage_order) # Validate the Order cannot move to stage which requires validation with self.assertRaisesRegex(ValidationError, validate_message): self.order_01.write({"stage_id": self.stage_order.id}) # Update the Order description field and validate it goes to next stage self.order_01.description = "Complete the work order" self.order_01.write({"stage_id": self.stage_order.id}) self.assertEqual( self.order_01.stage_id, self.stage_order, "FSM Order did not progress to correct stage", )
38.339901
7,783
368
py
PYTHON
15.0
# Copyright (C) 2020 Brian McMaster <[email protected]> # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, models from .validate_utils import validate_stage_fields class FSMPerson(models.Model): _inherit = "fsm.person" @api.constrains("stage_id") def _validate_stage_fields(self): validate_stage_fields(self)
28.307692
368
372
py
PYTHON
15.0
# Copyright (C) 2020 Brian McMaster <[email protected]> # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, models from .validate_utils import validate_stage_fields class FSMLocation(models.Model): _inherit = "fsm.location" @api.constrains("stage_id") def _validate_stage_fields(self): validate_stage_fields(self)
28.615385
372
366
py
PYTHON
15.0
# Copyright (C) 2020 Brian McMaster <[email protected]> # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, models from .validate_utils import validate_stage_fields class FSMOrder(models.Model): _inherit = "fsm.order" @api.constrains("stage_id") def _validate_stage_fields(self): validate_stage_fields(self)
28.153846
366
770
py
PYTHON
15.0
# Copyright 2022 Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from odoo import _ from odoo.exceptions import ValidationError def validate_stage_fields(records): for rec in records: stage = rec.stage_id field_ids = stage.validate_field_ids field_names = [x.name for x in field_ids] values = rec.read(field_names) for name in field_names: if not values[0][name]: raise ValidationError( _( 'Cannot move to stage "%(stage_name)s" ' 'until the "%(name)s" field is set.', stage_name=stage.name, name=name, ) )
32.083333
770
374
py
PYTHON
15.0
# Copyright (C) 2020 Brian McMaster <[email protected]> # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, models from .validate_utils import validate_stage_fields class FSMEquipment(models.Model): _inherit = "fsm.equipment" @api.constrains("stage_id") def _validate_stage_fields(self): validate_stage_fields(self)
28.769231
374
979
py
PYTHON
15.0
# Copyright (C) 2020 Brian McMaster <[email protected]> # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models class FSMStage(models.Model): _inherit = "fsm.stage" validate_field_ids = fields.Many2many( "ir.model.fields", string="Fields to Validate", help="Select fields which must be set on the document in this stage", ) stage_type_model_id = fields.Many2one( "ir.model", compute="_compute_stage_model", string="Model for Stage", help="Technical field to hold model type", ) @api.depends("stage_type") def _compute_stage_model(self): Model = self.env["ir.model"] for rec in self: model_id = False if rec.stage_type: model_string = "fsm." + rec.stage_type model_id = Model.search([("model", "=", model_string)], limit=1).id rec.stage_type_model_id = model_id
32.633333
979
322
py
PYTHON
15.0
# Copyright (C) 2019 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). def pre_init_hook(cr): cr.execute("""ALTER TABLE "fsm_location" ADD "customer_id" INT;""") cr.execute( """UPDATE "fsm_location" SET customer_id = owner_id WHERE customer_id IS NULL;""" )
32.2
322
1,038
py
PYTHON
15.0
# Copyright (C) 2018 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "Field Service - Analytic Accounting", "summary": """Track analytic accounts on Field Service locations and orders""", "version": "15.0.1.0.0", "category": "Field Service", "author": "Open Source Integrators, Odoo Community Association (OCA)", "website": "https://github.com/OCA/field-service", "depends": [ "fieldservice_account", "analytic", "product", ], "data": [ "data/ir_rule.xml", "security/ir.model.access.csv", "report/fsm_order_report_template.xml", "views/fsm_location.xml", "views/fsm_order.xml", "views/res_config_settings.xml", ], "demo": [ "demo/fsm_location.xml", ], "pre_init_hook": "pre_init_hook", "license": "AGPL-3", "development_status": "Beta", "maintainers": [ "osimallen", "brian10048", "bodedra", ], }
28.833333
1,038
262
py
PYTHON
15.0
# Copyright (C) 2021, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). def migrate(env, version): if not version: return env.execute("UPDATE fsm_order SET bill_to = 'location' " "WHERE bill_to IS NULL;")
29.111111
262
7,323
py
PYTHON
15.0
# Copyright 2019 Ecosoft Co., Ltd (http://ecosoft.co.th/) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) from datetime import timedelta from odoo import fields from odoo.exceptions import ValidationError from odoo.tests.common import TransactionCase class FSMAccountAnalyticCase(TransactionCase): def setUp(self): super(FSMAccountAnalyticCase, self).setUp() self.Wizard = self.env["fsm.wizard"] self.WorkOrder = self.env["fsm.order"] self.AccountInvoice = self.env["account.move"] self.AccountInvoiceLine = self.env["account.move.line"] # create a Res Partner self.test_partner = self.env["res.partner"].create( {"name": "Test Partner", "phone": "123", "email": "[email protected]"} ) # create a Res Partner to be converted to FSM Location/Person self.test_loc_partner = self.env["res.partner"].create( {"name": "Test Loc Partner", "phone": "ABC", "email": "[email protected]"} ) self.test_loc_partner2 = self.env["res.partner"].create( {"name": "Test Loc Partner 2", "phone": "123", "email": "[email protected]"} ) # create expected FSM Location to compare to converted FSM Location self.test_location = self.env["fsm.location"].create( { "name": "Test Location", "phone": "123", "email": "[email protected]", "partner_id": self.test_loc_partner.id, "owner_id": self.test_loc_partner.id, "customer_id": self.test_loc_partner.id, } ) self.location = self.env["fsm.location"].create( { "name": "Location 1", "phone": "123", "email": "[email protected]", "partner_id": self.test_loc_partner.id, "owner_id": self.test_loc_partner.id, "customer_id": self.test_loc_partner.id, } ) self.test_analytic_account = self.env["account.analytic.account"].create( {"name": "test_analytic_account"} ) self.test_location2 = self.env["fsm.location"].create( { "name": "Test Location 2", "phone": "123", "email": "[email protected]", "partner_id": self.test_loc_partner2.id, "owner_id": self.test_loc_partner2.id, "customer_id": self.test_loc_partner2.id, "fsm_parent_id": self.test_location.id, "analytic_account_id": self.test_analytic_account.id, } ) self.default_account_revenue = self.env["account.account"].search( [ ("company_id", "=", self.env.user.company_id.id), ( "user_type_id", "=", self.env.ref("account.data_account_type_revenue").id, ), ], limit=1, ) self.move_line = self.env["account.move.line"] self.analytic_line = self.env["account.analytic.line"] self.product1 = self.env["product.product"].create( { "name": "Product A", "detailed_type": "consu", } ) def test_convert_contact_to_fsm_loc(self): """ Test converting a contact to a location to make sure the customer_id and owner_id get set correctly :return: """ self.Wizard._prepare_fsm_location(self.test_partner) # check if there is a new FSM Location with the same name self.wiz_location = self.env["fsm.location"].search( [("name", "=", self.test_loc_partner2.name)] ) # check if location is created successfully and fields copied over self.assertEqual(self.test_loc_partner2, self.wiz_location.customer_id) self.assertEqual(self.test_loc_partner2, self.wiz_location.owner_id) def test_fsm_orders_1(self): """Test creating new workorders, and test following functions.""" # Create an Orders hours_diff = 100 date_start = fields.Datetime.today() order = self.WorkOrder.create( { "location_id": self.test_location.id, "date_start": date_start, "customer_id": self.test_partner.id, "date_end": date_start + timedelta(hours=hours_diff), "request_early": fields.Datetime.today(), } ) order2 = self.env["fsm.order"].create( { "location_id": self.test_location2.id, "date_start": fields.datetime.today(), "date_end": fields.datetime.today() + timedelta(hours=2), "request_early": fields.datetime.today(), } ) order4 = self.env["fsm.order"].create( { "location_id": self.location.id, "date_start": fields.datetime.today(), "date_end": fields.datetime.today() + timedelta(hours=2), "request_early": fields.datetime.today(), } ) order._compute_total_cost() order4._compute_total_cost() self.env.user.company_id.fsm_filter_location_by_contact = True self.test_location2.get_default_customer() general_journal = self.env["account.journal"].search( [ ("company_id", "=", self.env.user.company_id.id), ("type", "=", "general"), ], limit=1, ) general_move1 = self.env["account.move"].create( { "name": "general1", "journal_id": general_journal.id, } ) self.move_line.create( [ { "account_id": self.default_account_revenue.id, "analytic_account_id": self.test_analytic_account.id, "fsm_order_ids": [(6, 0, order2.ids)], "move_id": general_move1.id, } ] ) with self.assertRaises(ValidationError): self.move_line.create( { "account_id": self.default_account_revenue.id, "analytic_account_id": self.test_analytic_account.id, "fsm_order_ids": [(6, 0, order.ids)], } ) self.analytic_line.create( { "fsm_order_id": order2.id, "name": "Test01", "product_id": self.product1.id, } ) self.analytic_line.onchange_product_id() with self.assertRaises(ValidationError): self.analytic_line.create( { "fsm_order_id": order.id, "name": "Test01", } ) order._onchange_customer_id_location() self.test_location2._onchange_fsm_parent_id_account() self.env["res.partner"].with_context(location_id=self.test_location2.id).search( [] ) self.env["fsm.location"].with_context(customer_id=self.test_partner.id).search( [] )
38.746032
7,323
399
py
PYTHON
15.0
# Copyright (C) 2018 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import models class FSMWizard(models.TransientModel): _inherit = "fsm.wizard" def _prepare_fsm_location(self, partner): res = super()._prepare_fsm_location(partner) res["customer_id"] = partner.id res["owner_id"] = partner.id return res
30.692308
399
1,636
py
PYTHON
15.0
# Copyright (C) 2018 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models class FSMLocation(models.Model): _inherit = "fsm.location" analytic_account_id = fields.Many2one( "account.analytic.account", string="Analytic Account", company_dependent=True ) @api.model def get_default_customer(self): if self.fsm_parent_id: return self.fsm_parent_id.customer_id.id return self.owner_id.id customer_id = fields.Many2one( "res.partner", string="Billed Customer", required=True, ondelete="restrict", auto_join=True, tracking=True, default=get_default_customer, ) @api.onchange("fsm_parent_id") def _onchange_fsm_parent_id_account(self): self.customer_id = self.fsm_parent_id.customer_id or False @api.model def _search( self, args, offset=0, limit=None, order=None, count=False, access_rights_uid=None, ): args = args or [] context = dict(self._context) or {} if context.get("customer_id"): partner = self.env["res.partner"].browse(context.get("customer_id")) args.extend( [ ("partner_id", "=", partner.id), ] ) return super(FSMLocation, self)._search( args, offset=offset, limit=limit, order=order, count=count, access_rights_uid=access_rights_uid, )
27.266667
1,636
1,038
py
PYTHON
15.0
# Copyright (C) 2018 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import _, api, models from odoo.exceptions import ValidationError class AccountMoveLine(models.Model): _inherit = "account.move.line" @api.model_create_multi def create(self, vals_list): for vals in vals_list: if vals.get("fsm_order_ids") and vals.get("fsm_order_ids")[0][2]: fsm_orders = vals.get("fsm_order_ids")[0][2] for order in self.env["fsm.order"].browse(fsm_orders).exists(): if order.location_id.analytic_account_id: vals[ "analytic_account_id" ] = order.location_id.analytic_account_id.id else: raise ValidationError( _("No analytic account " "set on the order's Location.") ) return super(AccountMoveLine, self).create(vals_list)
41.52
1,038
1,214
py
PYTHON
15.0
# Copyright (C) 2018 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models class FSMOrder(models.Model): _inherit = "fsm.order" total_cost = fields.Float(compute="_compute_total_cost") bill_to = fields.Selection( [("location", "Bill Location"), ("contact", "Bill Contact")], required=True, default="location", ) customer_id = fields.Many2one( "res.partner", string="Contact", change_default=True, index=True, tracking=True, ) def _compute_total_cost(self): """To be overridden as needed from other modules""" for order in self: order.total_cost = 0.0 @api.onchange("customer_id") def _onchange_customer_id_location(self): self.location_id = ( self.customer_id.service_location_id if self.customer_id else False ) def write(self, vals): res = super(FSMOrder, self).write(vals) for order in self: if "customer_id" not in vals and not order.customer_id: order.customer_id = order.location_id.customer_id.id return res
30.35
1,214
321
py
PYTHON
15.0
# Copyright (C) 2020 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class ResCompany(models.Model): _inherit = "res.company" fsm_filter_location_by_contact = fields.Boolean( string="Filter Contacts with Location" )
26.75
321
423
py
PYTHON
15.0
# Copyright (C) 2020, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class ResConfigSettings(models.TransientModel): _inherit = "res.config.settings" fsm_filter_location_by_contact = fields.Boolean( string="Filter Contacts with Location", related="company_id.fsm_filter_location_by_contact", readonly=False, )
30.214286
423
1,043
py
PYTHON
15.0
# Copyright (C) 2018 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import _, api, fields, models from odoo.exceptions import ValidationError class AccountAnalyticLine(models.Model): _inherit = "account.analytic.line" fsm_order_id = fields.Many2one("fsm.order", string="FSM Order") product_id = fields.Many2one("product.product", string="Time Type") @api.model def create(self, vals): order = self.env["fsm.order"].browse(vals.get("fsm_order_id")) if order: if order.location_id.analytic_account_id: vals["account_id"] = order.location_id.analytic_account_id.id else: raise ValidationError( _("No analytic account set " "on the order's Location.") ) return super(AccountAnalyticLine, self).create(vals) @api.onchange("product_id") def onchange_product_id(self): self.name = self.product_id.name if self.product_id else False
37.25
1,043
1,043
py
PYTHON
15.0
# Copyright (C) 2022 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, models class ResPartner(models.Model): _inherit = "res.partner" @api.model def _search( self, args, offset=0, limit=None, order=None, count=False, access_rights_uid=None, ): args = args or [] context = dict(self._context) or {} if ( context.get("location_id") and self.env.user.company_id.fsm_filter_location_by_contact ): location = self.env["fsm.location"].browse(context.get("location_id")) args.extend( [ ("service_location_id", "=", location.id), ] ) return super(ResPartner, self)._search( args, offset=offset, limit=limit, order=order, count=count, access_rights_uid=access_rights_uid, )
26.74359
1,043
670
py
PYTHON
15.0
# Copyright (C) 2021 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "Field Service - Purchase", "summary": "Manage FSM Purchases", "author": "Open Source Integrators, " "Odoo Community Association (OCA)", "website": "https://github.com/OCA/field-service", "category": "Field Service", "license": "AGPL-3", "version": "15.0.1.0.1", "depends": [ "fieldservice", "purchase", ], "data": [ "security/ir.model.access.csv", "views/fsm_person.xml", ], "development_status": "Beta", "maintainers": [ "osi-scampbell", ], }
27.916667
670
1,476
py
PYTHON
15.0
# Copyright (C) 2021 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). import odoo.tests.common as common class TestFieldServicePurchase(common.TransactionCase): def setUp(self): super(TestFieldServicePurchase, self).setUp() self.product_supplierinfo_obj = self.env["product.supplierinfo"] self.fsm_person_obj = self.env["fsm.person"] def test_fieldservice_purchase(self): fsm_person = self.fsm_person_obj.create({"name": "Test FSM Person"}) # Test with 1 records Vendor Pricelist product_supplierinfo_vals = { "name": fsm_person.partner_id.id, "min_qty": 1.0, "price": 100, } self.product_supplierinfo_obj.create(product_supplierinfo_vals) fsm_person._compute_pricelist_count() self.assertEqual( fsm_person.pricelist_count, 1, "Wrong no of vendors pricelist!" ) fsm_person.action_view_pricelists() # Test with 2 records Vendor Pricelist product_supplierinfo_vals = { "name": fsm_person.partner_id.id, "min_qty": 2.0, "price": 200, } self.product_supplierinfo_obj.create(product_supplierinfo_vals) fsm_person._compute_pricelist_count() self.assertEqual( fsm_person.pricelist_count, 2, "Wrong no of vendors pricelist!" ) fsm_person.action_view_pricelists()
34.325581
1,476
1,224
py
PYTHON
15.0
# Copyright (C) 2021 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class FSMPerson(models.Model): _inherit = "fsm.person" pricelist_count = fields.Integer( compute="_compute_pricelist_count", string="# Pricelists" ) def _compute_pricelist_count(self): for worker in self: worker.pricelist_count = self.env["product.supplierinfo"].search_count( [("name", "=", worker.partner_id.id)] ) def action_view_pricelists(self): for worker in self: pricelist = self.env["product.supplierinfo"].search( [("name", "=", worker.partner_id.id)] ) action = self.env["ir.actions.act_window"]._for_xml_id( "product.product_supplierinfo_type_action" ) if len(pricelist) == 1: action["views"] = [ (self.env.ref("product.product_supplierinfo_form_view").id, "form") ] action["res_id"] = pricelist.ids[0] else: action["domain"] = [("id", "in", pricelist.ids)] return action
34.971429
1,224
736
py
PYTHON
15.0
# Copyright (C) 2021 - TODAY, Brian McMaster # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "Field Service - Delivery", "summary": "Select delivery methods and carriers on Field Service orders", "version": "15.0.1.0.0", "category": "Field Service", "author": "Open Source Integrators, " "Odoo Community Association (OCA)", "website": "https://github.com/OCA/field-service", "depends": [ "fieldservice_stock", "delivery", "stock_request", ], "data": [ "views/fsm_order.xml", ], "installable": True, "auto_install": True, "license": "AGPL-3", "development_status": "Beta", "maintainers": [ "max3903", ], }
28.307692
736
3,284
py
PYTHON
15.0
# Copyright (C) 2022 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from datetime import datetime, timedelta from odoo.tests.common import TransactionCase class FSMDeliveryCase(TransactionCase): def setUp(self): super(FSMDeliveryCase, self).setUp() self.SaleOrder = self.env["sale.order"] self.test_partner = self.env["res.partner"].create( {"name": "Test Partner", "phone": "123", "email": "[email protected]"} ) self.product_delivery_normal = self.env["product.product"].create( { "name": "Normal Delivery Charges", "invoice_policy": "order", "type": "service", "list_price": 10.0, "categ_id": self.env.ref("delivery.product_category_deliveries").id, } ) self.product_cable_management_box = self.env["product.product"].create( { "name": "Another product to deliver", "weight": 1.0, "invoice_policy": "order", } ) self.pricelist_id = self.env.ref("product.list0") self.normal_delivery = self.env["delivery.carrier"].create( { "name": "Normal Delivery Charges", "fixed_price": 10, "delivery_type": "fixed", "product_id": self.product_delivery_normal.id, } ) self.test_location = self.env["fsm.location"].create( { "name": "Test Location", "phone": "123", "email": "[email protected]", "partner_id": self.test_partner.id, "owner_id": self.test_partner.id, "customer_id": self.test_partner.id, } ) self.test_order = self.env["fsm.order"].create( { "location_id": self.test_location.id, "date_start": datetime.today(), "date_end": datetime.today() + timedelta(hours=2), "request_early": datetime.today(), "carrier_id": self.normal_delivery.id, } ) def test_delivery_stock_move(self): self.sale_prepaid = self.SaleOrder.create( { "partner_id": self.test_partner.id, "partner_invoice_id": self.test_partner.id, "partner_shipping_id": self.test_partner.id, "pricelist_id": self.pricelist_id.id, "order_line": [ ( 0, 0, { "name": "Cable Management Box", "product_id": self.product_cable_management_box.id, "product_uom_qty": 2, "product_uom": self.env.ref("uom.product_uom_unit").id, "price_unit": 750.00, }, ) ], } ) self.sale_prepaid.action_confirm() moves = self.sale_prepaid.picking_ids.move_lines moves.fsm_order_id = self.test_order.id moves._get_new_picking_values()
38.186047
3,284
281
py
PYTHON
15.0
# Copyright (C) 2021 - TODAY, Brian McMaster # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class FSMOrder(models.Model): _inherit = "fsm.order" carrier_id = fields.Many2one("delivery.carrier", string="Delivery Method")
28.1
281
543
py
PYTHON
15.0
# Copyright (C) 2021 - TODAY, Brian McMaster # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class StockMove(models.Model): _inherit = "stock.move" def _get_new_picking_values(self): vals = super(StockMove, self)._get_new_picking_values() vals["carrier_id"] = self.fsm_order_id.carrier_id.id return vals class ProcurementGroup(models.Model): _inherit = "procurement.group" carrier_id = fields.Many2one("delivery.carrier", string="Delivery Method")
28.578947
543