From c6ff256db0be7f00bf3559bb60ad29f3162782eb Mon Sep 17 00:00:00 2001 From: Murtuza Saleh Date: Wed, 26 Feb 2020 19:31:12 +0530 Subject: [PATCH] [WIP][13.0][MIG] fieldservice --- .isort.cfg | 2 +- fieldservice/README.rst | 40 +- fieldservice/__init__.py | 1 - fieldservice/__manifest__.py | 107 ++-- fieldservice/data/fsm_team.xml | 1 - fieldservice/data/ir_sequence.xml | 10 - fieldservice/data/mail_message_subtype.xml | 1 - fieldservice/data/module_category.xml | 1 - fieldservice/demo/fsm_demo.xml | 17 - fieldservice/demo/fsm_location.xml | 12 +- fieldservice/i18n/de.po | 13 + fieldservice/i18n/es.po | 13 + fieldservice/i18n/es_CL.po | 13 + fieldservice/i18n/fieldservice.pot | 11 + fieldservice/i18n/fr.po | 11 + fieldservice/i18n/pt_BR.po | 25 +- fieldservice/models/__init__.py | 10 +- fieldservice/models/fsm_branch.py | 14 - fieldservice/models/fsm_category.py | 26 +- fieldservice/models/fsm_district.py | 14 - fieldservice/models/fsm_equipment.py | 104 ++-- fieldservice/models/fsm_location.py | 371 ++++++------ fieldservice/models/fsm_location_person.py | 37 +- fieldservice/models/fsm_order.py | 548 +++++++++--------- fieldservice/models/fsm_order_type.py | 10 + fieldservice/models/fsm_person.py | 137 +++-- fieldservice/models/fsm_region.py | 13 - fieldservice/models/fsm_route.py | 36 -- fieldservice/models/fsm_stage.py | 136 +++-- fieldservice/models/fsm_tag.py | 26 +- fieldservice/models/fsm_team.py | 103 ++-- fieldservice/models/fsm_template.py | 28 +- fieldservice/models/fsm_territory.py | 30 - fieldservice/models/res_company.py | 8 +- fieldservice/models/res_config_settings.py | 120 ++-- fieldservice/models/res_country.py | 10 - fieldservice/models/res_partner.py | 51 +- fieldservice/models/res_state.py | 10 - fieldservice/models/res_territory.py | 11 + fieldservice/readme/CONFIGURE.rst | 15 +- fieldservice/readme/INSTALL.rst | 11 - .../report/fsm_order_report_template.xml | 10 +- fieldservice/security/ir.model.access.csv | 14 +- fieldservice/security/ir_rule.xml | 14 +- fieldservice/security/res_groups.xml | 6 - fieldservice/static/description/index.html | 121 ++-- fieldservice/static/src/js/fsm_gantt.js | 221 ------- .../static/src/js/fsm_gantt_person_filter.js | 311 ---------- .../src/scss/fsm_gantt_person_filter.scss | 10 - .../src/xml/fsm_gantt_person_filter.xml | 28 - fieldservice/tests/__init__.py | 1 - fieldservice/tests/test_fsm_equipment.py | 41 +- fieldservice/tests/test_fsm_location.py | 180 +++--- fieldservice/tests/test_fsm_order.py | 43 +- .../tests/test_fsm_order_template_onchange.py | 71 +-- fieldservice/tests/test_fsm_person.py | 21 +- fieldservice/tests/test_fsm_team.py | 33 +- fieldservice/tests/test_fsm_wizard.py | 27 +- fieldservice/views/fsm_branch.xml | 47 -- fieldservice/views/fsm_category.xml | 2 - fieldservice/views/fsm_district.xml | 47 -- fieldservice/views/fsm_equipment.xml | 6 +- fieldservice/views/fsm_location.xml | 7 - fieldservice/views/fsm_location_person.xml | 3 - fieldservice/views/fsm_order.xml | 59 +- fieldservice/views/fsm_order_type.xml | 35 ++ fieldservice/views/fsm_person.xml | 3 - fieldservice/views/fsm_region.xml | 45 -- fieldservice/views/fsm_route.xml | 111 ---- fieldservice/views/fsm_schedule.xml | 41 -- fieldservice/views/fsm_stage.xml | 5 +- fieldservice/views/fsm_tag.xml | 2 - fieldservice/views/fsm_team.xml | 5 +- fieldservice/views/fsm_template.xml | 2 - fieldservice/views/fsm_territory.xml | 74 --- fieldservice/views/menu.xml | 62 +- fieldservice/views/res_config_settings.xml | 213 +++++-- fieldservice/views/res_partner.xml | 8 +- fieldservice/views/res_territory.xml | 29 + fieldservice/wizard/__init__.py | 1 - fieldservice/wizard/fsm_wizard.py | 56 +- fieldservice/wizard/fsm_wizard.xml | 5 +- oca_dependencies.txt | 1 + 83 files changed, 1647 insertions(+), 2531 deletions(-) delete mode 100644 fieldservice/models/fsm_branch.py delete mode 100644 fieldservice/models/fsm_district.py create mode 100644 fieldservice/models/fsm_order_type.py delete mode 100644 fieldservice/models/fsm_region.py delete mode 100644 fieldservice/models/fsm_route.py delete mode 100644 fieldservice/models/fsm_territory.py delete mode 100644 fieldservice/models/res_country.py delete mode 100644 fieldservice/models/res_state.py create mode 100644 fieldservice/models/res_territory.py delete mode 100644 fieldservice/readme/INSTALL.rst delete mode 100644 fieldservice/static/src/js/fsm_gantt.js delete mode 100644 fieldservice/static/src/js/fsm_gantt_person_filter.js delete mode 100644 fieldservice/static/src/scss/fsm_gantt_person_filter.scss delete mode 100644 fieldservice/static/src/xml/fsm_gantt_person_filter.xml delete mode 100644 fieldservice/views/fsm_branch.xml delete mode 100644 fieldservice/views/fsm_district.xml create mode 100644 fieldservice/views/fsm_order_type.xml delete mode 100644 fieldservice/views/fsm_region.xml delete mode 100644 fieldservice/views/fsm_route.xml delete mode 100644 fieldservice/views/fsm_schedule.xml delete mode 100644 fieldservice/views/fsm_territory.xml create mode 100644 fieldservice/views/res_territory.xml create mode 100644 oca_dependencies.txt diff --git a/.isort.cfg b/.isort.cfg index 5751c40dd2..98b216f744 100644 --- a/.isort.cfg +++ b/.isort.cfg @@ -9,4 +9,4 @@ line_length=88 known_odoo=odoo known_odoo_addons=odoo.addons sections=FUTURE,STDLIB,THIRDPARTY,ODOO,ODOO_ADDONS,FIRSTPARTY,LOCALFOLDER -known_third_party= +known_third_party=setuptools diff --git a/fieldservice/README.rst b/fieldservice/README.rst index b9461e79ca..4f998d73ec 100644 --- a/fieldservice/README.rst +++ b/fieldservice/README.rst @@ -14,13 +14,13 @@ Field Service :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Ffield--service-lightgray.png?logo=github - :target: https://github.com/OCA/field-service/tree/12.0/fieldservice + :target: https://github.com/OCA/field-service/tree/13.0/fieldservice :alt: OCA/field-service .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/field-service-12-0/field-service-12-0-fieldservice + :target: https://translation.odoo-community.org/projects/field-service-13-0/field-service-13-0-fieldservice :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png - :target: https://runbot.odoo-community.org/runbot/264/12.0 + :target: https://runbot.odoo-community.org/runbot/264/13.0 :alt: Try me on Runbot |badge1| |badge2| |badge3| |badge4| |badge5| @@ -32,21 +32,6 @@ This module is the base of the Field Service application in Odoo. .. contents:: :local: -Installation -============ - -As of version 12, you can install Field Service alone without mapping features. - -To install Field Service and have the mapping features, you need to install GeoEngine. -GeoEngine requires you to have `PostGIS `_ installed and also -install two additional python libs: - -* `Shapely `_ -* `geojson `_ - -Please refer to the installation instructions available at: -https://github.com/OCA/geospatial/tree/12.0/base_geoengine - Configuration ============= @@ -68,15 +53,6 @@ comes pre-configured for use. #. Select *Order* type to apply this stage to your orders. #. Additonally, you can set a color for the stage. -You need to add attribute mention below with the tag as base element. - -* colors (optional): it allows to set certain specific colors if the expressed - condition (JS syntax) is met. -* custom_color (optional): it allows to set custom color for fsm.stages - example custom_color = "true". And there is minor condition to follow to - implement this as. Define any one stage color condition like - colors="#ffffff:stage_id=='New';" - Field Service Areas ~~~~~~~~~~~~~~~~~~~ @@ -89,12 +65,12 @@ are managed under an encompassing Region. Setup a Territory ----------------- -#. Go to *Field Service > Configuration > Locations > Territories* +#. Go to Settings > Users & Companies > Territories* #. Create or select a territory #. Set the territory Name and description #. Select or create a branch which this territory serves -#. Choose a type of zip, state, or country whichs defines the boundary used -#. Input a list of zip codes, states, or countries based on your desired +#. Choose a type of zip, country whichs defines the boundary used +#. Input a list of zip codes, countries based on your desired configuration Setup Branches, Districts, and Regions @@ -205,7 +181,7 @@ 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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -261,6 +237,6 @@ Current `maintainers `__: |maintainer-wolfhall| |maintainer-max3903| -This module is part of the `OCA/field-service `_ project on GitHub. +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/__init__.py b/fieldservice/__init__.py index 13d8d1168f..4d7a49b5e2 100644 --- a/fieldservice/__init__.py +++ b/fieldservice/__init__.py @@ -1,4 +1,3 @@ -# Copyright (C) 2018 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from . import models diff --git a/fieldservice/__manifest__.py b/fieldservice/__manifest__.py index 811372808a..647d5b4c16 100644 --- a/fieldservice/__manifest__.py +++ b/fieldservice/__manifest__.py @@ -2,66 +2,55 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { - 'name': 'Field Service', - 'summary': 'Manage Field Service Locations, Workers and Orders', - 'version': '12.0.2.3.3', - 'category': 'Field Service', - 'author': 'Open Source Integrators, Odoo Community Association (OCA)', - 'website': 'https://github.com/OCA/field-service', - 'depends': [ - 'base_geolocalize', - 'mail', - 'web_timeline', - 'resource', - 'contacts', - 'partner_fax' + "name": "Field Service", + "summary": "Manage Field Service Locations, Workers and Orders", + "version": "13.0.1.0.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", + "partner_fax", ], - '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/fsm_territory.xml', - 'views/fsm_branch.xml', - 'views/fsm_district.xml', - 'views/fsm_region.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_route.xml', - 'views/fsm_schedule.xml', - 'views/fsm_category.xml', - 'views/fsm_equipment.xml', - 'views/fsm_template.xml', - 'views/fsm_team.xml', - 'views/menu.xml', - 'wizard/fsm_wizard.xml', + "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', - ], - 'qweb': [ - 'static/src/xml/*.xml', - ], - 'application': True, - 'license': 'AGPL-3', - 'development_status': 'Beta', - 'maintainers': [ - 'wolfhall', - 'max3903', + "demo": [ + "demo/fsm_demo.xml", + "demo/fsm_equipment.xml", + "demo/fsm_location.xml", + "demo/fsm_person.xml", ], + "application": True, + "development_status": "Beta", + "maintainers": ["wolfhall", "max3903"], } diff --git a/fieldservice/data/fsm_team.xml b/fieldservice/data/fsm_team.xml index e3ed06d4ec..ce89e3a0c4 100644 --- a/fieldservice/data/fsm_team.xml +++ b/fieldservice/data/fsm_team.xml @@ -1,4 +1,3 @@ - diff --git a/fieldservice/data/ir_sequence.xml b/fieldservice/data/ir_sequence.xml index 4d8e713315..5f6310c670 100644 --- a/fieldservice/data/ir_sequence.xml +++ b/fieldservice/data/ir_sequence.xml @@ -1,4 +1,3 @@ - @@ -10,13 +9,4 @@ - - - FSM Route - fsm.route - SR - 3 - - - diff --git a/fieldservice/data/mail_message_subtype.xml b/fieldservice/data/mail_message_subtype.xml index 3924dbb708..d728623e46 100644 --- a/fieldservice/data/mail_message_subtype.xml +++ b/fieldservice/data/mail_message_subtype.xml @@ -1,4 +1,3 @@ - diff --git a/fieldservice/data/module_category.xml b/fieldservice/data/module_category.xml index 4fd7c0ba17..8c8c2b68ed 100644 --- a/fieldservice/data/module_category.xml +++ b/fieldservice/data/module_category.xml @@ -1,4 +1,3 @@ - diff --git a/fieldservice/demo/fsm_demo.xml b/fieldservice/demo/fsm_demo.xml index 5a33817961..64f26ab43f 100644 --- a/fieldservice/demo/fsm_demo.xml +++ b/fieldservice/demo/fsm_demo.xml @@ -50,21 +50,4 @@ tp@email.com - - - Test Region - - - Test District - - - - Test Branch - - - - Test Territory - - - diff --git a/fieldservice/demo/fsm_location.xml b/fieldservice/demo/fsm_location.xml index 5a1a357c06..0a5830c149 100644 --- a/fieldservice/demo/fsm_location.xml +++ b/fieldservice/demo/fsm_location.xml @@ -24,11 +24,10 @@ tp@email.com - - - - - + + + + New the old inventory 14 Tower A, main street Bangkok, Thailand @@ -39,20 +38,17 @@ Location 1 - Location 2 - Location 3 - diff --git a/fieldservice/i18n/de.po b/fieldservice/i18n/de.po index 06f92dcbbb..dfe4a8dc3b 100644 --- a/fieldservice/i18n/de.po +++ b/fieldservice/i18n/de.po @@ -1783,6 +1783,13 @@ msgstr "" msgid "Manage Order Activities" msgstr "Aktivitäten" +#. module: fieldservice +#: model_terms:ir.ui.view,arch_db:fieldservice.res_config_settings_view_form +#, fuzzy +#| msgid "Activities" +msgid "Manage Order Sizes" +msgstr "Aktivitäten" + #. module: fieldservice #: model_terms:ir.ui.view,arch_db:fieldservice.res_config_settings_view_form msgid "Manage Order Sub-Statuses" @@ -1885,6 +1892,12 @@ msgstr "Aktivitäten" msgid "Manage routes of yoru workers" msgstr "" +#. module: fieldservice +#: model:ir.model.fields,field_description:fieldservice.field_res_config_settings__module_fieldservice_size +#: model_terms:ir.ui.view,arch_db:fieldservice.res_config_settings_view_form +msgid "Manage sizes for orders and locations" +msgstr "" + #. module: fieldservice #: model_terms:ir.ui.view,arch_db:fieldservice.res_config_settings_view_form msgid "Manage sub-statuses" diff --git a/fieldservice/i18n/es.po b/fieldservice/i18n/es.po index a51f59bfa7..f10b1b12df 100644 --- a/fieldservice/i18n/es.po +++ b/fieldservice/i18n/es.po @@ -1813,6 +1813,13 @@ msgstr "Gestionar Categorías de Trabajador de Servicio de Campo" msgid "Manage Order Activities" msgstr "Gestionar Actividades de Pedidos" +#. module: fieldservice +#: model_terms:ir.ui.view,arch_db:fieldservice.res_config_settings_view_form +#, fuzzy +#| msgid "Manage Order Activities" +msgid "Manage Order Sizes" +msgstr "Gestionar Actividades de Pedidos" + #. module: fieldservice #: model_terms:ir.ui.view,arch_db:fieldservice.res_config_settings_view_form msgid "Manage Order Sub-Statuses" @@ -1915,6 +1922,12 @@ msgstr "Gestionar Rutas" msgid "Manage routes of yoru workers" msgstr "Administra las rutas de tus trabajadores" +#. module: fieldservice +#: model:ir.model.fields,field_description:fieldservice.field_res_config_settings__module_fieldservice_size +#: model_terms:ir.ui.view,arch_db:fieldservice.res_config_settings_view_form +msgid "Manage sizes for orders and locations" +msgstr "" + #. module: fieldservice #: model_terms:ir.ui.view,arch_db:fieldservice.res_config_settings_view_form msgid "Manage sub-statuses" diff --git a/fieldservice/i18n/es_CL.po b/fieldservice/i18n/es_CL.po index 1887f64499..c526597598 100644 --- a/fieldservice/i18n/es_CL.po +++ b/fieldservice/i18n/es_CL.po @@ -1813,6 +1813,13 @@ msgstr "Gestionar Categorías de Trabajador de Servicio de Campo" msgid "Manage Order Activities" msgstr "Gestionar Actividades de Pedidos" +#. module: fieldservice +#: model_terms:ir.ui.view,arch_db:fieldservice.res_config_settings_view_form +#, fuzzy +#| msgid "Manage Order Activities" +msgid "Manage Order Sizes" +msgstr "Gestionar Actividades de Pedidos" + #. module: fieldservice #: model_terms:ir.ui.view,arch_db:fieldservice.res_config_settings_view_form msgid "Manage Order Sub-Statuses" @@ -1915,6 +1922,12 @@ msgstr "Gestionar Rutas" msgid "Manage routes of yoru workers" msgstr "Administra las rutas de tus trabajadores" +#. module: fieldservice +#: model:ir.model.fields,field_description:fieldservice.field_res_config_settings__module_fieldservice_size +#: model_terms:ir.ui.view,arch_db:fieldservice.res_config_settings_view_form +msgid "Manage sizes for orders and locations" +msgstr "" + #. module: fieldservice #: model_terms:ir.ui.view,arch_db:fieldservice.res_config_settings_view_form msgid "Manage sub-statuses" diff --git a/fieldservice/i18n/fieldservice.pot b/fieldservice/i18n/fieldservice.pot index f91f5d56ed..277d08eeb1 100644 --- a/fieldservice/i18n/fieldservice.pot +++ b/fieldservice/i18n/fieldservice.pot @@ -1751,6 +1751,11 @@ msgstr "" msgid "Manage Order Activities" msgstr "" +#. module: fieldservice +#: model_terms:ir.ui.view,arch_db:fieldservice.res_config_settings_view_form +msgid "Manage Order Sizes" +msgstr "" + #. module: fieldservice #: model_terms:ir.ui.view,arch_db:fieldservice.res_config_settings_view_form msgid "Manage Order Sub-Statuses" @@ -1847,6 +1852,12 @@ msgstr "" msgid "Manage routes of yoru workers" msgstr "" +#. module: fieldservice +#: model:ir.model.fields,field_description:fieldservice.field_res_config_settings__module_fieldservice_size +#: model_terms:ir.ui.view,arch_db:fieldservice.res_config_settings_view_form +msgid "Manage sizes for orders and locations" +msgstr "" + #. module: fieldservice #: model_terms:ir.ui.view,arch_db:fieldservice.res_config_settings_view_form msgid "Manage sub-statuses" diff --git a/fieldservice/i18n/fr.po b/fieldservice/i18n/fr.po index 1a1c184942..93c9d7802e 100644 --- a/fieldservice/i18n/fr.po +++ b/fieldservice/i18n/fr.po @@ -1775,6 +1775,11 @@ msgstr "" msgid "Manage Order Activities" msgstr "" +#. module: fieldservice +#: model_terms:ir.ui.view,arch_db:fieldservice.res_config_settings_view_form +msgid "Manage Order Sizes" +msgstr "" + #. module: fieldservice #: model_terms:ir.ui.view,arch_db:fieldservice.res_config_settings_view_form msgid "Manage Order Sub-Statuses" @@ -1873,6 +1878,12 @@ msgstr "" msgid "Manage routes of yoru workers" msgstr "" +#. module: fieldservice +#: model:ir.model.fields,field_description:fieldservice.field_res_config_settings__module_fieldservice_size +#: model_terms:ir.ui.view,arch_db:fieldservice.res_config_settings_view_form +msgid "Manage sizes for orders and locations" +msgstr "" + #. module: fieldservice #: model_terms:ir.ui.view,arch_db:fieldservice.res_config_settings_view_form msgid "Manage sub-statuses" diff --git a/fieldservice/i18n/pt_BR.po b/fieldservice/i18n/pt_BR.po index 9c36268144..9ab411ea47 100644 --- a/fieldservice/i18n/pt_BR.po +++ b/fieldservice/i18n/pt_BR.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 12.0\n" "Report-Msgid-Bugs-To: \n" -"PO-Revision-Date: 2020-02-13 00:12+0000\n" +"PO-Revision-Date: 2020-02-25 09:13+0000\n" "Last-Translator: Marcel Savegnago \n" "Language-Team: none\n" "Language: pt_BR\n" @@ -457,7 +457,7 @@ msgid "" "orders." msgstr "" "Marque esta caixa se este contacto for um cliente. Ele pode ser selecionado " -"em ordens de venda." +"em pedidos de venda." #. module: fieldservice #: model:ir.model.fields,help:fieldservice.field_fsm_location__supplier @@ -1809,6 +1809,13 @@ msgstr "Gerenciar Categorias de Trabalhadores de Serviço de Campo" msgid "Manage Order Activities" msgstr "Gerenciar Atividades da Ordem" +#. module: fieldservice +#: model_terms:ir.ui.view,arch_db:fieldservice.res_config_settings_view_form +#, fuzzy +#| msgid "Manage Order Activities" +msgid "Manage Order Sizes" +msgstr "Gerenciar Atividades da Ordem" + #. module: fieldservice #: model_terms:ir.ui.view,arch_db:fieldservice.res_config_settings_view_form msgid "Manage Order Sub-Statuses" @@ -1907,6 +1914,12 @@ msgstr "Gerenciar Rotas" msgid "Manage routes of yoru workers" msgstr "Gerenciar rotas de seus trabalhadores" +#. module: fieldservice +#: model:ir.model.fields,field_description:fieldservice.field_res_config_settings__module_fieldservice_size +#: model_terms:ir.ui.view,arch_db:fieldservice.res_config_settings_view_form +msgid "Manage sizes for orders and locations" +msgstr "" + #. module: fieldservice #: model_terms:ir.ui.view,arch_db:fieldservice.res_config_settings_view_form msgid "Manage sub-statuses" @@ -2008,7 +2021,7 @@ msgstr "Mensagem para Ordem de Compra" #: model:ir.model.fields,field_description:fieldservice.field_fsm_location__sale_warn_msg #: model:ir.model.fields,field_description:fieldservice.field_fsm_person__sale_warn_msg msgid "Message for Sales Order" -msgstr "Mensagem para Ordem de Vendas" +msgstr "Mensagem para Pedido de Vendas" #. module: fieldservice #: model:ir.model.fields,field_description:fieldservice.field_fsm_location__picking_warn_msg @@ -2596,13 +2609,13 @@ msgstr "Rotas" #: model:ir.model.fields,field_description:fieldservice.field_fsm_location__sale_order_count #: model:ir.model.fields,field_description:fieldservice.field_fsm_person__sale_order_count msgid "Sale Order Count" -msgstr "Contagem de Ordens de Venda" +msgstr "Contagem de Pedidos de Venda" #. module: fieldservice #: model:ir.model.fields,field_description:fieldservice.field_fsm_location__sale_order_ids #: model:ir.model.fields,field_description:fieldservice.field_fsm_person__sale_order_ids msgid "Sales Order" -msgstr "Ordens de Venda" +msgstr "Pedidos de Venda" #. module: fieldservice #: model:ir.model.fields,field_description:fieldservice.field_fsm_location__team_id @@ -2672,7 +2685,7 @@ msgstr "" #. module: fieldservice #: model_terms:ir.ui.view,arch_db:fieldservice.res_config_settings_view_form msgid "Select field services on sale orders." -msgstr "Selecione serviços de campo em ordens de venda." +msgstr "Selecione serviços de campo em pedidos de venda." #. module: fieldservice #: model_terms:ir.ui.view,arch_db:fieldservice.partner_wizard_view diff --git a/fieldservice/models/__init__.py b/fieldservice/models/__init__.py index 7cd592fb73..3b28d3665f 100644 --- a/fieldservice/models/__init__.py +++ b/fieldservice/models/__init__.py @@ -1,4 +1,3 @@ -# Copyright (C) 2018 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from . import ( @@ -6,10 +5,7 @@ res_config_settings, fsm_category, fsm_template, - fsm_region, - fsm_district, - fsm_branch, - fsm_territory, + res_territory, fsm_tag, fsm_stage, fsm_team, @@ -17,9 +13,7 @@ fsm_location, fsm_location_person, res_partner, - res_state, - res_country, fsm_equipment, fsm_order, - fsm_route, + fsm_order_type, ) diff --git a/fieldservice/models/fsm_branch.py b/fieldservice/models/fsm_branch.py deleted file mode 100644 index db3bed990d..0000000000 --- a/fieldservice/models/fsm_branch.py +++ /dev/null @@ -1,14 +0,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 FSMBranch(models.Model): - _name = 'fsm.branch' - _description = 'branch' - - name = fields.Char(string='Name', required=True) - partner_id = fields.Many2one('res.partner', string='Branch Manager') - district_id = fields.Many2one('fsm.district', string='District') - description = fields.Char(string='Description') diff --git a/fieldservice/models/fsm_category.py b/fieldservice/models/fsm_category.py index 48f764cc70..6c12206d9b 100644 --- a/fieldservice/models/fsm_category.py +++ b/fieldservice/models/fsm_category.py @@ -5,26 +5,28 @@ class FSMCategory(models.Model): - _name = 'fsm.category' - _description = 'Field Service Worker Category' + _name = "fsm.category" + _description = "Field Service Worker Category" - name = fields.Char(string='Name', required='True') - parent_id = fields.Many2one('fsm.category', string='Parent') - color = fields.Integer('Color Index', default=10) + name = fields.Char(string="Name", required="True") + parent_id = fields.Many2one("fsm.category", string="Parent") + color = fields.Integer("Color Index", default=10) full_name = fields.Char(string="Full Name", compute="_compute_full_name") - description = fields.Char(string='Description') + description = fields.Char(string="Description") company_id = fields.Many2one( - 'res.company', string='Company', required=True, index=True, + "res.company", + string="Company", + required=True, + index=True, default=lambda self: self.env.user.company_id, - help="Company related to this category") + help="Company related to this category", + ) - _sql_constraints = [ - ('name_uniq', 'unique (name)', "Category name already exists!"), - ] + _sql_constraints = [("name_uniq", "unique (name)", "Category name already exists!")] def _compute_full_name(self): for record in self: if record.parent_id: - record.full_name = (record.parent_id.name + '/' + record.name) + record.full_name = record.parent_id.name + "/" + record.name else: record.full_name = record.name diff --git a/fieldservice/models/fsm_district.py b/fieldservice/models/fsm_district.py deleted file mode 100644 index 87d4bb7962..0000000000 --- a/fieldservice/models/fsm_district.py +++ /dev/null @@ -1,14 +0,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 FSMDistrict(models.Model): - _name = 'fsm.district' - _description = 'District' - - name = fields.Char(string='Name', required=True) - region_id = fields.Many2one('fsm.region', string='Region') - partner_id = fields.Many2one('res.partner', string='District Manager') - description = fields.Char(string='Description') diff --git a/fieldservice/models/fsm_equipment.py b/fieldservice/models/fsm_equipment.py index ecf26168c9..08884a75ad 100644 --- a/fieldservice/models/fsm_equipment.py +++ b/fieldservice/models/fsm_equipment.py @@ -1,98 +1,106 @@ # Copyright (C) 2018 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import fields, models, api +from odoo import api, fields, models class FSMEquipment(models.Model): - _name = 'fsm.equipment' - _description = 'Field Service Equipment' - _inherit = ['mail.thread', 'mail.activity.mixin'] + _name = "fsm.equipment" + _description = "Field Service Equipment" + _inherit = ["mail.thread", "mail.activity.mixin"] - name = fields.Char(string='Name', required='True') - person_id = fields.Many2one('fsm.person', string='Assigned Operator') - location_id = fields.Many2one('fsm.location', string='Assigned Location') - notes = fields.Text(string='Notes') - territory_id = fields.Many2one('fsm.territory', string='Territory') - branch_id = fields.Many2one('fsm.branch', string='Branch') - district_id = fields.Many2one('fsm.district', string='District') - region_id = fields.Many2one('fsm.region', string='Region') - current_location_id = fields.Many2one('fsm.location', - string='Current Location', - required=True) + name = fields.Char(string="Name", required="True") + person_id = fields.Many2one("fsm.person", string="Assigned Operator") + location_id = fields.Many2one("fsm.location", string="Assigned Location") + notes = fields.Text(string="Notes") + 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", required=True + ) - 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') - stage_id = fields.Many2one('fsm.stage', string='Stage', - track_visibility='onchange', - index=True, copy=False, - group_expand='_read_group_stage_ids', - default=lambda self: self._default_stage_id()) + 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") + stage_id = fields.Many2one( + "fsm.stage", + string="Stage", + track_visibility="onchange", + index=True, + copy=False, + group_expand="_read_group_stage_ids", + default=lambda self: self._default_stage_id(), + ) hide = fields.Boolean(default=False) - color = fields.Integer('Color Index') + color = fields.Integer("Color Index") company_id = fields.Many2one( - 'res.company', string='Company', required=True, index=True, + "res.company", + string="Company", + required=True, + index=True, default=lambda self: self.env.user.company_id, - help="Company related to this equipment") + help="Company related to this equipment", + ) _sql_constraints = [ - ('name_uniq', 'unique (name)', "Equipment name already exists!"), + ("name_uniq", "unique (name)", "Equipment name already exists!") ] - @api.onchange('location_id') + @api.onchange("location_id") def _onchange_location_id(self): self.territory_id = self.location_id.territory_id - @api.onchange('territory_id') + @api.onchange("territory_id") def _onchange_territory_id(self): self.branch_id = self.territory_id.branch_id - @api.onchange('branch_id') + @api.onchange("branch_id") def _onchange_branch_id(self): self.district_id = self.branch_id.district_id - @api.onchange('district_id') + @api.onchange("district_id") def _onchange_district_id(self): self.region_id = self.district_id.region_id @api.model def _read_group_stage_ids(self, stages, domain, order): - stage_ids = self.env['fsm.stage'].search([('stage_type', - '=', 'equipment')]) + stage_ids = self.env["fsm.stage"].search([("stage_type", "=", "equipment")]) return stage_ids def _default_stage_id(self): - return self.env['fsm.stage'].search([('stage_type', '=', 'equipment'), - ('sequence', '=', '1')]) + return self.env["fsm.stage"].search( + [("stage_type", "=", "equipment"), ("sequence", "=", "1")] + ) def next_stage(self): seq = self.stage_id.sequence - next_stage = self.env['fsm.stage'].search( - [('stage_type', '=', 'equipment'), ('sequence', '>', seq)], - order="sequence asc") + next_stage = self.env["fsm.stage"].search( + [("stage_type", "=", "equipment"), ("sequence", ">", seq)], + order="sequence asc", + ) if next_stage: self.stage_id = next_stage[0] self._onchange_stage_id() def previous_stage(self): seq = self.stage_id.sequence - prev_stage = self.env['fsm.stage'].search( - [('stage_type', '=', 'equipment'), ('sequence', '<', seq)], - order="sequence desc") + prev_stage = self.env["fsm.stage"].search( + [("stage_type", "=", "equipment"), ("sequence", "<", seq)], + order="sequence desc", + ) if prev_stage: self.stage_id = prev_stage[0] self._onchange_stage_id() - @api.onchange('stage_id') + @api.onchange("stage_id") def _onchange_stage_id(self): # get last stage - heighest_stage = self.env['fsm.stage'].search( - [('stage_type', '=', 'equipment')], - order='sequence desc', - limit=1) + heighest_stage = self.env["fsm.stage"].search( + [("stage_type", "=", "equipment")], order="sequence desc", limit=1 + ) if self.stage_id.name == heighest_stage.name: self.hide = True else: diff --git a/fieldservice/models/fsm_location.py b/fieldservice/models/fsm_location.py index e4bb00f287..fa002b57e9 100644 --- a/fieldservice/models/fsm_location.py +++ b/fieldservice/models/fsm_location.py @@ -1,89 +1,102 @@ # 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 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'] - _description = 'Field Service Location' - - ref = fields.Char(string='Internal Reference', copy=False) - direction = fields.Char(string='Directions') - 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) - customer_id = fields.Many2one('res.partner', string='Billed Customer', - required=True, ondelete='restrict', - auto_join=True, - track_visibility='onchange') - contact_id = fields.Many2one('res.partner', string='Primary Contact', - domain="[('is_company', '=', False)," - " ('fsm_location', '=', False)]", - index=True) - description = fields.Char(string='Description') - territory_id = fields.Many2one('fsm.territory', string='Territory') - branch_id = fields.Many2one('fsm.branch', string='Branch') - district_id = fields.Many2one('fsm.district', string='District') - region_id = fields.Many2one('fsm.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) + _name = "fsm.location" + _inherits = {"res.partner": "partner_id"} + _inherit = ["mail.thread", "mail.activity.mixin"] + _description = "Field Service Location" + + ref = fields.Char(string="Internal Reference", copy=False) + direction = fields.Char(string="Directions") + 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(string="Description") + 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(string='Complete Name', - compute='_compute_complete_name', - store=True) + 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( + string="Complete Name", compute="_compute_complete_name", store=True + ) hide = fields.Boolean(default=False) - stage_id = fields.Many2one('fsm.stage', string='Stage', - track_visibility='onchange', - index=True, copy=False, - group_expand='_read_group_stage_ids', - default=lambda self: self._default_stage_id()) - - @api.depends('partner_id.name', 'fsm_parent_id.complete_name') + stage_id = fields.Many2one( + "fsm.stage", + string="Stage", + track_visibility="onchange", + index=True, + copy=False, + group_expand="_read_group_stage_ids", + default=lambda self: self._default_stage_id(), + ) + + @api.depends("partner_id.name", "fsm_parent_id.complete_name") def _compute_complete_name(self): for loc in self: if loc.fsm_parent_id: if loc.ref: - loc.complete_name = '%s / [%s] %s' % ( - loc.fsm_parent_id.complete_name, loc.ref, - loc.partner_id.name) + loc.complete_name = "{} / [{}] {}".format( + loc.fsm_parent_id.complete_name, loc.ref, loc.partner_id.name + ) else: - loc.complete_name = '%s / %s' % ( - loc.fsm_parent_id.complete_name, loc.partner_id.name) + loc.complete_name = "{} / {}".format( + loc.fsm_parent_id.complete_name, loc.partner_id.name + ) else: if loc.ref: - loc.complete_name = '[%s] %s' % (loc.ref, - loc.partner_id.name) + loc.complete_name = "[{}] {}".format(loc.ref, loc.partner_id.name) else: loc.complete_name = loc.partner_id.name - @api.multi def name_get(self): results = [] for rec in self: @@ -91,62 +104,67 @@ def name_get(self): return results @api.model - def name_search(self, name, args=None, operator='ilike', limit=100): + 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) + recs = self.search([("ref", "ilike", name)] + args, limit=limit) if not recs: - recs = self.search([('name', operator, name)] + args, limit=limit) + recs = self.search([("name", operator, name)] + args, limit=limit) return recs.name_get() - _sql_constraints = [('fsm_location_ref_uniq', 'unique (ref)', - 'This internal reference already exists!')] + _sql_constraints = [ + ( + "fsm_location_ref_uniq", + "unique (ref)", + "This internal reference already exists!", + ) + ] @api.model def _read_group_stage_ids(self, stages, domain, order): - stage_ids = self.env['fsm.stage'].search([('stage_type', - '=', 'location')]) + stage_ids = self.env["fsm.stage"].search([("stage_type", "=", "location")]) return stage_ids def _default_stage_id(self): - return self.env['fsm.stage'].search([('stage_type', '=', 'location'), - ('sequence', '=', '1')]) + return self.env["fsm.stage"].search( + [("stage_type", "=", "location"), ("sequence", "=", "1")] + ) def next_stage(self): seq = self.stage_id.sequence - next_stage = self.env['fsm.stage'].search( - [('stage_type', '=', 'location'), ('sequence', '>', seq)], - order="sequence asc") + next_stage = self.env["fsm.stage"].search( + [("stage_type", "=", "location"), ("sequence", ">", seq)], + order="sequence asc", + ) if next_stage: self.stage_id = next_stage[0] self._onchange_stage_id() def previous_stage(self): seq = self.stage_id.sequence - prev_stage = self.env['fsm.stage'].search( - [('stage_type', '=', 'location'), ('sequence', '<', seq)], - order="sequence desc") + prev_stage = self.env["fsm.stage"].search( + [("stage_type", "=", "location"), ("sequence", "<", seq)], + order="sequence desc", + ) if prev_stage: self.stage_id = prev_stage[0] self._onchange_stage_id() - @api.onchange('stage_id') + @api.onchange("stage_id") def _onchange_stage_id(self): # get last stage - heighest_stage = self.env['fsm.stage'].search( - [('stage_type', '=', 'location')], - order='sequence desc', - limit=1) + heighest_stage = self.env["fsm.stage"].search( + [("stage_type", "=", "location")], order="sequence desc", limit=1 + ) if self.stage_id.name == heighest_stage.name: self.hide = True else: self.hide = False - @api.onchange('fsm_parent_id') + @api.onchange("fsm_parent_id") def _onchange_fsm_parent_id(self): self.owner_id = self.fsm_parent_id.owner_id or False - self.customer_id = self.fsm_parent_id.customer_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 @@ -158,62 +176,63 @@ def _onchange_fsm_parent_id(self): self.tz = self.fsm_parent_id.tz or False self.territory_id = self.fsm_parent_id.territory_id or False - @api.onchange('territory_id') + @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.user.company_id.auto_populate_persons_on_location: for person in self.territory_id.person_ids: - self.env['fsm.location.person'].create({ - 'location_id': self.id, - 'person_id': person.id, - 'sequence': 10, - }) + self.env["fsm.location.person"].create( + {"location_id": self.id, "person_id": person.id, "sequence": 10} + ) - @api.onchange('branch_id') + @api.onchange("branch_id") def _onchange_branch_id(self): - self.branch_manager_id = \ - self.territory_id.branch_id.partner_id or False + 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') + @api.onchange("district_id") def _onchange_district_id(self): - self.district_manager_id = \ - self.branch_id.district_id.partner_id or False + 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') + @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)]) + 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)]) + 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)]) + 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) @@ -222,142 +241,142 @@ def comp_count(self, contact, equipment, loc): 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)]) + 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)]) + 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)]) + 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 - @api.multi 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.ref('contacts.action_contacts').\ - read()[0] + action = self.env.ref("contacts.action_contacts").read()[0] contacts = self.get_action_views(1, 0, location) - action['context'] = self.env.context.copy() - action['context'].update({'default_service_location_id': self.id}) + action["context"] = self.env.context.copy() + action["context"].update({"default_service_location_id": self.id}) if len(contacts) == 1: - action['views'] = [(self.env.ref('base.view_partner_form').id, - 'form')] - action['res_id'] = contacts.id - action['context'].update({'active_id': contacts.id}) + action["views"] = [(self.env.ref("base.view_partner_form").id, "form")] + action["res_id"] = contacts.id + action["context"].update({"active_id": contacts.id}) else: - action['domain'] = [('id', 'in', contacts.ids)] - action['context'].update({'active_ids': contacts.ids}) - action['context'].update({'active_id': ''}) + action["domain"] = [("id", "in", contacts.ids)] + action["context"].update({"active_ids": contacts.ids}) + action["context"].update({"active_id": ""}) return action - @api.multi def _compute_contact_ids(self): for loc in self: contacts = self.comp_count(1, 0, loc) loc.contact_count = contacts - @api.multi 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.ref('fieldservice.action_fsm_equipment').\ - read()[0] + action = self.env.ref("fieldservice.action_fsm_equipment").read()[0] equipment = self.get_action_views(0, 1, location) - action['context'] = self.env.context.copy() - action['context'].update({'default_location_id': self.id}) + action["context"] = self.env.context.copy() + action["context"].update({"default_location_id": self.id}) if len(equipment) == 0 or len(equipment) > 1: - action['domain'] = [('id', 'in', equipment.ids)] + action["domain"] = [("id", "in", equipment.ids)] elif equipment: - action['views'] = [(self.env. - ref('fieldservice.' + - 'fsm_equipment_form_view').id, - 'form')] - action['res_id'] = equipment.id + action["views"] = [ + ( + self.env.ref("fieldservice." + "fsm_equipment_form_view").id, + "form", + ) + ] + action["res_id"] = equipment.id return action - @api.multi def _compute_sublocation_ids(self): for loc in self: sublocation = self.comp_count(0, 0, loc) loc.sublocation_count = sublocation - @api.multi 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.ref('fieldservice.action_fsm_location').read()[0] + action = self.env.ref("fieldservice.action_fsm_location").read()[0] sublocation = self.get_action_views(0, 0, location) - action['context'] = self.env.context.copy() - action['context'].update({'default_fsm_parent_id': self.id}) + action["context"] = self.env.context.copy() + action["context"].update({"default_fsm_parent_id": self.id}) if len(sublocation) > 1 or len(sublocation) == 0: - action['domain'] = [('id', 'in', sublocation.ids)] + action["domain"] = [("id", "in", sublocation.ids)] elif sublocation: - action['views'] = [(self.env. - ref('fieldservice.' + - 'fsm_location_form_view').id, - 'form')] - action['res_id'] = sublocation.id + action["views"] = [ + ( + self.env.ref("fieldservice." + "fsm_location_form_view").id, + "form", + ) + ] + action["res_id"] = sublocation.id return action - @api.multi def _compute_equipment_ids(self): for loc in self: equipment = self.comp_count(0, 1, loc) loc.equipment_count = equipment - @api.constrains('fsm_parent_id') + @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.')) + if not self._check_recursion(parent="fsm_parent_id"): + raise ValidationError(_("You cannot create recursive location.")) return True - @api.onchange('country_id') + @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') + @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' + _inherit = "fsm.person" - location_ids = fields.One2many('fsm.location.person', - 'person_id', - string='Linked Locations') + location_ids = fields.One2many( + "fsm.location.person", "person_id", string="Linked Locations" + ) diff --git a/fieldservice/models/fsm_location_person.py b/fieldservice/models/fsm_location_person.py index 546babd080..b89bd38505 100644 --- a/fieldservice/models/fsm_location_person.py +++ b/fieldservice/models/fsm_location_person.py @@ -5,26 +5,27 @@ class FSMLocationPerson(models.Model): - _name = 'fsm.location.person' - _description = 'Field Service Location Person Info' - _rec_name = 'location_id' - _order = 'sequence' + _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) + 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(string="Sequence", required=True, default="10") - phone = fields.Char(related='person_id.phone', string='Phone') - email = fields.Char(related='person_id.email', string='Email') - owner_id = fields.Many2one(related='location_id.owner_id', string='Owner') - customer_id = fields.Many2one(related='location_id.customer_id', - string='Customer') - contact_id = fields.Many2one(related='location_id.contact_id', - string='Contact') + phone = fields.Char(related="person_id.phone", string="Phone") + email = fields.Char(related="person_id.email", string="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.') + ( + "location_person_uniq", + "unique(location_id,person_id)", + "The worker is already linked to this location.", + ) ] diff --git a/fieldservice/models/fsm_order.py b/fieldservice/models/fsm_order.py index 9036d6d208..976cdfa212 100644 --- a/fieldservice/models/fsm_order.py +++ b/fieldservice/models/fsm_order.py @@ -1,167 +1,194 @@ -# Copyright (C) 2018 - TODAY, Open Source Integrators +# 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 . import fsm_stage + +from odoo import _, api, fields, models from odoo.exceptions import ValidationError +from . import fsm_stage + class FSMOrder(models.Model): - _name = 'fsm.order' - _description = 'Field Service Order' - _inherit = ['mail.thread', 'mail.activity.mixin'] + _name = "fsm.order" + _description = "Field Service Order" + _inherit = ["mail.thread", "mail.activity.mixin"] def _default_stage_id(self): - 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', limit=1) + 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", + limit=1, + ) if stage_ids: return stage_ids[0] else: - raise ValidationError(_( - "You must create an FSM order stage first.")) + raise ValidationError(_("You must create an FSM order stage first.")) def _default_team_id(self): - team_ids = self.env['fsm.team'].\ - search([('company_id', 'in', (self.env.user.company_id.id, - False))], - order='sequence asc', limit=1) + team_ids = self.env["fsm.team"].search( + [("company_id", "in", (self.env.user.company_id.id, False))], + order="sequence asc", + limit=1, + ) if team_ids: return team_ids[0] else: - raise ValidationError(_( - "You must create an FSM team first.")) + raise ValidationError(_("You must create an FSM team first.")) + + api.depends("date_start", "date_end") - @api.depends('date_start', 'date_end') def _compute_duration(self): + duration = 0.0 for rec in self: 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 - rec.duration = delta.total_seconds() / 3600 + duration = delta.total_seconds() / 3600 + rec.duration = duration - @api.depends('stage_id') + @api.depends("stage_id") def _get_stage_color(self): """ Get stage color""" - self.custom_color = self.stage_id.custom_color or '#FFFFFF' - - stage_id = fields.Many2one('fsm.stage', string='Stage', - track_visibility='onchange', - index=True, copy=False, - group_expand='_read_group_stage_ids', - default=lambda self: self._default_stage_id()) - priority = fields.Selection(fsm_stage.AVAILABLE_PRIORITIES, - string='Priority', - 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, - track_visibility='onchange') + self.custom_color = self.stage_id.custom_color or "#FFFFFF" + + stage_id = fields.Many2one( + "fsm.stage", + string="Stage", + track_visibility="onchange", + index=True, + copy=False, + group_expand="_read_group_stage_ids", + default=lambda self: self._default_stage_id(), + ) + priority = fields.Selection( + fsm_stage.AVAILABLE_PRIORITIES, + string="Priority", + 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, + track_visibility="onchange", + ) # Request - name = fields.Char(string='Name', required=True, index=True, copy=False, - default=lambda self: _('New')) - customer_id = fields.Many2one('res.partner', string='Contact', - domain=[('customer', '=', True)], - change_default=True, - index=True, - track_visibility='always') - location_id = fields.Many2one('fsm.location', string='Location', - index=True, required=True) - location_directions = fields.Char(string='Location Directions') - request_early = fields.Datetime(string='Earliest Request Date', - default=datetime.now()) - color = fields.Integer('Color Index') + name = fields.Char( + string="Name", + 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(string="Location Directions") + 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, + "res.company", + string="Company", + required=True, + index=True, default=lambda self: self.env.user.company_id, - help="Company related to this order") + help="Company related to this order", + ) def _compute_request_late(self, vals): - if vals.get('priority') == '0': - if vals.get('request_early'): - vals['request_late'] = fields.Datetime.\ - from_string(vals.get('request_early')) + timedelta(days=3) + 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('priority') == '1': - vals['request_late'] = fields.Datetime.\ - from_string(vals.get('request_early')) + timedelta(days=2) - elif vals.get('priority') == '2': - vals['request_late'] = fields.Datetime.\ - from_string(vals.get('request_early')) + timedelta(days=1) - elif vals.get('priority') == '3': - vals['request_late'] = fields.Datetime.\ - from_string(vals.get('request_early')) + timedelta(hours=8) + vals["request_late"] = datetime.now() + timedelta(days=3) + elif vals.get("priority") == "1": + vals["request_late"] = fields.Datetime.from_string( + vals.get("request_early") + ) + timedelta(days=2) + elif vals.get("priority") == "2": + vals["request_late"] = fields.Datetime.from_string( + vals.get("request_early") + ) + timedelta(days=1) + elif vals.get("priority") == "3": + vals["request_late"] = fields.Datetime.from_string( + vals.get("request_early") + ) + timedelta(hours=8) return vals - request_late = fields.Datetime(string='Latest Request Date') - description = fields.Text(string='Description') + request_late = fields.Datetime(string="Latest Request Date") + description = fields.Text(string="Description") - person_ids = fields.Many2many('fsm.person', - string='Field Service Workers') + person_ids = fields.Many2many("fsm.person", string="Field Service Workers") - @api.onchange('location_id') + @api.onchange("location_id") def _onchange_location_id_customer(self): - if self.location_id: - return {'domain': {'customer_id': [('service_location_id', '=', - self.location_id.name)]}} - else: - return {'domain': {'customer_id': [('id', '!=', None)]}} - - @api.onchange('customer_id') - def _onchange_customer_id_location(self): - if self.customer_id: - self.location_id = self.customer_id.service_location_id + 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") - route_id = fields.Many2one('fsm.route', string='Route', index=True) - scheduled_date_start = fields.Datetime(string='Scheduled Start (ETA)') - scheduled_duration = fields.Float(string='Scheduled duration', - help='Scheduled duration of the work in' - ' hours') + 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( + string="Scheduled duration", help="Scheduled duration of the work in" " hours" + ) scheduled_date_end = fields.Datetime(string="Scheduled End") - sequence = fields.Integer(string='Sequence', default=10) - todo = fields.Text(string='Instructions') + sequence = fields.Integer(string="Sequence", default=10) + todo = fields.Text(string="Instructions") # Execution - resolution = fields.Text(string='Resolution', - placeholder="Resolution of the order") - 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') + resolution = fields.Text(string="Resolution", placeholder="Resolution of the order") + 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('fsm.territory', string="Territory", - related='location_id.territory_id', - store=True) - branch_id = fields.Many2one('fsm.branch', string='Branch', - related='location_id.branch_id', - store=True) - district_id = fields.Many2one('fsm.district', string='District', - related='location_id.district_id', - store=True) - region_id = fields.Many2one('fsm.region', string='Region', - related='location_id.region_id', - store=True) + 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") @@ -169,212 +196,206 @@ def _onchange_customer_id_location(self): street2 = fields.Char(related="location_id.street2") zip = fields.Char(related="location_id.zip") city = fields.Char(related="location_id.city", string="City") - state_name = fields.Char(related="location_id.state_id.name", - string='State', ondelete='restrict') - country_name = fields.Char(related="location_id.country_id.name", - string='Country', ondelete='restrict') + state_name = fields.Char( + related="location_id.state_id.name", string="State", ondelete="restrict" + ) + country_name = fields.Char( + related="location_id.country_id.name", string="Country", ondelete="restrict" + ) 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') + 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") + 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_id = fields.Many2one("fsm.equipment", string="Equipment") # Equipment used for all other Service Orders - equipment_ids = fields.Many2many('fsm.equipment', string='Equipments') - type = fields.Selection([], string='Type') + equipment_ids = fields.Many2many("fsm.equipment", string="Equipments") + type = fields.Many2one("fsm.order.type", string="Type") @api.model def _read_group_stage_ids(self, stages, domain, order): - stage_ids = self.env['fsm.stage'].\ - search([('stage_type', '=', 'order'), - ('company_id', '=', self.env.user.company_id.id)]) - return stage_ids + 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') - if vals.get('request_early', False) and not vals.get( - 'scheduled_date_start'): - req_date = fields.Datetime.from_string(vals['request_early']) + if vals.get("name", _("New")) == _("New"): + vals["name"] = self.env["ir.sequence"].next_by_code("fsm.order") or _("New") + if vals.get("request_early", False) and not vals.get("scheduled_date_start"): + req_date = fields.Datetime.from_string(vals["request_early"]) # Round scheduled date start req_date = req_date.replace(minute=0, second=0) - vals.update({'scheduled_date_start': str(req_date), - 'request_early': str(req_date)}) + vals.update( + {"scheduled_date_start": str(req_date), "request_early": str(req_date)} + ) + vals.update( + { + "scheduled_date_end": self._context.get("default_scheduled_date_end") + or False + } + ) 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) + 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('priority') == '1': - vals['request_late'] = fields.Datetime.\ - from_string(vals.get('request_early')) + timedelta(days=2) - elif vals.get('priority') == '2': - vals['request_late'] = fields.Datetime.\ - from_string(vals.get('request_early')) + timedelta(days=1) - elif vals.get('priority') == '3': - vals['request_late'] = fields.Datetime.\ - from_string(vals.get('request_early')) + timedelta(hours=8) + vals["request_late"] = datetime.now() + timedelta(days=3) + elif vals.get("priority") == "1": + vals["request_late"] = fields.Datetime.from_string( + vals.get("request_early") + ) + timedelta(days=2) + elif vals.get("priority") == "2": + vals["request_late"] = fields.Datetime.from_string( + vals.get("request_early") + ) + timedelta(days=1) + elif vals.get("priority") == "3": + vals["request_late"] = fields.Datetime.from_string( + vals.get("request_early") + ) + timedelta(hours=8) return super(FSMOrder, self).create(vals) - @api.multi def write(self, vals): self._calc_scheduled_dates(vals) res = super(FSMOrder, self).write(vals) - for order in self: - if 'customer_id' not in vals and order.customer_id is False: - order.customer_id = order.location_id.customer_id.id 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): + for order in self: + if order.can_unlink(): + return super(FSMOrder, order).unlink() + else: + raise ValidationError(_("You cannot delete this order.")) + def _calc_scheduled_dates(self, vals): """Calculate scheduled dates and duration""" - if (vals.get('scheduled_duration') - or vals.get('scheduled_date_start') - or vals.get('scheduled_date_end')): - date_end = '' - date_start = '' - if vals.get('scheduled_duration', False): - date_to_with_delta = fields.Datetime.from_string( - vals.get('scheduled_date_start', - self.scheduled_date_start)) + timedelta( - hours=vals.get('scheduled_duration', False)) - date_end = str(date_to_with_delta) - - if (vals.get('scheduled_date_start', False) - and self.scheduled_date_start != vals.get( - 'scheduled_date_start', False) - and vals.get('scheduled_date_end', False) - and self.scheduled_date_end != vals.get( - 'scheduled_date_end', False)): - 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 - self.scheduled_duration = float(hrs) - elif (vals.get('scheduled_date_start', False) - and self.scheduled_date_start != vals.get( - 'scheduled_date_start', False)): - old_date_start = fields.Datetime.from_string(self.scheduled_date_start) - new_date_start = fields.Datetime.from_string( - vals.get('scheduled_date_start', False)) - date_end = fields.Datetime.from_string(self.scheduled_date_end) - if old_date_start and new_date_start: - if old_date_start > new_date_start: - hours = old_date_start.replace(second=0) - new_date_start.replace(second=0) - hrs = hours.total_seconds() / 3600 - self.scheduled_duration += float(hrs) - elif old_date_start < new_date_start: - hours = new_date_start.replace(second=0) - old_date_start.replace(second=0) - hrs = hours.total_seconds() / 3600 - if date_end and not new_date_start >= date_end: - self.scheduled_duration -= float(hrs) - hrs = vals.get('scheduled_duration', False) or self.scheduled_duration or 0 - date_to_with_delta = fields.Datetime.from_string( - vals.get('scheduled_date_start', False)) + timedelta(hours=hrs) - date_end = str(date_to_with_delta) - - elif (vals.get('scheduled_date_end', False) - and self.scheduled_date_end != vals.get( - 'scheduled_date_end', False)): + if ( + vals.get("scheduled_duration") + or vals.get("scheduled_date_start") + or vals.get("scheduled_date_end") + ): - old_date_end = fields.Datetime.from_string(self.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)) - date_start = fields.Datetime.from_string(self.scheduled_date_start) - if old_date_end and new_date_end: - if old_date_end > new_date_end: - hours = old_date_end.replace(second=0) - new_date_end.replace(second=0) - hrs = hours.total_seconds() / 3600 - if date_start and not new_date_end <= date_start: - self.scheduled_duration -= hrs - else: - hours = new_date_end.replace(second=0) - old_date_end.replace(second=0) - hrs = hours.total_seconds() / 3600 - self.scheduled_duration += hrs - hrs = vals.get('scheduled_duration', False) or self.scheduled_duration or 0 + 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) - date_start = str(date_to_with_delta) - - if date_end: - vals['scheduled_date_end'] = date_end - if date_start: - vals['scheduled_date_start'] = date_start + vals.get("scheduled_date_end", False) + ) - timedelta(hours=hrs) + vals["scheduled_date_start"] = str(date_to_with_delta) + + elif vals.get("scheduled_duration", False) or ( + vals.get("scheduled_date_start", False) + 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) def action_complete(self): - return self.write({'stage_id': self.env.ref( - 'fieldservice.fsm_stage_completed').id}) + return self.write( + {"stage_id": self.env.ref("fieldservice.fsm_stage_completed").id} + ) def action_cancel(self): - return self.write({'stage_id': self.env.ref( - 'fieldservice.fsm_stage_cancelled').id}) + return self.write( + {"stage_id": self.env.ref("fieldservice.fsm_stage_cancelled").id} + ) - @api.onchange('scheduled_date_end') + @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.scheduled_date_end + ) - timedelta(hours=self.scheduled_duration) self.date_start = str(date_to_with_delta) - @api.onchange('scheduled_duration') + @api.onchange("scheduled_duration") def onchange_scheduled_duration(self): - if (self.scheduled_duration and self.scheduled_date_start): + 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_start + ) + timedelta(hours=self.scheduled_duration) self.scheduled_date_end = str(date_to_with_delta) def copy_notes(self): self.description = "" - if self.type and self.type.name not in ['repair', 'maintenance']: + if self.type and self.type.name not in ["repair", "maintenance"]: for equipment_id in self.equipment_ids: if equipment_id: if equipment_id.notes is not False: if self.description is not False: - self.description = (self.description + - equipment_id.notes + '\n ') + self.description = ( + self.description + equipment_id.notes + "\n " + ) else: - self.description = (equipment_id.notes + '\n ') + self.description = equipment_id.notes + "\n " else: if self.equipment_id: if self.equipment_id.notes is not False: if self.description is not False: - self.description = (self.description + - self.equipment_id.notes + '\n ') + self.description = ( + self.description + self.equipment_id.notes + "\n " + ) else: - self.description = (self.equipment_id.notes + '\n ') + self.description = self.equipment_id.notes + "\n " if self.location_id: s = self.location_id.direction - if s is not False and s != '


