From 31921650342672bf92d61396cf8e5420c0ad0c60 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 | 31 +- fieldservice/__init__.py | 1 - fieldservice/__manifest__.py | 112 ++-- 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 | 28 +- fieldservice/models/fsm_district.py | 14 - fieldservice/models/fsm_equipment.py | 106 ++-- fieldservice/models/fsm_location.py | 373 ++++++------ fieldservice/models/fsm_location_person.py | 39 +- fieldservice/models/fsm_order.py | 548 +++++++++--------- fieldservice/models/fsm_order_type.py | 10 + fieldservice/models/fsm_person.py | 139 +++-- fieldservice/models/fsm_region.py | 13 - fieldservice/models/fsm_route.py | 36 -- fieldservice/models/fsm_stage.py | 138 +++-- fieldservice/models/fsm_tag.py | 28 +- fieldservice/models/fsm_team.py | 104 ++-- fieldservice/models/fsm_template.py | 30 +- fieldservice/models/fsm_territory.py | 30 - fieldservice/models/res_company.py | 10 +- fieldservice/models/res_config_settings.py | 119 ++-- fieldservice/models/res_country.py | 10 - fieldservice/models/res_partner.py | 53 +- fieldservice/models/res_state.py | 10 - fieldservice/models/res_territory.py | 11 + fieldservice/readme/CONFIGURE.rst | 8 +- 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/tests/__init__.py | 1 - fieldservice/tests/test_fsm_equipment.py | 43 +- fieldservice/tests/test_fsm_location.py | 182 +++--- fieldservice/tests/test_fsm_order.py | 45 +- .../tests/test_fsm_order_template_onchange.py | 72 +-- fieldservice/tests/test_fsm_person.py | 23 +- fieldservice/tests/test_fsm_team.py | 35 +- fieldservice/tests/test_fsm_wizard.py | 29 +- 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 | 29 +- 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 | 2 - fieldservice/views/fsm_stage.xml | 5 +- fieldservice/views/fsm_tag.xml | 2 - fieldservice/views/fsm_team.xml | 3 - fieldservice/views/fsm_template.xml | 2 - fieldservice/views/fsm_territory.xml | 74 --- fieldservice/views/menu.xml | 52 +- fieldservice/views/res_config_settings.xml | 202 +++++-- fieldservice/views/res_partner.xml | 6 +- fieldservice/views/res_territory.xml | 29 + fieldservice/wizard/__init__.py | 1 - fieldservice/wizard/fsm_wizard.py | 58 +- fieldservice/wizard/fsm_wizard.xml | 5 +- 77 files changed, 1603 insertions(+), 1813 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/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_territory.xml create mode 100644 fieldservice/views/res_territory.xml 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..ed7a4d08c3 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 ============= @@ -89,12 +74,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 +190,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 +246,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..00ae50f80a 100644 --- a/fieldservice/__manifest__.py +++ b/fieldservice/__manifest__.py @@ -1,67 +1,59 @@ -# Copyright (C) 2018 - TODAY, Open Source Integrators +# Copyright (C) 2020 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { - 'name': 'Field Service', - 'summary': 'Manage Field Service Locations, Workers and Orders', - 'version': '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", + "category": "Field Service", + "author": "Open Source Integrators, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/field-service", + "depends": [ + "base_territory", + "base_geolocalize", + "web_timeline", + "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_schedule.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", ], + "qweb": ["static/src/xml/*.xml"], + "application": True, + "license": "AGPL-3", + "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..bb62bd0980 100644 --- a/fieldservice/models/fsm_category.py +++ b/fieldservice/models/fsm_category.py @@ -1,30 +1,32 @@ -# Copyright (C) 2018 - TODAY, Open Source Integrators +# Copyright (C) 2020 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models 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..88808276d3 100644 --- a/fieldservice/models/fsm_equipment.py +++ b/fieldservice/models/fsm_equipment.py @@ -1,98 +1,106 @@ -# Copyright (C) 2018 - TODAY, Open Source Integrators +# Copyright (C) 2020 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..150abbd11d 100644 --- a/fieldservice/models/fsm_location.py +++ b/fieldservice/models/fsm_location.py @@ -1,89 +1,102 @@ -# Copyright (C) 2018 - TODAY, Open Source Integrators +# Copyright (C) 2020 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..a5148a61b3 100644 --- a/fieldservice/models/fsm_location_person.py +++ b/fieldservice/models/fsm_location_person.py @@ -1,30 +1,31 @@ -# Copyright (C) 2018 - TODAY, Open Source Integrators +# Copyright (C) 2020 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class FSMLocationPerson(models.Model): - _name = 'fsm.location.person' - _description = 'Field Service Location Person Info' - _rec_name = 'location_id' - _order = 'sequence' + _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..8749b5650f 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) 2020 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..7b9b246c8b --- /dev/null +++ b/fieldservice/models/fsm_order_type.py @@ -0,0 +1,10 @@ +# Copyright (C) 2020 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..4a4256345c 100644 --- a/fieldservice/models/fsm_person.py +++ b/fieldservice/models/fsm_person.py @@ -1,116 +1,139 @@ -# Copyright (C) 2018 - TODAY, Open Source Integrators +# Copyright (C) 2020 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models class FSMPerson(models.Model): - _name = 'fsm.person' - _inherits = {'res.partner': 'partner_id'} - _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..24725d6b0d 100644 --- a/fieldservice/models/fsm_stage.py +++ b/fieldservice/models/fsm_stage.py @@ -1,77 +1,107 @@ -# Copyright (C) 2018 - TODAY, Open Source Integrators +# Copyright (C) 2020 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..ee6a313840 100644 --- a/fieldservice/models/fsm_tag.py +++ b/fieldservice/models/fsm_tag.py @@ -1,29 +1,31 @@ -# Copyright (C) 2018 - TODAY, Open Source Integrators +# Copyright (C) 2020 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class FSMTag(models.Model): - _name = 'fsm.tag' - _description = 'Field Service Tag' + _name = "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..bed8b78592 100644 --- a/fieldservice/models/fsm_team.py +++ b/fieldservice/models/fsm_team.py @@ -1,80 +1,82 @@ -# Copyright (C) 2018 - TODAY, Brian McMaster +# Copyright (C) 2018 Brian McMaster +# Copyright (C) 2020 Open Source Integrators # 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..5f59abd64a 100644 --- a/fieldservice/models/fsm_template.py +++ b/fieldservice/models/fsm_template.py @@ -1,22 +1,28 @@ -# Copyright (C) 2018 - TODAY, Open Source Integrators +# Copyright (C) 2020 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class FSMTemplate(models.Model): - _name = 'fsm.template' - _description = 'Field Service Order Template' + _name = "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..e4ba8d9ed9 100644 --- a/fieldservice/models/res_company.py +++ b/fieldservice/models/res_company.py @@ -1,11 +1,15 @@ -# Copyright (C) 2019 - TODAY, Open Source Integrators +# Copyright (C) 2020 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class ResCompany(models.Model): - _inherit = 'res.company' + _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..5252c4705b 100644 --- a/fieldservice/models/res_config_settings.py +++ b/fieldservice/models/res_config_settings.py @@ -1,87 +1,102 @@ -# Copyright (C) 2018 - TODAY, Open Source Integrators +# Copyright (C) 2020 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models class ResConfigSettings(models.TransientModel): - _inherit = 'res.config.settings' + _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") # 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..29a06fac30 100644 --- a/fieldservice/models/res_partner.py +++ b/fieldservice/models/res_partner.py @@ -1,45 +1,44 @@ -# Copyright (C) 2018 - TODAY, Open Source Integrators +# Copyright (C) 2020 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..0b2c01128c --- /dev/null +++ b/fieldservice/models/res_territory.py @@ -0,0 +1,11 @@ +# Copyright (C) 2020 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResTerritory(models.Model): + _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..66777ea67e 100644 --- a/fieldservice/readme/CONFIGURE.rst +++ b/fieldservice/readme/CONFIGURE.rst @@ -22,7 +22,7 @@ You need to add attribute mention below with the tag as base element. 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 + implement this as. Define any one stage color condition like colors="#ffffff:stage_id=='New';" Field Service Areas @@ -37,12 +37,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/tests/__init__.py b/fieldservice/tests/__init__.py index 2dacb17345..673737b616 100644 --- a/fieldservice/tests/__init__.py +++ b/fieldservice/tests/__init__.py @@ -1,4 +1,3 @@ -# Copyright (C) 2019 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from . import test_fsm_wizard diff --git a/fieldservice/tests/test_fsm_equipment.py b/fieldservice/tests/test_fsm_equipment.py index e6387b35fb..c0149f219d 100644 --- a/fieldservice/tests/test_fsm_equipment.py +++ b/fieldservice/tests/test_fsm_equipment.py @@ -1,20 +1,19 @@ -# Copyright (C) 2019 - TODAY, Open Source Integrators +# Copyright (C) 2020 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo.tests.common import TransactionCase, Form +from odoo.tests.common import Form, TransactionCase class FSMEquipment(TransactionCase): - def setUp(self): super(FSMEquipment, self).setUp() - self.Equipment = self.env['fsm.equipment'] - self.test_location = self.env.ref('fieldservice.test_location') - self.test_territory = self.env.ref('fieldservice.test_territory') - self.test_branch = self.env.ref('fieldservice.test_branch') - self.test_district = self.env.ref('fieldservice.test_district') - self.test_region = self.env.ref('fieldservice.test_region') - self.current_location = self.env.ref('fieldservice.location_1') + self.Equipment = self.env["fsm.equipment"] + self.test_location = self.env.ref("fieldservice.test_location") + self.test_territory = self.env.ref("base_territory.test_territory") + self.test_branch = self.env.ref("base_territory.test_branch") + self.test_district = self.env.ref("base_territory.test_district") + self.test_region = self.env.ref("base_territory.test_region") + self.current_location = self.env.ref("fieldservice.location_1") def test_fsm_equipment(self): """ Test createing new equipment @@ -23,9 +22,9 @@ def test_fsm_equipment(self): - Change stage """ # Create an equipment - view_id = ('fieldservice.fsm_equipment_form_view') + view_id = "fieldservice.fsm_equipment_form_view" with Form(self.Equipment, view=view_id) as f: - f.name = 'Equipment 1' + f.name = "Equipment 1" f.current_location_id = self.current_location f.location_id = self.test_location equipment = f.save() @@ -35,16 +34,20 @@ def test_fsm_equipment(self): self.assertEqual(self.test_district, equipment.district_id) self.assertEqual(self.test_region, equipment.region_id) # Test initial stage - self.assertEqual(equipment.stage_id, - self.env.ref('fieldservice.equipment_stage_1')) + self.assertEqual( + equipment.stage_id, self.env.ref("fieldservice.equipment_stage_1") + ) # Test change state equipment.next_stage() - self.assertEqual(equipment.stage_id, - self.env.ref('fieldservice.equipment_stage_2')) + self.assertEqual( + equipment.stage_id, self.env.ref("fieldservice.equipment_stage_2") + ) equipment.next_stage() - self.assertEqual(equipment.stage_id, - self.env.ref('fieldservice.equipment_stage_3')) + self.assertEqual( + equipment.stage_id, self.env.ref("fieldservice.equipment_stage_3") + ) self.assertTrue(equipment.hide) # hide as max stage equipment.previous_stage() - self.assertEqual(equipment.stage_id, - self.env.ref('fieldservice.equipment_stage_2')) + self.assertEqual( + equipment.stage_id, self.env.ref("fieldservice.equipment_stage_2") + ) diff --git a/fieldservice/tests/test_fsm_location.py b/fieldservice/tests/test_fsm_location.py index 27a98a3ed4..a253e2f898 100644 --- a/fieldservice/tests/test_fsm_location.py +++ b/fieldservice/tests/test_fsm_location.py @@ -1,29 +1,24 @@ -# Copyright (C) 2019 - TODAY, Open Source Integrators +# Copyright (C) 2020 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo.tests.common import TransactionCase, Form from odoo.exceptions import ValidationError +from odoo.tests.common import Form, TransactionCase class FSMLocation(TransactionCase): - def setUp(self): super(FSMLocation, self).setUp() - self.Location = self.env['fsm.location'] - self.Equipment = self.env['fsm.equipment'] - self.test_location = self.env.ref('fieldservice.test_location') - self.location_1 = self.env.ref('fieldservice.location_1') - self.location_2 = self.env.ref('fieldservice.location_2') - self.location_3 = self.env.ref('fieldservice.location_3') - self.test_territory = self.env.ref('fieldservice.test_territory') - self.test_loc_partner = self.env.ref('fieldservice.' - 'test_loc_partner') - self.location_partner_1 = self.env.ref('fieldservice.' - 'location_partner_1') - self.location_partner_2 = self.env.ref('fieldservice.' - 'location_partner_2') - self.location_partner_3 = self.env.ref('fieldservice.' - 'location_partner_3') + self.Location = self.env["fsm.location"] + self.Equipment = self.env["fsm.equipment"] + self.test_location = self.env.ref("fieldservice.test_location") + self.location_1 = self.env.ref("fieldservice.location_1") + self.location_2 = self.env.ref("fieldservice.location_2") + self.location_3 = self.env.ref("fieldservice.location_3") + self.test_territory = self.env.ref("base_territory.test_territory") + self.test_loc_partner = self.env.ref("fieldservice.test_loc_partner") + self.location_partner_1 = self.env.ref("fieldservice.location_partner_1") + self.location_partner_2 = self.env.ref("fieldservice.location_partner_2") + self.location_partner_3 = self.env.ref("fieldservice.location_partner_3") def test_fsm_location(self): """ Test createing new location @@ -33,37 +28,53 @@ def test_fsm_location(self): - Create fsm.location.person if auto_populate_persons_on_location """ # Create an equipment - view_id = ('fieldservice.fsm_location_form_view') + view_id = "fieldservice.fsm_location_form_view" with Form(self.Location, view=view_id) as f: - f.name = 'Child Location' + f.name = "Child Location" f.fsm_parent_id = self.test_location location = f.save() # Test child location equal to parent location - for x in ['owner_id', 'customer_id', 'contact_id', 'direction', - 'street', 'street2', 'city', 'zip', 'state_id', 'country_id', - 'tz', 'territory_id']: + for x in [ + "owner_id", + "contact_id", + "direction", + "street", + "street2", + "city", + "zip", + "state_id", + "country_id", + "tz", + "territory_id", + ]: self.assertEqual(location[x], self.test_location[x]) # Test initial stage - self.assertEqual(location.stage_id, - self.env.ref('fieldservice.location_stage_1')) + self.assertEqual( + location.stage_id, self.env.ref("fieldservice.location_stage_1") + ) # Test change state location.next_stage() - self.assertEqual(location.stage_id, - self.env.ref('fieldservice.location_stage_2')) + self.assertEqual( + location.stage_id, self.env.ref("fieldservice.location_stage_2") + ) location.next_stage() - self.assertEqual(location.stage_id, - self.env.ref('fieldservice.location_stage_3')) + self.assertEqual( + location.stage_id, self.env.ref("fieldservice.location_stage_3") + ) self.assertTrue(location.hide) # hide as max stage location.previous_stage() - self.assertEqual(location.stage_id, - self.env.ref('fieldservice.location_stage_2')) + self.assertEqual( + location.stage_id, self.env.ref("fieldservice.location_stage_2") + ) # Test create fsm.location.person, when has if territory has person_ids self.env.user.company_id.auto_populate_persons_on_location = True - person_ids = [self.env.ref('fieldservice.person_1').id, - self.env.ref('fieldservice.person_2').id, - self.env.ref('fieldservice.person_3').id] - self.test_territory.write({'person_ids': [(6, 0, person_ids)]}) + person_ids = [ + self.env.ref("fieldservice.person_1").id, + self.env.ref("fieldservice.person_2").id, + self.env.ref("fieldservice.person_3").id, + ] + self.test_territory.write({"person_ids": [(6, 0, person_ids)]}) location.territory_id = self.test_territory self.assertEqual(len(location.person_ids), 0) location._onchange_territory_id() @@ -79,16 +90,22 @@ def test_fsm_multi_sublocation(self): self.location_2.fsm_parent_id = self.location_1 self.location_1.fsm_parent_id = self.test_location # Test sublocation_count of each level - self.assertEqual((self.test_location.sublocation_count, - self.location_1.sublocation_count, - self.location_2.sublocation_count, - self.location_3.sublocation_count), (3, 2, 1, 0)) - loc_ids = self.test_location.action_view_sublocation()['domain'][0][2] - loc_1_ids = self.location_1.action_view_sublocation()['domain'][0][2] - loc_2_ids = [self.location_2.action_view_sublocation()['res_id']] - loc_3_ids = self.location_3.action_view_sublocation()['domain'][0][2] - self.assertEqual((len(loc_ids), len(loc_1_ids), len(loc_2_ids), - len(loc_3_ids)), (3, 2, 1, 0)) + self.assertEqual( + ( + self.test_location.sublocation_count, + self.location_1.sublocation_count, + self.location_2.sublocation_count, + self.location_3.sublocation_count, + ), + (3, 2, 1, 0), + ) + loc_ids = self.test_location.action_view_sublocation()["domain"][0][2] + loc_1_ids = self.location_1.action_view_sublocation()["domain"][0][2] + loc_2_ids = [self.location_2.action_view_sublocation()["res_id"]] + loc_3_ids = self.location_3.action_view_sublocation()["domain"][0][2] + self.assertEqual( + (len(loc_ids), len(loc_1_ids), len(loc_2_ids), len(loc_3_ids)), (3, 2, 1, 0) + ) # Test recursion exception with self.assertRaises(ValidationError): @@ -96,28 +113,40 @@ def test_fsm_multi_sublocation(self): self.test_location.fsm_parent_id = False # Set back # Add equipments on each locations, and test counting - location_vs_num_eq = {self.test_location.id: 1, # Topup = 9 - self.location_1.id: 1, # Topup = 8 - self.location_2.id: 5, # Topup = 7 - self.location_3.id: 2} # Topup = 2 + location_vs_num_eq = { + self.test_location.id: 1, # Topup = 9 + self.location_1.id: 1, # Topup = 8 + self.location_2.id: 5, # Topup = 7 + self.location_3.id: 2, + } # Topup = 2 for loc_id, num_eq in location_vs_num_eq.items(): for i in range(num_eq): - self.Equipment.create({ - 'name': 'Eq-%s-%s' % (str(loc_id), str(i+1)), - 'location_id': loc_id, - 'current_location_id': loc_id, }) + self.Equipment.create( + { + "name": "Eq-{}-{}".format(str(loc_id), str(i + 1)), + "location_id": loc_id, + "current_location_id": loc_id, + } + ) # Test valid equipments at each location - self.assertEqual((self.test_location.equipment_count, - self.location_1.equipment_count, - self.location_2.equipment_count, - self.location_3.equipment_count), (9, 8, 7, 2)) # !! + self.assertEqual( + ( + self.test_location.equipment_count, + self.location_1.equipment_count, + self.location_2.equipment_count, + self.location_3.equipment_count, + ), + (9, 8, 7, 2), + ) # !! # Test smart button to open equipment - loc_eq_ids = self.test_location.action_view_equipment()['domain'][0][2] - loc_1_eq_ids = self.location_1.action_view_equipment()['domain'][0][2] - loc_2_eq_ids = self.location_2.action_view_equipment()['domain'][0][2] - loc_3_eq_ids = self.location_3.action_view_equipment()['domain'][0][2] - self.assertEqual((len(loc_eq_ids), len(loc_1_eq_ids), - len(loc_2_eq_ids), len(loc_3_eq_ids)), (9, 8, 7, 2)) + loc_eq_ids = self.test_location.action_view_equipment()["domain"][0][2] + loc_1_eq_ids = self.location_1.action_view_equipment()["domain"][0][2] + loc_2_eq_ids = self.location_2.action_view_equipment()["domain"][0][2] + loc_3_eq_ids = self.location_3.action_view_equipment()["domain"][0][2] + self.assertEqual( + (len(loc_eq_ids), len(loc_1_eq_ids), len(loc_2_eq_ids), len(loc_3_eq_ids)), + (9, 8, 7, 2), + ) # Set service_location_id, on relavant res.partner, test contact count self.test_loc_partner.service_location_id = self.test_location @@ -125,14 +154,21 @@ def test_fsm_multi_sublocation(self): self.location_partner_2.service_location_id = self.location_2 self.location_partner_3.service_location_id = self.location_3 # Test valid contacts at each location - self.assertEqual((self.test_location.contact_count, - self.location_1.contact_count, - self.location_2.contact_count, - self.location_3.contact_count), (4, 3, 2, 1)) + self.assertEqual( + ( + self.test_location.contact_count, + self.location_1.contact_count, + self.location_2.contact_count, + self.location_3.contact_count, + ), + (4, 3, 2, 1), + ) # Test smart button to open contacts - cont_ids = self.test_location.action_view_contacts()['domain'][0][2] - cont_1_ids = self.location_1.action_view_contacts()['domain'][0][2] - cont_2_ids = self.location_2.action_view_contacts()['domain'][0][2] - cont_3_ids = [self.location_3.action_view_contacts()['res_id']] - self.assertEqual((len(cont_ids), len(cont_1_ids), - len(cont_2_ids), len(cont_3_ids)), (4, 3, 2, 1)) + cont_ids = self.test_location.action_view_contacts()["domain"][0][2] + cont_1_ids = self.location_1.action_view_contacts()["domain"][0][2] + cont_2_ids = self.location_2.action_view_contacts()["domain"][0][2] + cont_3_ids = [self.location_3.action_view_contacts()["res_id"]] + self.assertEqual( + (len(cont_ids), len(cont_1_ids), len(cont_2_ids), len(cont_3_ids)), + (4, 3, 2, 1), + ) diff --git a/fieldservice/tests/test_fsm_order.py b/fieldservice/tests/test_fsm_order.py index 58ade20665..8405671ffb 100644 --- a/fieldservice/tests/test_fsm_order.py +++ b/fieldservice/tests/test_fsm_order.py @@ -1,17 +1,17 @@ -# Copyright (C) 2019 - TODAY, Open Source Integrators +# Copyright (C) 2020 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from datetime import timedelta + from odoo import fields -from odoo.tests.common import TransactionCase, Form +from odoo.tests.common import Form, TransactionCase class TestFSMOrder(TransactionCase): - def setUp(self): super(TestFSMOrder, self).setUp() - self.Order = self.env['fsm.order'] - self.test_location = self.env.ref('fieldservice.test_location') + self.Order = self.env["fsm.order"] + self.test_location = self.env.ref("fieldservice.test_location") def test_fsm_order(self): """ Test creating new workorders, and test following functions, @@ -21,7 +21,7 @@ def test_fsm_order(self): - scheduled_date_end = scheduled_date_start + duration (hrs) """ # Create an Orders - view_id = ('fieldservice.fsm_order_form') + view_id = "fieldservice.fsm_order_form" hours_diff = 100 with Form(self.Order, view=view_id) as f: f.location_id = self.test_location @@ -32,35 +32,38 @@ def test_fsm_order(self): # Test _compute_duration self.assertEqual(order.duration, hours_diff) # Test _compute_request_late() - priority_vs_late_days = {'0': 3, '1': 2, '2': 1, '3': 1/3} + priority_vs_late_days = {"0": 3, "1": 2, "2": 1, "3": 1 / 3} for priority, late_days in priority_vs_late_days.items(): order.priority = priority order.request_late = False - vals = { - 'request_early': fields.Datetime.today(), - 'priority': priority - } + vals = {"request_early": fields.Datetime.today(), "priority": priority} vals = order._compute_request_late(vals) - self.assertEqual(vals['request_late'], - order.request_early + timedelta(days=late_days)) + self.assertEqual( + vals["request_late"], order.request_early + timedelta(days=late_days) + ) # Test set scheduled_date_start using request_early w/o time - self.assertEqual(order.scheduled_date_start, - order.request_early.replace(minute=0, second=0)) + self.assertEqual( + order.scheduled_date_start, order.request_early.replace(minute=0, second=0) + ) # Test scheduled_date_end = scheduled_date_start + duration (hrs) # Set date start - order.scheduled_date_start = \ - order.scheduled_date_start.replace(hour=0, minute=0, second=0) + order.scheduled_date_start = order.scheduled_date_start.replace( + hour=0, minute=0, second=0 + ) # Set duration duration = 10 order.scheduled_duration = duration # Check date end self.assertEqual( order.scheduled_date_end, - order.scheduled_date_start + timedelta(hours=duration)) + order.scheduled_date_start + timedelta(hours=duration), + ) # Set new date end - order.scheduled_date_end = \ - order.scheduled_date_end.replace(hour=1, minute=1, second=1) + order.scheduled_date_end = order.scheduled_date_end.replace( + hour=1, minute=1, second=0 + ) # Check date start self.assertEqual( order.scheduled_date_start, - order.scheduled_date_end - timedelta(hours=duration)) + order.scheduled_date_end - timedelta(hours=duration), + ) diff --git a/fieldservice/tests/test_fsm_order_template_onchange.py b/fieldservice/tests/test_fsm_order_template_onchange.py index 01519f3b31..93238ff622 100644 --- a/fieldservice/tests/test_fsm_order_template_onchange.py +++ b/fieldservice/tests/test_fsm_order_template_onchange.py @@ -1,25 +1,20 @@ # Copyright (C) 2019 Brian McMaster +# Copyright (C) 2020 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields + from . import test_fsm_order class TestTemplateOnchange(test_fsm_order.TestFSMOrder): - def setUp(self): super(TestTemplateOnchange, self).setUp() - self.fsm_category_a = self.env['fsm.category'].create({ - 'name': 'Category A' - }) - self.fsm_category_b = self.env['fsm.category'].create({ - 'name': 'Category B' - }) - self.fsm_type_a = self.env['fsm.order.type'].create({ - 'name': 'FSM Order Type A' - }) - self.fsm_team_a = self.env['fsm.team'].create({ - 'name': 'FSM Team A' - }) + self.fsm_category_a = self.env["fsm.category"].create({"name": "Category A"}) + self.fsm_category_b = self.env["fsm.category"].create({"name": "Category B"}) + self.fsm_type_a = self.env["fsm.order.type"].create( + {"name": "FSM Order Type A"} + ) + self.fsm_team_a = self.env["fsm.team"].create({"name": "FSM Team A"}) def test_fsm_order_onchange_template(self): """ Test the onchange function for FSM Template @@ -29,37 +24,28 @@ def test_fsm_order_onchange_template(self): categories = [] categories.append(self.fsm_category_a.id) categories.append(self.fsm_category_b.id) - self.fsm_template_1 = self.env['fsm.template'].create({ - 'name': 'Test FSM Template #1', - 'instructions': 'These are the instructions for Template #1', - 'category_ids': (6, 0, categories), - 'hours': 2.25, - 'type_id': self.fsm_type_a.id, - 'team_id': self.fsm_team_a.id, - }) - self.fso = self.Order.create({ - 'location_id': self.test_location.id, - 'template_id': self.fsm_template_1.id, - 'scheduled_date_start': fields.Datetime.today(), - }) - self.fso._onchange_template_id() - self.assertEqual( - self.fso.category_ids.ids, - self.fsm_template_1.category_ids.ids + self.fsm_template_1 = self.env["fsm.template"].create( + { + "name": "Test FSM Template #1", + "instructions": "These are the instructions for Template #1", + "category_ids": [(6, 0, categories)], + "hours": 2.25, + "type_id": self.fsm_type_a.id, + "team_id": self.fsm_team_a.id, + } ) - self.assertEqual( - self.fso.scheduled_duration, - self.fsm_template_1.hours - ) - self.assertEqual( - self.fso.type.id, - self.fsm_template_1.type_id.id - ) - self.assertEqual( - self.fso.todo, - self.fsm_template_1.instructions + self.fso = self.Order.create( + { + "location_id": self.test_location.id, + "template_id": self.fsm_template_1.id, + "scheduled_date_start": fields.Datetime.today(), + } ) + self.fso._onchange_template_id() self.assertEqual( - self.fso.team_id.id, - self.fsm_team_a.id + self.fso.category_ids.ids, self.fsm_template_1.category_ids.ids ) + self.assertEqual(self.fso.scheduled_duration, self.fsm_template_1.hours) + self.assertEqual(self.fso.type.id, self.fsm_template_1.type_id.id) + self.assertEqual(self.fso.todo, self.fsm_template_1.instructions) + self.assertEqual(self.fso.team_id.id, self.fsm_team_a.id) diff --git a/fieldservice/tests/test_fsm_person.py b/fieldservice/tests/test_fsm_person.py index c5d7e94528..6dc9e55e0f 100644 --- a/fieldservice/tests/test_fsm_person.py +++ b/fieldservice/tests/test_fsm_person.py @@ -1,14 +1,13 @@ -# Copyright (C) 2019 - TODAY, Open Source Integrators +# Copyright (C) 2020 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo.tests.common import TransactionCase, Form +from odoo.tests.common import Form, TransactionCase class FSMPerson(TransactionCase): - def setUp(self): super(FSMPerson, self).setUp() - self.Worker = self.env['fsm.person'] + self.Worker = self.env["fsm.person"] def test_fsm_location(self): """ Test createing new person @@ -17,23 +16,19 @@ def test_fsm_location(self): - _search """ # Create an equipment - view_id = ('fieldservice.fsm_person_form') + view_id = "fieldservice.fsm_person_form" with Form(self.Worker, view=view_id) as f: - f.name = 'Worker A' + f.name = "Worker A" worker = f.save() # Test initial stage - self.assertEqual(worker.stage_id, - self.env.ref('fieldservice.worker_stage_1')) + self.assertEqual(worker.stage_id, self.env.ref("fieldservice.worker_stage_1")) # Test change state worker.next_stage() - self.assertEqual(worker.stage_id, - self.env.ref('fieldservice.worker_stage_2')) + self.assertEqual(worker.stage_id, self.env.ref("fieldservice.worker_stage_2")) worker.next_stage() - self.assertEqual(worker.stage_id, - self.env.ref('fieldservice.worker_stage_3')) + self.assertEqual(worker.stage_id, self.env.ref("fieldservice.worker_stage_3")) self.assertTrue(worker.hide) # hide as max stage worker.previous_stage() - self.assertEqual(worker.stage_id, - self.env.ref('fieldservice.worker_stage_2')) + self.assertEqual(worker.stage_id, self.env.ref("fieldservice.worker_stage_2")) # TODO: https://github.com/OCA/field-service/issues/265 diff --git a/fieldservice/tests/test_fsm_team.py b/fieldservice/tests/test_fsm_team.py index 13905e8acb..51f2ff008d 100644 --- a/fieldservice/tests/test_fsm_team.py +++ b/fieldservice/tests/test_fsm_team.py @@ -1,17 +1,16 @@ -# Copyright (C) 2019 - TODAY, Open Source Integrators +# Copyright (C) 2020 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo.tests.common import TransactionCase, Form +from odoo.tests.common import Form, TransactionCase class FSMTeam(TransactionCase): - def setUp(self): super(FSMTeam, self).setUp() - self.Order = self.env['fsm.order'] - self.Team = self.env['fsm.team'] - self.test_location = self.env.ref('fieldservice.test_location') - self.test_team = self.Team.create({'name': 'Test Team'}) + self.Order = self.env["fsm.order"] + self.Team = self.env["fsm.team"] + self.test_location = self.env.ref("fieldservice.test_location") + self.test_team = self.Team.create({"name": "Test Team"}) def test_fsm_order(self): """ Test creating new workorders @@ -22,20 +21,26 @@ def test_fsm_order(self): # Create 5 Orders, which are, # - 2 assigned (3 unassigned) # - 4 scheduled (1 unscheduled) - todo = {'orders': 5, 'assigned': [3, 4], 'scheduled': [0, 1, 2, 3]} - view_id = ('fieldservice.fsm_order_form') + todo = {"orders": 5, "assigned": [3, 4], "scheduled": [0, 1, 2, 3]} + view_id = "fieldservice.fsm_order_form" orders = self.Order - for i in range(todo['orders']): + for i in range(todo["orders"]): with Form(self.Order, view=view_id) as f: f.location_id = self.test_location f.team_id = self.test_team order = f.save() orders += order - order.person_id = i in todo['assigned'] and \ - self.env.ref('fieldservice.person_1') or False + order.person_id = ( + i in todo["assigned"] and self.env.ref("fieldservice.person_1") or False + ) # TODO: after this https://github.com/OCA/field-service/issues/266 # assert should then be (5, 3, 1) # order.scheduled_date_start = False - self.assertEqual((self.test_team.order_count, - self.test_team.order_need_assign_count, - self.test_team.order_need_schedule_count), (5, 3, 0)) + self.assertEqual( + ( + self.test_team.order_count, + self.test_team.order_need_assign_count, + self.test_team.order_need_schedule_count, + ), + (5, 3, 0), + ) diff --git a/fieldservice/tests/test_fsm_wizard.py b/fieldservice/tests/test_fsm_wizard.py index bfdeba009a..4d8e7f23ae 100644 --- a/fieldservice/tests/test_fsm_wizard.py +++ b/fieldservice/tests/test_fsm_wizard.py @@ -1,4 +1,4 @@ -# Copyright (C) 2019 - TODAY, Open Source Integrators +# Copyright (C) 2020 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo.tests.common import TransactionCase @@ -14,23 +14,24 @@ class FSMWizard(TransactionCase): - test_convert_sublocation: tests that the sub-contacts on a res.partner are converted into Other Addresses. """ + def setUp(self): super(FSMWizard, self).setUp() - self.Wizard = self.env['fsm.wizard'] - self.test_partner = self.env.ref('fieldservice.test_partner') - self.test_parent_partner = \ - self.env.ref('fieldservice.test_parent_partner') - self.test_loc_partner = self.env.ref('fieldservice.test_loc_partner') - self.test_location = self.env.ref('fieldservice.test_location') - self.test_person = self.env.ref('fieldservice.test_person') + self.Wizard = self.env["fsm.wizard"] + self.test_partner = self.env.ref("fieldservice.test_partner") + self.test_parent_partner = self.env.ref("fieldservice.test_parent_partner") + self.test_loc_partner = self.env.ref("fieldservice.test_loc_partner") + self.test_location = self.env.ref("fieldservice.test_location") + self.test_person = self.env.ref("fieldservice.test_person") def test_convert_location(self): # convert test_partner to FSM Location self.Wizard.action_convert_location(self.test_partner) # check if there is a new FSM Location with name 'Test Partner' - self.wiz_location = self.env['fsm.location'].\ - search([('name', '=', 'Test Partner')]) + self.wiz_location = self.env["fsm.location"].search( + [("name", "=", "Test Partner")] + ) # check if 'Test Partner' creation successful and fields copied over self.assertEqual(self.test_location.phone, self.wiz_location.phone) @@ -41,8 +42,7 @@ def test_convert_person(self): self.Wizard.action_convert_person(self.test_partner) # check if there is a new FSM Person with name 'Test Partner' - self.wiz_person = self.env['fsm.person'].\ - search([('name', '=', 'Test Partner')]) + self.wiz_person = self.env["fsm.person"].search([("name", "=", "Test Partner")]) # check if 'Test Partner' creation successful and fields copied over self.assertEqual(self.test_person.phone, self.wiz_person.phone) @@ -53,9 +53,8 @@ def test_convert_sublocation(self): self.Wizard.action_convert_location(self.test_parent_partner) # check if 'Parent Partner' creation successful and fields copied over - wiz_parent = self.env['fsm.location'].\ - search([('name', '=', 'Parent Partner')]) + wiz_parent = self.env["fsm.location"].search([("name", "=", "Parent Partner")]) # check all children were assigned type 'other' for child in wiz_parent.child_ids: - self.assertEqual(child.type, 'other') + self.assertEqual(child.type, "other") diff --git a/fieldservice/views/fsm_branch.xml b/fieldservice/views/fsm_branch.xml deleted file mode 100644 index 7e642b122b..0000000000 --- a/fieldservice/views/fsm_branch.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - fsm.branch.tree - fsm.branch - - - - - - - - - - - fsm.branch.form - fsm.branch - -
- - -
-
-
- - - Branches - fsm.branch - - form - tree,form - - -
diff --git a/fieldservice/views/fsm_category.xml b/fieldservice/views/fsm_category.xml index 06645ea036..5c8193b01c 100644 --- a/fieldservice/views/fsm_category.xml +++ b/fieldservice/views/fsm_category.xml @@ -1,4 +1,3 @@ - @@ -45,7 +44,6 @@ Field Service Category fsm.category - form tree,form

