From 9953a9ef8e2c2a9af63837d625014af43066daaa Mon Sep 17 00:00:00 2001 From: brian10048 Date: Mon, 20 Jul 2020 23:54:14 -0400 Subject: [PATCH] [IMP] fieldservice_fleet: black, isort, prettier --- fieldservice_fleet/__manifest__.py | 44 +- fieldservice_fleet/hooks.py | 37 +- fieldservice_fleet/models/fleet_vehicle.py | 20 +- fieldservice_fleet/models/fsm_vehicle.py | 32 +- .../static/description/index.html | 1213 +++++++++++------ fieldservice_fleet/tests/__init__.py | 4 +- .../tests/test_fsm_fleet_wizard.py | 33 +- fieldservice_fleet/views/fleet_vehicle.xml | 7 +- fieldservice_fleet/views/fsm_vehicle.xml | 6 +- fieldservice_fleet/wizard/fsm_fleet_wizard.py | 33 +- .../wizard/fsm_fleet_wizard.xml | 30 +- 11 files changed, 881 insertions(+), 578 deletions(-) diff --git a/fieldservice_fleet/__manifest__.py b/fieldservice_fleet/__manifest__.py index b40d7c8c6a..78bbaeb080 100644 --- a/fieldservice_fleet/__manifest__.py +++ b/fieldservice_fleet/__manifest__.py @@ -3,31 +3,23 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { - 'name': 'Field Service Fleet', - 'summary': 'Link Field Service vehicles with Odoo Fleet', - 'version': '12.0.1.0.1', - 'category': 'Field Service', - 'author': - 'Brian McMaster, ' - 'Open Source Integrators, ' - 'Odoo Community Association (OCA)', - 'website': 'https://github.com/OCA/field-service', - 'depends': [ - 'fieldservice_vehicle', - 'fleet', + "name": "Field Service Fleet", + "summary": "Link Field Service vehicles with Odoo Fleet", + "version": "12.0.1.0.1", + "category": "Field Service", + "author": "Brian McMaster, " + "Open Source Integrators, " + "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/field-service", + "depends": ["fieldservice_vehicle", "fleet"], + "data": [ + "views/fsm_vehicle.xml", + "views/fleet_vehicle.xml", + "wizard/fsm_fleet_wizard.xml", ], - 'data': [ - 'views/fsm_vehicle.xml', - 'views/fleet_vehicle.xml', - 'wizard/fsm_fleet_wizard.xml', - ], - 'license': 'AGPL-3', - 'development_status': 'Beta', - 'maintainers': [ - 'wolfhall', - 'max3903', - 'brian10048', - ], - 'pre_init_hook': 'pre_init_hook', - 'installable': True, + "license": "AGPL-3", + "development_status": "Beta", + "maintainers": ["wolfhall", "max3903", "brian10048"], + "pre_init_hook": "pre_init_hook", + "installable": True, } diff --git a/fieldservice_fleet/hooks.py b/fieldservice_fleet/hooks.py index 0a9143c1ca..5bf726e1c5 100644 --- a/fieldservice_fleet/hooks.py +++ b/fieldservice_fleet/hooks.py @@ -6,28 +6,28 @@ def pre_init_hook(cr): # Check for existing fsm vehicles - cr.execute('SELECT * FROM fsm_vehicle') + cr.execute("SELECT * FROM fsm_vehicle") vehicles = [] vehicles = cr.dictfetchall() if vehicles: # Add new columns to hold values - cr.execute('ALTER TABLE fsm_vehicle ADD fleet_vehicle_id INT;') - cr.execute('ALTER TABLE fleet_vehicle ADD is_fsm_vehicle BOOLEAN;') + cr.execute("ALTER TABLE fsm_vehicle ADD fleet_vehicle_id INT;") + cr.execute("ALTER TABLE fleet_vehicle ADD is_fsm_vehicle BOOLEAN;") # Get a fleet vehicle model to set on the new Fleet vehicle(s) env = api.Environment(cr, SUPERUSER_ID, {}) - model_id = env['fleet.vehicle.model'].search([], limit=1).id + model_id = env["fleet.vehicle.model"].search([], limit=1).id # Create a new Fleet vehicle for each FSM vehicle for veh in vehicles: # Get the FSM worker to set as the Fleet driver - fsm_person_id = veh.get('person_id', False) + fsm_person_id = veh.get("person_id", False) driver_id = False if fsm_person_id: - driver_id = env['fsm.person'].browse( - fsm_person_id).partner_id.id + driver_id = env["fsm.person"].browse(fsm_person_id).partner_id.id - cr.execute(""" + cr.execute( + """ INSERT INTO fleet_vehicle ( name, model_id, @@ -42,25 +42,24 @@ def pre_init_hook(cr): True, 'kilometers', True);""", - ( - veh.get('name'), - model_id, - driver_id - ) - ) + (veh.get("name"), model_id, driver_id), + ) # Set this new Fleet vehicle on the existing FSM vehicle - cr.execute(""" + cr.execute( + """ SELECT id FROM fleet_vehicle ORDER BY id desc LIMIT 1 - """) + """ + ) fleet = cr.dictfetchone() - cr.execute(""" + cr.execute( + """ UPDATE fsm_vehicle SET fleet_vehicle_id = %s WHERE id = %s;""", - (fleet.get('id'), veh.get('id')) - ) + (fleet.get("id"), veh.get("id")), + ) diff --git a/fieldservice_fleet/models/fleet_vehicle.py b/fieldservice_fleet/models/fleet_vehicle.py index b8a36510c9..24038b961c 100644 --- a/fieldservice_fleet/models/fleet_vehicle.py +++ b/fieldservice_fleet/models/fleet_vehicle.py @@ -6,27 +6,25 @@ class FleetVehicle(models.Model): - _inherit = 'fleet.vehicle' + _inherit = "fleet.vehicle" - is_fsm_vehicle = fields.Boolean( - string='Is used for Field Service?' - ) + is_fsm_vehicle = fields.Boolean(string="Is used for Field Service?") def set_fsm_driver(self): self.ensure_one() if self.driver_id and self.is_fsm_vehicle: driver_partner = self.driver_id - fsm_worker = self.env['fsm.person'].search( - [('partner_id', '=', driver_partner.id)] + fsm_worker = self.env["fsm.person"].search( + [("partner_id", "=", driver_partner.id)] ) if not fsm_worker: # Create FSM worker - fsm_worker = self.env['fsm.person'].create( - {'partner_id': driver_partner.id} + fsm_worker = self.env["fsm.person"].create( + {"partner_id": driver_partner.id} ) - driver_partner.write({'fsm_person': True}) - fsm_vehicle = self.env['fsm.vehicle'].search( - [('fleet_vehicle_id', '=', self.id)] + driver_partner.write({"fsm_person": True}) + fsm_vehicle = self.env["fsm.vehicle"].search( + [("fleet_vehicle_id", "=", self.id)] ) # Assign the worker to the FSM vehicle fsm_vehicle.person_id = fsm_worker diff --git a/fieldservice_fleet/models/fsm_vehicle.py b/fieldservice_fleet/models/fsm_vehicle.py index 26091dddd7..39f05b67fa 100644 --- a/fieldservice_fleet/models/fsm_vehicle.py +++ b/fieldservice_fleet/models/fsm_vehicle.py @@ -6,40 +6,40 @@ class FSMVehicle(models.Model): - _inherit = 'fsm.vehicle' - _inherits = {'fleet.vehicle': 'fleet_vehicle_id'} + _inherit = "fsm.vehicle" + _inherits = {"fleet.vehicle": "fleet_vehicle_id"} fleet_vehicle_id = fields.Many2one( - 'fleet.vehicle', string='Vehicle Details', - required=True, ondelete='restrict', + "fleet.vehicle", string="Vehicle Details", required=True, ondelete="restrict", ) _sql_constraints = [ - ('fsm_vehicle_fleet_uniq', - 'unique(id,fleet_vehicle_id)', - 'FSM vehicle can only be linked to one fleet vehicle') + ( + "fsm_vehicle_fleet_uniq", + "unique(id,fleet_vehicle_id)", + "FSM vehicle can only be linked to one fleet vehicle", + ) ] @api.model def create(self, vals): - fleet_id = vals.get('fleet_vehicle_id') + fleet_id = vals.get("fleet_vehicle_id") if fleet_id: - if vals.get('person_id', False): - vals['driver_id'] = vals.get('person_id') - vals['is_fsm_vehicle'] = True + if vals.get("person_id", False): + vals["driver_id"] = vals.get("person_id") + vals["is_fsm_vehicle"] = True return super().create(vals) @api.multi def write(self, vals): # update fsm.vehicle worker based on the fleet.vehicle driver - if 'driver_id' in vals: + if "driver_id" in vals: for vehicle in self: if vehicle.is_fsm_vehicle: vehicle.set_fsm_driver() # update fleet.vehicle driver based on the fsm.vehicle worker - fsm_worker_id = vals.get('person_id', False) + fsm_worker_id = vals.get("person_id", False) if fsm_worker_id: - worker_partner = self.env['fsm.person'].browse( - fsm_worker_id).partner_id - vals.update({'driver_id': worker_partner.id}) + worker_partner = self.env["fsm.person"].browse(fsm_worker_id).partner_id + vals.update({"driver_id": worker_partner.id}) return super().write(vals) diff --git a/fieldservice_fleet/static/description/index.html b/fieldservice_fleet/static/description/index.html index 77b7cb9bc0..ea9b423710 100644 --- a/fieldservice_fleet/static/description/index.html +++ b/fieldservice_fleet/static/description/index.html @@ -1,13 +1,15 @@ - - - -Field Service Fleet - - - -
-

Field Service Fleet

- - -

Beta License: AGPL-3 OCA/field-service Translate me on Weblate Try me on Runbot

-

This module allows you to link the vehicles and workers of Field Service with vehicles and drivers of Fleet.

-

Beware that the Fleet module can have more vehicles than the FSM one (not all vehicles of the company are used for Field Service work).

-

Table of contents

- -
-

Installation

-

To install Field Service and have the mapping features, you need to install GeoEngine.

-

Please refer to the installation instructions available at: -https://github.com/OCA/geospatial/tree/12.0/base_geoengine

-
-
-

Configuration

-

Upon installation, any existing FSM Vehicles will have Fleet vehicles created for them.

-

Go to Fleet and review the vehicles created from the existing FSM vehicles

-
    -
  • Update the vehicle model as needed
  • -
  • Update the odometer unit which is set to kilometers by default
  • -
-
-
-

Usage

-

To use this module, you need to:

-

Fleet

-
-
    -
  • Go to Fleet
  • -
  • Create or select a vehicle
  • -
  • From Action menu, choose Convert to FSM Vehicle
  • -
  • A new FSM Vehicle will be created linked to this Fleet Vehicle
  • -
-
-

Field Service

-
-
    -
  • Go to Field Service > Master Data > Vehicles
  • -
  • Select or create a vehicle.
  • -
  • Link to a Fleet Vehicle by assigining one to the vehicle details
  • -
-
-

Changing the Fleet vehicle driver sets the FSM Vehicle worker -Changing the FSM Vehicle worker sets the Fleet Vehicle driver

-
-
-

Known issues / Roadmap

-

The roadmap of the Field Service application is documented on -Github.

-
-
-

Bug Tracker

-

Bugs are tracked on GitHub Issues. -In case of trouble, please check there if your issue has already been reported. -If you spotted it first, help us smashing it by providing a detailed and welcomed -feedback.

-

Do not contact contributors directly about support or help with technical issues.

-
-
-

Credits

-
-

Authors

-
    -
  • Brian McMaster
  • -
  • Open Source Integrators
  • -
-
-
-

Contributors

- -
-
-

Other credits

-

The development of this module has been financially supported by:

- -
-
-

Maintainers

-

This module is maintained by the OCA.

-Odoo Community Association -

OCA, or the Odoo Community Association, is a nonprofit organization whose -mission is to support the collaborative development of Odoo features and -promote its widespread use.

-

Current maintainers:

-

wolfhall max3903 brian10048

-

This module is part of the OCA/field-service project on GitHub.

-

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

-
-
-
- +

+ Beta + License: AGPL-3 + OCA/field-service + Translate me on Weblate + Try me on Runbot +

+

+ This module allows you to link the vehicles and workers of Field Service with + vehicles and drivers of Fleet. +

+

+ Beware that the Fleet module can have more vehicles than the FSM one (not all + vehicles of the company are used for Field Service work). +

+

Table of contents

+
+ +
+
+

Installation

+

+ To install Field Service and have the mapping features, you need to install + GeoEngine. +

+

+ Please refer to the installation instructions available at: + https://github.com/OCA/geospatial/tree/12.0/base_geoengine +

+
+
+

Configuration

+

+ Upon installation, any existing FSM Vehicles will have Fleet vehicles created + for them. +

+

+ Go to Fleet and review the vehicles created from the existing FSM vehicles +

+ +
+
+

Usage

+

To use this module, you need to:

+

Fleet

+
+
    +
  • Go to Fleet
  • +
  • Create or select a vehicle
  • +
  • From Action menu, choose Convert to FSM Vehicle
  • +
  • A new FSM Vehicle will be created linked to this Fleet Vehicle
  • +
+
+

Field Service

+
+
    +
  • Go to Field Service > Master Data > Vehicles
  • +
  • Select or create a vehicle.
  • +
  • Link to a Fleet Vehicle by assigining one to the vehicle details
  • +
+
+

+ Changing the Fleet vehicle driver sets the FSM Vehicle worker Changing the FSM + Vehicle worker sets the Fleet Vehicle driver +

+
+
+

Known issues / Roadmap

+

+ The roadmap of the Field Service application is documented on + Github. +

+
+
+

Bug Tracker

+

+ Bugs are tracked on + GitHub Issues. In case of trouble, please check there if your issue has already been + reported. If you spotted it first, help us smashing it by providing a detailed + and welcomed + feedback. +

+

+ Do not contact contributors directly about support or help with technical + issues. +

+
+
+

Credits

+
+

Authors

+
    +
  • Brian McMaster
  • +
  • Open Source Integrators
  • +
+
+
+

Contributors

+ +
+
+

Other credits

+

The development of this module has been financially supported by:

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ Odoo Community Association +

+ OCA, or the Odoo Community Association, is a nonprofit organization whose + mission is to support the collaborative development of Odoo features and + promote its widespread use. +

+

+ Current + maintainers: +

+

+ wolfhall + max3903 + brian10048 +

+

+ This module is part of the + OCA/field-service + project on GitHub. +

+

+ You are welcome to contribute. To learn how please visit + https://odoo-community.org/page/Contribute. +

+
+
+ + diff --git a/fieldservice_fleet/tests/__init__.py b/fieldservice_fleet/tests/__init__.py index d3cff6fc01..2c297e3189 100644 --- a/fieldservice_fleet/tests/__init__.py +++ b/fieldservice_fleet/tests/__init__.py @@ -1,6 +1,4 @@ # Copyright (C) 2019 Brian McMaster # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from . import ( - test_fsm_fleet_wizard, -) +from . import test_fsm_fleet_wizard diff --git a/fieldservice_fleet/tests/test_fsm_fleet_wizard.py b/fieldservice_fleet/tests/test_fsm_fleet_wizard.py index df56b21632..f20d054874 100644 --- a/fieldservice_fleet/tests/test_fsm_fleet_wizard.py +++ b/fieldservice_fleet/tests/test_fsm_fleet_wizard.py @@ -1,47 +1,47 @@ - # Copyright (C) 2019 Brian McMaster # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo.tests.common import TransactionCase from odoo.exceptions import UserError +from odoo.tests.common import TransactionCase class TestFSMFleetWizard(TransactionCase): - def setUp(self): super(TestFSMFleetWizard, self).setUp() - self.Wizard = self.env['fsm.fleet.wizard'] - self.fleet_vehicle_1 = self.env.ref('fleet.vehicle_1') + self.Wizard = self.env["fsm.fleet.wizard"] + self.fleet_vehicle_1 = self.env.ref("fleet.vehicle_1") def test_convert_vehicle(self): # Convert a Fleet vehicle to FSM vehicle and link it self.Wizard.action_convert_vehicle(self.fleet_vehicle_1) # Search FSM vehicle records linked to the test Fleet vehicle - fsm_vehicle = self.env['fsm.vehicle'].search([ - ('fleet_vehicle_id', '=', self.fleet_vehicle_1.id) - ]) + fsm_vehicle = self.env["fsm.vehicle"].search( + [("fleet_vehicle_id", "=", self.fleet_vehicle_1.id)] + ) self.assertEqual( - len(fsm_vehicle), 1, + len(fsm_vehicle), + 1, """FSM Fleet Wizard: Did not find FSM vehicle - linked to Fleet vehicle""" + linked to Fleet vehicle""", ) self.assertEqual( - fsm_vehicle.name, self.fleet_vehicle_1.name, + fsm_vehicle.name, + self.fleet_vehicle_1.name, """FSM Fleet Wizard: FSM Vehicle and Fleet Vehicle - names do not match""" + names do not match""", ) self.assertTrue( self.fleet_vehicle_1.is_fsm_vehicle, """FSM Fleet Wizard: Fleet vehicle boolean field - is_fsm_vehicle is False""" + is_fsm_vehicle is False""", ) self.assertEqual( fsm_vehicle.person_id.partner_id, self.fleet_vehicle_1.driver_id, """FSM Fleet Wizard: FSM vehicle driver is not same - as the Fleet vehicle driver""" + as the Fleet vehicle driver""", ) # Attempt to convert the Fleet vehicle again, but expect UserError @@ -50,8 +50,7 @@ def test_convert_vehicle(self): self.Wizard.action_convert_vehicle(self.fleet_vehicle_1) self.assertEqual( e.exception.name, - 'A Field Service Vehicle related to that' - ' Fleet Vehicle already exists.', + "A Field Service Vehicle related to that" " Fleet Vehicle already exists.", """FSM Fleet Wizard: UserError not thrown when converting - Fleet vehicle already linked to FSM Vehicle.""" + Fleet vehicle already linked to FSM Vehicle.""", ) diff --git a/fieldservice_fleet/views/fleet_vehicle.xml b/fieldservice_fleet/views/fleet_vehicle.xml index 37ff144bb2..be3d87fc7e 100644 --- a/fieldservice_fleet/views/fleet_vehicle.xml +++ b/fieldservice_fleet/views/fleet_vehicle.xml @@ -1,15 +1,12 @@ - fleet.vehicle.form.fsm fleet.vehicle - + - + - diff --git a/fieldservice_fleet/views/fsm_vehicle.xml b/fieldservice_fleet/views/fsm_vehicle.xml index b53d27c859..caa1268dbd 100644 --- a/fieldservice_fleet/views/fsm_vehicle.xml +++ b/fieldservice_fleet/views/fsm_vehicle.xml @@ -1,14 +1,12 @@ - fsm.vehicle.form.fleet fsm.vehicle - + - + - diff --git a/fieldservice_fleet/wizard/fsm_fleet_wizard.py b/fieldservice_fleet/wizard/fsm_fleet_wizard.py index 5e2b33211c..283021198a 100644 --- a/fieldservice_fleet/wizard/fsm_fleet_wizard.py +++ b/fieldservice_fleet/wizard/fsm_fleet_wizard.py @@ -2,7 +2,7 @@ # Copyright (C) 2019 Brian McMaster # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import api, models, _ +from odoo import _, api, models from odoo.exceptions import UserError @@ -10,31 +10,36 @@ class FSMFleetWizard(models.TransientModel): """ A wizard to convert a fleet.vehicle record to a fsm.vehicle """ - _name = 'fsm.fleet.wizard' - _description = 'FSM Fleet Vehicle Conversion' + + _name = "fsm.fleet.wizard" + _description = "FSM Fleet Vehicle Conversion" @api.multi def action_convert(self): - vehicles = self.env['fleet.vehicle'].browse( - self._context.get('active_ids', [])) + vehicles = self.env["fleet.vehicle"].browse(self._context.get("active_ids", [])) for vehicle in vehicles: self.action_convert_vehicle(vehicle) - return {'type': 'ir.actions.act_window_close'} + return {"type": "ir.actions.act_window_close"} def _prepare_fsm_vehicle(self, vehicle): return { - 'fleet_vehicle_id': vehicle.id, - 'name': vehicle.name, + "fleet_vehicle_id": vehicle.id, + "name": vehicle.name, } def action_convert_vehicle(self, vehicle): - res = self.env['fsm.vehicle'].search_count( - [('fleet_vehicle_id', '=', vehicle.id)]) + res = self.env["fsm.vehicle"].search_count( + [("fleet_vehicle_id", "=", vehicle.id)] + ) if res == 0: vals = self._prepare_fsm_vehicle(vehicle) - self.env['fsm.vehicle'].create(vals) - vehicle.write({'is_fsm_vehicle': True}) + self.env["fsm.vehicle"].create(vals) + vehicle.write({"is_fsm_vehicle": True}) vehicle.set_fsm_driver() else: - raise UserError(_('A Field Service Vehicle related to that' - ' Fleet Vehicle already exists.')) + raise UserError( + _( + "A Field Service Vehicle related to that" + " Fleet Vehicle already exists." + ) + ) diff --git a/fieldservice_fleet/wizard/fsm_fleet_wizard.xml b/fieldservice_fleet/wizard/fsm_fleet_wizard.xml index 815978cd32..706e86804d 100644 --- a/fieldservice_fleet/wizard/fsm_fleet_wizard.xml +++ b/fieldservice_fleet/wizard/fsm_fleet_wizard.xml @@ -1,16 +1,16 @@ - - - + Convert to a FSM Vehicle @@ -21,11 +21,15 @@ Convert this vehicle record into a Field Service Vehicle. -