': - s = s.replace('

', '') - s = s.replace('
', '') - s = s.replace('

', '\n') + if s is not False and s != "


": + s = s.replace("

", "") + s = s.replace("
", "") + s = s.replace("

", "\n") if self.location_directions is not False: - self.location_directions = (self.location_directions + - '\n' + s + '\n') + self.location_directions = ( + self.location_directions + "\n" + s + "\n" + ) else: - self.location_directions = (s + '\n ') + self.location_directions = s + "\n " if self.template_id: self.todo = self.template_id.instructions - @api.onchange('location_id') + @api.onchange("location_id") def onchange_location_id(self): if self.location_id: self.territory_id = self.location_id.territory_id or False @@ -383,23 +404,16 @@ def onchange_location_id(self): self.region_id = self.location_id.region_id or False self.copy_notes() - @api.onchange('equipment_ids') + @api.onchange("equipment_ids") def onchange_equipment_ids(self): self.copy_notes() - @api.onchange('template_id') + @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.hours self.copy_notes() self.type = self.template_id.type_id - self.team_id = self.template_id.team_id - - -class FSMTeam(models.Model): - _inherit = 'fsm.team' - - order_ids = fields.One2many( - 'fsm.order', 'team_id', string='Orders', - domain=[('stage_id.is_closed', '=', False)]) + if self.template_id.team_id: + self.team_id = self.template_id.team_id diff --git a/fieldservice/models/fsm_order_type.py b/fieldservice/models/fsm_order_type.py new file mode 100644 index 0000000000..d80d8b63d2 --- /dev/null +++ b/fieldservice/models/fsm_order_type.py @@ -0,0 +1,10 @@ +# 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(string="Name") diff --git a/fieldservice/models/fsm_person.py b/fieldservice/models/fsm_person.py index dd6c327f97..24a949505a 100644 --- a/fieldservice/models/fsm_person.py +++ b/fieldservice/models/fsm_person.py @@ -5,112 +5,135 @@ class FSMPerson(models.Model): - _name = 'fsm.person' - _inherits = {'res.partner': 'partner_id'} - _description = 'Field Service Worker' + _name = "fsm.person" + _inherits = {"res.partner": "partner_id"} + _description = "Field Service 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') - stage_id = fields.Many2one('fsm.stage', string='Stage', - track_visibility='onchange', - index=True, copy=False, - group_expand='_read_group_stage_ids', - default=lambda self: self._default_stage_id()) + 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") + stage_id = fields.Many2one( + "fsm.stage", + string="Stage", + track_visibility="onchange", + index=True, + copy=False, + group_expand="_read_group_stage_ids", + default=lambda self: self._default_stage_id(), + ) hide = fields.Boolean(default=False) mobile = fields.Char(string="Mobile") - territory_ids = fields.Many2many('fsm.territory', string='Territories') + territory_ids = fields.Many2many("res.territory", string="Territories") @api.model - def _search(self, args, offset=0, limit=None, order=None, count=False, - access_rights_uid=None): + def _search( + self, + args, + offset=0, + limit=None, + order=None, + count=False, + access_rights_uid=None, + ): res = super(FSMPerson, self)._search( - args=args, offset=offset, limit=limit, order=order, count=count, - access_rights_uid=access_rights_uid) + 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(arg, (list)): - if arg[0] == 'location_ids': + 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],)) + 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],)) + 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)]) + 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] + 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}) + vals.update({"fsm_person": True}) return super(FSMPerson, self).create(vals) - @api.multi def get_person_information(self, vals): # get person ids - person_ids = self.search([('id', '!=', 0), ('active', '=', True)]) + person_ids = self.search([("id", "!=", 0), ("active", "=", True)]) person_information_dict = [] for person in person_ids: - person_information_dict.append({ - 'id': person.id, - 'name': person.name}) + person_information_dict.append({"id": person.id, "name": person.name}) return person_information_dict @api.model def _read_group_stage_ids(self, stages, domain, order): - stage_ids = self.env['fsm.stage'].search([('stage_type', - '=', 'worker')]) + stage_ids = self.env["fsm.stage"].search([("stage_type", "=", "worker")]) return stage_ids def _default_stage_id(self): - return self.env['fsm.stage'].search([('stage_type', '=', 'worker'), - ('sequence', '=', '1')]) + return self.env["fsm.stage"].search( + [("stage_type", "=", "worker"), ("sequence", "=", "1")] + ) def next_stage(self): seq = self.stage_id.sequence - next_stage = self.env['fsm.stage'].search( - [('stage_type', '=', 'worker'), ('sequence', '>', seq)], - order="sequence asc") + next_stage = self.env["fsm.stage"].search( + [("stage_type", "=", "worker"), ("sequence", ">", seq)], + order="sequence asc", + ) if next_stage: self.stage_id = next_stage[0] self._onchange_stage_id() def previous_stage(self): seq = self.stage_id.sequence - prev_stage = self.env['fsm.stage'].search( - [('stage_type', '=', 'worker'), ('sequence', '<', seq)], - order="sequence desc") + prev_stage = self.env["fsm.stage"].search( + [("stage_type", "=", "worker"), ("sequence", "<", seq)], + order="sequence desc", + ) if prev_stage: self.stage_id = prev_stage[0] self._onchange_stage_id() - @api.onchange('stage_id') + @api.onchange("stage_id") def _onchange_stage_id(self): # get last stage - heighest_stage = self.env['fsm.stage'].search( - [('stage_type', '=', 'worker')], - order='sequence desc', - limit=1) + heighest_stage = self.env["fsm.stage"].search( + [("stage_type", "=", "worker")], order="sequence desc", limit=1 + ) if self.stage_id.name == heighest_stage.name: self.hide = True else: diff --git a/fieldservice/models/fsm_region.py b/fieldservice/models/fsm_region.py deleted file mode 100644 index a1cf496505..0000000000 --- a/fieldservice/models/fsm_region.py +++ /dev/null @@ -1,13 +0,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 FSMRegion(models.Model): - _name = 'fsm.region' - _description = 'Region' - - name = fields.Char(string='Name', required=True) - description = fields.Char(string='Description') - partner_id = fields.Many2one('res.partner', string='Region Manager') diff --git a/fieldservice/models/fsm_route.py b/fieldservice/models/fsm_route.py deleted file mode 100644 index df5c4934c0..0000000000 --- a/fieldservice/models/fsm_route.py +++ /dev/null @@ -1,36 +0,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 FSMRoute(models.Model): - _name = 'fsm.route' - _description = 'Field Service Route' - _order = 'date, name' - - name = fields.Char(string='Name', required=True, - default=lambda self: _('New')) - order_ids = fields.One2many('fsm.order', 'route_id', - string='Orders') - person_id = fields.Many2one('fsm.person', - string='Assigned To', - required=True) - date = fields.Date(string='Date', required=True) - 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 route") - - _sql_constraints = [ - ('fsm_route_person_date_uniq', - 'unique (person_id, date)', - "You cannot create 2 routes for the same worker on the same day!"), - ] - - @api.model - def create(self, vals): - if vals.get('name', _('New')) == _('New'): - vals['name'] = self.env['ir.sequence'].next_by_code('fsm.route')\ - or _('New') - return super(FSMRoute, self).create(vals) diff --git a/fieldservice/models/fsm_stage.py b/fieldservice/models/fsm_stage.py index ee72dafa99..1a1ce763ef 100644 --- a/fieldservice/models/fsm_stage.py +++ b/fieldservice/models/fsm_stage.py @@ -1,77 +1,107 @@ # 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 import _, api, fields, models from odoo.exceptions import ValidationError - -AVAILABLE_PRIORITIES = [ - ('0', 'Normal'), - ('1', 'Low'), - ('2', 'High'), - ('3', 'Urgent'), -] +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' + _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 - name = fields.Char(string='Name', required=True) - sequence = fields.Integer('Sequence', 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") + name = fields.Char(string="Name", required=True) + sequence = fields.Integer( + "Sequence", 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) + 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(), + ) - @api.multi 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, - }) + 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.env['fsm.stage'].search([]) + stages = self.env["fsm.stage"].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.")) + 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(FSMStage, self).create(vals) - @api.constrains('custom_color') + @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')) + 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")) diff --git a/fieldservice/models/fsm_tag.py b/fieldservice/models/fsm_tag.py index 0162e85b8e..48bf8477ab 100644 --- a/fieldservice/models/fsm_tag.py +++ b/fieldservice/models/fsm_tag.py @@ -5,25 +5,27 @@ class FSMTag(models.Model): - _name = 'fsm.tag' - _description = 'Field Service Tag' + _name = "fsm.tag" + _description = "Field Service Tag" - name = fields.Char(string='Name', required=True) - parent_id = fields.Many2one('fsm.tag', string='Parent') - color = fields.Integer('Color Index', default=10) - full_name = fields.Char(string='Full Name', compute='_compute_full_name') + name = fields.Char(string="Name", required=True) + parent_id = fields.Many2one("fsm.tag", string="Parent") + color = fields.Integer("Color Index", default=10) + full_name = fields.Char(string="Full Name", compute="_compute_full_name") company_id = fields.Many2one( - 'res.company', string='Company', required=True, index=True, + "res.company", + string="Company", + required=True, + index=True, default=lambda self: self.env.user.company_id, - help="Company related to this tag") + help="Company related to this tag", + ) - _sql_constraints = [ - ('name_uniq', 'unique (name)', "Tag name already exists!"), - ] + _sql_constraints = [("name_uniq", "unique (name)", "Tag name already exists!")] def _compute_full_name(self): for record in self: if record.parent_id: - record.full_name = (record.parent_id.name + '/' + record.name) + record.full_name = record.parent_id.name + "/" + record.name else: record.full_name = record.name diff --git a/fieldservice/models/fsm_team.py b/fieldservice/models/fsm_team.py index 9fe7525673..b415d7ce31 100644 --- a/fieldservice/models/fsm_team.py +++ b/fieldservice/models/fsm_team.py @@ -1,80 +1,81 @@ -# Copyright (C) 2018 - TODAY, Brian McMaster +# 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'] + _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)]) + 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} + 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)], - ['team_id'], ['team_id']) - result = {data['team_id'][0]: int(data['team_id_count']) - for data in order_data} + order_data = self.env["fsm.order"].read_group( + [("team_id", "in", self.ids), ("person_id", "=", 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)], - ['team_id'], ['team_id']) - result = {data['team_id'][0]: int(data['team_id_count']) - for data in order_data} + order_data = self.env["fsm.order"].read_group( + [("team_id", "in", self.ids), ("scheduled_date_start", "=", 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, translation=True) description = fields.Text(translation=True) - color = fields.Integer('Color Index') + 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_count = fields.Integer( - compute='_compute_order_count', - string="Orders Count") + "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") + 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('Sequence', default=1, - help="Used to sort teams. Lower is better.") + compute="_compute_order_need_schedule_count", string="Orders to Schedule" + ) + sequence = fields.Integer( + "Sequence", default=1, help="Used to sort teams. Lower is better." + ) company_id = fields.Many2one( - 'res.company', string='Company', required=True, index=True, + "res.company", + string="Company", + required=True, + index=True, default=lambda self: self.env.user.company_id, - help="Company related to this team") + help="Company related to this team", + ) - _sql_constraints = [ - ('name_uniq', 'unique (name)', "Team name already exists!"), - ] - - -class FSMStage(models.Model): - _inherit = 'fsm.stage' - - 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 - - team_ids = fields.Many2many( - 'fsm.team', 'order_team_stage_rel', 'stage_id', 'team_id', - string='Teams', - default=lambda self: self._default_team_ids()) + _sql_constraints = [("name_uniq", "unique (name)", "Team name already exists!")] diff --git a/fieldservice/models/fsm_template.py b/fieldservice/models/fsm_template.py index 2977e2c30c..c3993fe962 100644 --- a/fieldservice/models/fsm_template.py +++ b/fieldservice/models/fsm_template.py @@ -5,18 +5,24 @@ class FSMTemplate(models.Model): - _name = 'fsm.template' - _description = 'Field Service Order Template' + _name = "fsm.template" + _description = "Field Service Order Template" - name = fields.Char(string='Name', required=True) - instructions = fields.Text(string='Instructions') - category_ids = fields.Many2many('fsm.category', string='Categories') - hours = fields.Float(string='Hours') + name = fields.Char(string="Name", required=True) + instructions = fields.Text(string="Instructions") + category_ids = fields.Many2many("fsm.category", string="Categories") + hours = fields.Float(string="Hours") company_id = fields.Many2one( - 'res.company', string='Company', required=True, index=True, + "res.company", + string="Company", + required=True, + index=True, default=lambda self: self.env.user.company_id, - help='Company related to this template') - type_id = fields.Many2one('fsm.order.type', string='Type') + 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') + "fsm.team", + string="Team", + help="Choose a team to be set on orders of this template", + ) diff --git a/fieldservice/models/fsm_territory.py b/fieldservice/models/fsm_territory.py deleted file mode 100644 index 87600a2b55..0000000000 --- a/fieldservice/models/fsm_territory.py +++ /dev/null @@ -1,30 +0,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 FSMTerritory(models.Model): - _name = 'fsm.territory' - _description = 'Territory' - - name = fields.Char(string='Name', required=True) - branch_id = fields.Many2one('fsm.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') - - person_ids = fields.Many2many('fsm.person', string='Field Service Workers') - description = fields.Char(string='Description') - person_id = fields.Many2one('fsm.person', string='Primary Assignment') - type = fields.Selection([('zip', 'Zip'), - ('state', 'State'), - ('country', 'Country')], 'Type') - - zip_codes = fields.Char(string='ZIP Codes') - state_ids = fields.One2many('res.country.state', - 'territory_id', string='State Names') - country_ids = fields.One2many('res.country', - 'territory_id', - string='Country Names') diff --git a/fieldservice/models/res_company.py b/fieldservice/models/res_company.py index a1d7eb4753..6362ccbbb7 100644 --- a/fieldservice/models/res_company.py +++ b/fieldservice/models/res_company.py @@ -5,7 +5,11 @@ class ResCompany(models.Model): - _inherit = 'res.company' + _inherit = "res.company" auto_populate_persons_on_location = fields.Boolean( - string='Auto-populate Workers on Location based on Territory') + 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" + ) diff --git a/fieldservice/models/res_config_settings.py b/fieldservice/models/res_config_settings.py index 5b6c9a1470..11bb4f0217 100644 --- a/fieldservice/models/res_config_settings.py +++ b/fieldservice/models/res_config_settings.py @@ -5,83 +5,101 @@ class ResConfigSettings(models.TransientModel): - _inherit = 'res.config.settings' + _inherit = "res.config.settings" # Groups group_fsm_team = fields.Boolean( - string='Manage Teams', - implied_group='fieldservice.group_fsm_team') + string="Manage Teams", implied_group="fieldservice.group_fsm_team" + ) group_fsm_category = fields.Boolean( - string='Manage Categories', - implied_group='fieldservice.group_fsm_category') + 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_substatus = fields.Boolean( - string='Manage Substatus', - implied_group='fieldservice.group_fsm_substatus') + string="Manage Tags", implied_group="fieldservice.group_fsm_tag" + ) group_fsm_equipment = fields.Boolean( - string='Manage Equipment', - implied_group='fieldservice.group_fsm_equipment') + string="Manage Equipment", implied_group="fieldservice.group_fsm_equipment" + ) group_fsm_template = fields.Boolean( - string='Manage Template', - implied_group='fieldservice.group_fsm_template') + 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_distribution = fields.Boolean( - string='Manage Distribution') - module_fieldservice_geoengine = fields.Boolean( - string='Use GeoEngine') + 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_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') + string="Link FSM orders to maintenance requests" + ) module_fieldservice_purchase = fields.Boolean( - string='Manage subcontractors and their pricelists') + string="Manage subcontractors and their pricelists" + ) module_fieldservice_repair = fields.Boolean( - string='Link FSM orders to MRP Repair orders') - 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_recurring = fields.Boolean( - string='Manage Recurring Orders') - 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) - module_fieldservice_project = fields.Boolean( - string='Projects and Tasks') - module_fieldservice_crm = fields.Boolean( - string='CRM') + 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_recurring = fields.Boolean(string="Manage Recurring Orders") + module_fieldservice_project = fields.Boolean(string="Projects and Tasks") + 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) + 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, + ) # Dependencies - @api.onchange('module_fieldservice_repair') + @api.onchange("group_fsm_equipment") + def _onchange_group_fsm_equipment(self): + if not self.group_fsm_equipment: + self.auto_populate_the_equipments = False + + @api.onchange("module_fieldservice_repair") def _onchange_module_fieldservice_repair(self): if self.module_fieldservice_repair: self.group_fsm_equipment = True - @api.onchange('module_fieldservice_stock') + @api.onchange("module_fieldservice_stock") def _onchange_module_fieldservice_stock(self): if self.module_fieldservice_stock: self.group_stock_production_lot = True self.group_stock_request_order = True - @api.onchange('module_fieldservice_purchase') + @api.onchange("module_fieldservice_purchase") def _onchange_module_fieldservice_purchase(self): if self.module_fieldservice_purchase: self.group_manage_vendor_price = True diff --git a/fieldservice/models/res_country.py b/fieldservice/models/res_country.py deleted file mode 100644 index 898b7357a3..0000000000 --- a/fieldservice/models/res_country.py +++ /dev/null @@ -1,10 +0,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 ResCountry(models.Model): - _inherit = 'res.country' - - territory_id = fields.Many2one('fsm.territory', string="Territory") diff --git a/fieldservice/models/res_partner.py b/fieldservice/models/res_partner.py index de366fe59e..4204fd563d 100644 --- a/fieldservice/models/res_partner.py +++ b/fieldservice/models/res_partner.py @@ -1,45 +1,44 @@ # 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 import fields, models class ResPartner(models.Model): - _inherit = 'res.partner' + _inherit = "res.partner" - fsm_location = fields.Boolean('Is a FS Location') - fsm_person = fields.Boolean('Is a FS Worker') - service_location_id = fields.Many2one('fsm.location', - string='Primary Service Location') + fsm_location = fields.Boolean("Is a FS Location") + fsm_person = fields.Boolean("Is a FS Worker") + 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)]) + "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") + compute="_compute_owned_location_count", string="# of Owned Locations" + ) - @api.multi def _compute_owned_location_count(self): for partner in self: - res = self.env['fsm.location'].search_count( - [('owner_id', '=', partner.id)]) + res = self.env["fsm.location"].search_count([("owner_id", "=", partner.id)]) partner.owned_location_count = res - @api.multi def action_open_owned_locations(self): for partner in self: - owned_location_ids = self.env['fsm.location'].search( - [('owner_id', '=', partner.id)]) - action = self.env.ref( - 'fieldservice.action_fsm_location').read()[0] - action['context'] = {} + owned_location_ids = self.env["fsm.location"].search( + [("owner_id", "=", partner.id)] + ) + action = self.env.ref("fieldservice.action_fsm_location").read()[0] + action["context"] = {} if len(owned_location_ids) > 1: - action['domain'] = [('id', 'in', owned_location_ids.ids)] + 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] + action["views"] = [ + (self.env.ref("fieldservice.fsm_location_form_view").id, "form") + ] + action["res_id"] = owned_location_ids.ids[0] return action diff --git a/fieldservice/models/res_state.py b/fieldservice/models/res_state.py deleted file mode 100644 index ad57232bb8..0000000000 --- a/fieldservice/models/res_state.py +++ /dev/null @@ -1,10 +0,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 ResCountryState(models.Model): - _inherit = 'res.country.state' - - territory_id = fields.Many2one('fsm.territory', string="Territory") diff --git a/fieldservice/models/res_territory.py b/fieldservice/models/res_territory.py new file mode 100644 index 0000000000..c0c8a65b01 --- /dev/null +++ b/fieldservice/models/res_territory.py @@ -0,0 +1,11 @@ +# 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") diff --git a/fieldservice/readme/CONFIGURE.rst b/fieldservice/readme/CONFIGURE.rst index bd38c94946..285f6b16f9 100644 --- a/fieldservice/readme/CONFIGURE.rst +++ b/fieldservice/readme/CONFIGURE.rst @@ -16,15 +16,6 @@ comes pre-configured for use. #. Select *Order* type to apply this stage to your orders. #. Additonally, you can set a color for the stage. -You need to add attribute mention below with the tag as base element. - -* colors (optional): it allows to set certain specific colors if the expressed - condition (JS syntax) is met. -* custom_color (optional): it allows to set custom color for fsm.stages - example custom_color = "true". And there is minor condition to follow to - implement this as. Define any one stage color condition like - colors="#ffffff:stage_id=='New';" - Field Service Areas ~~~~~~~~~~~~~~~~~~~ @@ -37,12 +28,12 @@ are managed under an encompassing Region. Setup a Territory ----------------- -#. Go to *Field Service > Configuration > Locations > Territories* +#. Go to Settings > Users & Companies > Territories* #. Create or select a territory #. Set the territory Name and description #. Select or create a branch which this territory serves -#. Choose a type of zip, state, or country whichs defines the boundary used -#. Input a list of zip codes, states, or countries based on your desired +#. Choose a type of zip, country whichs defines the boundary used +#. Input a list of zip codes, countries based on your desired configuration Setup Branches, Districts, and Regions diff --git a/fieldservice/readme/INSTALL.rst b/fieldservice/readme/INSTALL.rst deleted file mode 100644 index 80d0ec0e89..0000000000 --- a/fieldservice/readme/INSTALL.rst +++ /dev/null @@ -1,11 +0,0 @@ -As of version 12, you can install Field Service alone without mapping features. - -To install Field Service and have the mapping features, you need to install GeoEngine. -GeoEngine requires you to have `PostGIS `_ installed and also -install two additional python libs: - -* `Shapely `_ -* `geojson `_ - -Please refer to the installation instructions available at: -https://github.com/OCA/geospatial/tree/12.0/base_geoengine diff --git a/fieldservice/report/fsm_order_report_template.xml b/fieldservice/report/fsm_order_report_template.xml index 7bce6a923b..2d3ccb04cb 100644 --- a/fieldservice/report/fsm_order_report_template.xml +++ b/fieldservice/report/fsm_order_report_template.xml @@ -6,18 +6,10 @@
-
+
Date Completed:

- - - -
- - -

diff --git a/fieldservice/security/ir.model.access.csv b/fieldservice/security/ir.model.access.csv index 4d6e19d489..eab45d554f 100644 --- a/fieldservice/security/ir.model.access.csv +++ b/fieldservice/security/ir.model.access.csv @@ -8,17 +8,7 @@ access_fsm_person_manager,fsm.person.manager,model_fsm_person,fieldservice.group access_fsm_location_user,fsm.location.user,model_fsm_location,fieldservice.group_fsm_user,1,1,0,0 access_fsm_location_dispatcher,fsm.location.dispatcher,model_fsm_location,fieldservice.group_fsm_dispatcher,1,1,1,0 access_fsm_order_user,fsm.order.user,model_fsm_order,fieldservice.group_fsm_user,1,1,0,0 -access_fsm_order_dispatcher,fsm.order.dispatcher,model_fsm_order,fieldservice.group_fsm_dispatcher,1,1,1,0 -access_fsm_route_user,fsm.route.user,model_fsm_route,fieldservice.group_fsm_user,1,1,0,0 -access_fsm_route_dispatcher,fsm.route.dispatcher,model_fsm_route,fieldservice.group_fsm_dispatcher,1,1,1,1 -access_fsm_territory_user,territory.user,model_fsm_territory,fieldservice.group_fsm_user,1,0,0,0 -access_fsm_territory_manager,territory.manager,model_fsm_territory,fieldservice.group_fsm_manager,1,1,1,1 -access_fsm_branch_user,branch.user,model_fsm_branch,fieldservice.group_fsm_user,1,0,0,0 -access_fsm_branch_manager,branch.manager,model_fsm_branch,fieldservice.group_fsm_manager,1,1,1,1 -access_fsm_district_user,district.user,model_fsm_district,fieldservice.group_fsm_user,1,0,0,0 -access_fsm_district_manager,district.manager,model_fsm_district,fieldservice.group_fsm_manager,1,1,1,1 -access_fsm_region_user,region.user,model_fsm_region,fieldservice.group_fsm_user,1,0,0,0 -access_fsm_region_manager,region.manager,model_fsm_region,fieldservice.group_fsm_manager,1,1,1,1 +access_fsm_order_dispatcher,fsm.order.dispatcher,model_fsm_order,fieldservice.group_fsm_dispatcher,1,1,1,1 access_fsm_equipment_fsm_user,fsm.equipment.user,model_fsm_equipment,fieldservice.group_fsm_user,1,0,0,0 access_fsm_equipment_fsm_manager,fsm.equipment.manager,model_fsm_equipment,fieldservice.group_fsm_manager,1,1,1,1 access_fsm_category_user,fsm.category.user,model_fsm_category,fieldservice.group_fsm_user,1,0,0,0 @@ -29,3 +19,5 @@ access_fsm_team_user,fsm.team.user,model_fsm_team,fieldservice.group_fsm_user,1, access_fsm_team_manager,fsm.team.manager,model_fsm_team,fieldservice.group_fsm_manager,1,1,1,1 access_fsm_location_person_user,fsm.location.person.user,model_fsm_location_person,fieldservice.group_fsm_user,1,1,0,0 access_fsm_location_person_manager,fsm.location.person.manager,model_fsm_location_person,fieldservice.group_fsm_manager,1,1,1,1 +access_fsm_order_type_user,fsm.order.type.user,model_fsm_order_type,fieldservice.group_fsm_user,1,1,0,0 +access_fsm_order_type_manager,fsm.order.type.manager,model_fsm_order_type,fieldservice.group_fsm_manager,1,1,1,1 diff --git a/fieldservice/security/ir_rule.xml b/fieldservice/security/ir_rule.xml index ce879b1381..44f60fd36e 100644 --- a/fieldservice/security/ir_rule.xml +++ b/fieldservice/security/ir_rule.xml @@ -17,13 +17,6 @@ ['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])] - - FSM Routes Entry - - - ['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])] - - FSM Teams Entry @@ -52,4 +45,11 @@ ['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])] + + FSM Stage Entry + + + ['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])] + + diff --git a/fieldservice/security/res_groups.xml b/fieldservice/security/res_groups.xml index 67e98cc034..5ee8b223cf 100644 --- a/fieldservice/security/res_groups.xml +++ b/fieldservice/security/res_groups.xml @@ -1,4 +1,3 @@ - @@ -37,11 +36,6 @@ - - Manage Field Service Substatus - - - Manage Field Service Equipment diff --git a/fieldservice/static/description/index.html b/fieldservice/static/description/index.html index 9fe613a42e..a384057150 100644 --- a/fieldservice/static/description/index.html +++ b/fieldservice/static/description/index.html @@ -3,7 +3,7 @@ - + Field Service