diff --git a/fieldservice/views/fsm_district.xml b/fieldservice/views/fsm_district.xml deleted file mode 100644 index c4f36f416b..0000000000 --- a/fieldservice/views/fsm_district.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - fsm.district.tree - fsm.district - - - - - - - - - - - fsm.district.form - fsm.district - -

- - -
-
-
- - - Districts - fsm.district - - form - tree,form - - -
diff --git a/fieldservice/views/fsm_equipment.xml b/fieldservice/views/fsm_equipment.xml index a258cb2432..a3d92ed325 100644 --- a/fieldservice/views/fsm_equipment.xml +++ b/fieldservice/views/fsm_equipment.xml @@ -1,4 +1,3 @@ - @@ -41,6 +40,8 @@ + +
@@ -123,7 +124,6 @@ Field Service Equipment fsm.equipment - form tree,form {'default_location_id': @@ -195,7 +195,6 @@ Field Service Equipment fsm.equipment - form tree,kanban,form

@@ -228,7 +227,6 @@ Equipments fsm.equipment - form graph,pivot

diff --git a/fieldservice/views/fsm_location.xml b/fieldservice/views/fsm_location.xml index 590e8047ca..4bc5621b93 100644 --- a/fieldservice/views/fsm_location.xml +++ b/fieldservice/views/fsm_location.xml @@ -1,4 +1,3 @@ - @@ -18,7 +17,6 @@ - @@ -71,7 +69,6 @@ - @@ -155,7 +152,6 @@ string="Location"/> - @@ -174,7 +170,6 @@ - @@ -184,7 +179,6 @@ Service Locations fsm.location - form tree,form @@ -217,7 +211,6 @@ Locations fsm.location - form pivot,graph

diff --git a/fieldservice/views/fsm_location_person.xml b/fieldservice/views/fsm_location_person.xml index b30bad35ba..f248fdc526 100644 --- a/fieldservice/views/fsm_location_person.xml +++ b/fieldservice/views/fsm_location_person.xml @@ -1,4 +1,3 @@ - @@ -25,7 +24,6 @@ - @@ -59,7 +57,6 @@ Location Persons fsm.location.person - form tree,form diff --git a/fieldservice/views/fsm_order.xml b/fieldservice/views/fsm_order.xml index d3bba25256..5dbe482073 100644 --- a/fieldservice/views/fsm_order.xml +++ b/fieldservice/views/fsm_order.xml @@ -1,4 +1,3 @@ - @@ -21,7 +20,8 @@ attrs="{'invisible': [('stage_id', 'in', (%(fieldservice.fsm_stage_completed)d, %(fieldservice.fsm_stage_cancelled)d))]}"/> + domain="[('stage_type', '=', 'order'), + ('team_ids', 'in', (team_id, False))]"/>

@@ -32,7 +32,7 @@
- + - @@ -75,11 +74,8 @@ - - - + + @@ -130,6 +126,8 @@ + + @@ -153,7 +151,6 @@ - @@ -166,7 +163,6 @@ Orders fsm.order - form tree,form

@@ -182,10 +178,9 @@ + options='{"group_by_tooltip": {"description": "Description"}}'/> - @@ -226,11 +221,6 @@ widget="many2many_tags" options="{'color_field': 'color'}"/>

-
- - - -
@@ -359,7 +349,6 @@ - @@ -371,7 +360,6 @@ Orders fsm.order - form kanban,timeline,tree,form,calendar @@ -405,7 +393,6 @@ Orders fsm.order - form graph,pivot

diff --git a/fieldservice/views/fsm_order_type.xml b/fieldservice/views/fsm_order_type.xml new file mode 100644 index 0000000000..6d6d54d642 --- /dev/null +++ b/fieldservice/views/fsm_order_type.xml @@ -0,0 +1,35 @@ + + + + + fsm.order.type.tree + fsm.order.type + + + + + + + + + + fsm.order.type.form + fsm.order.type + +

+ + +
+
+
+ + + Order Types + fsm.order.type + + tree,form + + + diff --git a/fieldservice/views/fsm_person.xml b/fieldservice/views/fsm_person.xml index e91af5f253..b9412e361b 100644 --- a/fieldservice/views/fsm_person.xml +++ b/fieldservice/views/fsm_person.xml @@ -1,4 +1,3 @@ - @@ -89,7 +88,6 @@ -
@@ -108,7 +106,6 @@ Field Service Workers fsm.person - form tree,form diff --git a/fieldservice/views/fsm_region.xml b/fieldservice/views/fsm_region.xml deleted file mode 100644 index 18ee0ab593..0000000000 --- a/fieldservice/views/fsm_region.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - fsm.region.tree - fsm.region - - - - - - - - - - fsm.region.form - fsm.region - -
- - -
-
-
- - - Regions - fsm.region - - form - tree,form - - -
diff --git a/fieldservice/views/fsm_route.xml b/fieldservice/views/fsm_route.xml deleted file mode 100644 index bce7ded173..0000000000 --- a/fieldservice/views/fsm_route.xml +++ /dev/null @@ -1,111 +0,0 @@ - - - - - - fsm.route.tree - fsm.route - - - - - - - - - - - - fsm.route.form - fsm.route - -
- -
-

- -

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-
-
- - - Day Routes - fsm.route - form - tree,form - -

- Add Day Routes here. -

-
-
- - - - fsm.route.graph - fsm.route - - - - - - - - - fsm.route.pivot - fsm.route - - - - - - - - - Day Routes - fsm.route - form - graph,pivot - -

- Day Routes Report -

-
-
- -
diff --git a/fieldservice/views/fsm_schedule.xml b/fieldservice/views/fsm_schedule.xml index 9f031c2db4..b9b53a3e6a 100644 --- a/fieldservice/views/fsm_schedule.xml +++ b/fieldservice/views/fsm_schedule.xml @@ -1,4 +1,3 @@ - @@ -29,7 +28,6 @@ Schedules resource.calendar - form tree,form

diff --git a/fieldservice/views/fsm_stage.xml b/fieldservice/views/fsm_stage.xml index 0e8d8d91e0..487cfed495 100644 --- a/fieldservice/views/fsm_stage.xml +++ b/fieldservice/views/fsm_stage.xml @@ -1,4 +1,3 @@ - @@ -26,7 +25,7 @@ - @@ -36,6 +35,7 @@ + @@ -52,7 +52,6 @@ Stages fsm.stage - form tree,form {'search_default_group_stage_type': 1} diff --git a/fieldservice/views/fsm_tag.xml b/fieldservice/views/fsm_tag.xml index 33f45a4ce1..c12b97368d 100644 --- a/fieldservice/views/fsm_tag.xml +++ b/fieldservice/views/fsm_tag.xml @@ -1,4 +1,3 @@ - @@ -42,7 +41,6 @@ Tags fsm.tag - form tree,form

diff --git a/fieldservice/views/fsm_team.xml b/fieldservice/views/fsm_team.xml index 6555d40513..7c1244d32c 100644 --- a/fieldservice/views/fsm_team.xml +++ b/fieldservice/views/fsm_team.xml @@ -1,4 +1,3 @@ -