diff --git a/fieldservice_calendar/README.rst b/fieldservice_calendar/README.rst new file mode 100644 index 0000000000..90be7cefc4 --- /dev/null +++ b/fieldservice_calendar/README.rst @@ -0,0 +1,95 @@ +======================== +Field Service - Calendar +======================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:7a34f3ab21df98dc13e662f2a4d3e481c7be3a21cc9a4a34ee589c9f3de01ee6 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :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/17.0/fieldservice_calendar + :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-17-0/field-service-17-0-fieldservice_calendar + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/field-service&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This modules creates calendar event from FSM Orders. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +A "calendar" user should be set on FSM Team. Events will be added to his +calendar. Then the FSM Order' person_id (worker) will be an attendee of +the calendar's event (Meeting). + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Akretion + +Contributors +------------ + +- Raphaël Reverdy +- Freni Patel +- `APSL `__: + + - Antoni Marroig + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +.. |maintainer-hparfr| image:: https://github.com/hparfr.png?size=40px + :target: https://github.com/hparfr + :alt: hparfr + +Current `maintainer `__: + +|maintainer-hparfr| + +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_calendar/__init__.py b/fieldservice_calendar/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/fieldservice_calendar/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/fieldservice_calendar/__manifest__.py b/fieldservice_calendar/__manifest__.py new file mode 100644 index 0000000000..16518713c1 --- /dev/null +++ b/fieldservice_calendar/__manifest__.py @@ -0,0 +1,24 @@ +# Copyright (C) 2021 Raphaël Reverdy +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "Field Service - Calendar", + "summary": "Add calendar to FSM Orders", + "author": "Akretion, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/field-service", + "category": "Field Service", + "license": "AGPL-3", + "version": "18.0.1.0.0", + "depends": [ + "calendar", + "fieldservice", + ], + "data": [ + "views/fsm_order.xml", + "views/fsm_team.xml", + ], + "installable": True, + "development_status": "Beta", + "maintainers": [ + "hparfr", + ], +} diff --git a/fieldservice_calendar/i18n/de.po b/fieldservice_calendar/i18n/de.po new file mode 100644 index 0000000000..ced5a77768 --- /dev/null +++ b/fieldservice_calendar/i18n/de.po @@ -0,0 +1,52 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * fieldservice_calendar +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-04-14 10:37+0000\n" +"Last-Translator: André Volksdorf \n" +"Language-Team: none\n" +"Language: de\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: fieldservice_calendar +#: model:ir.model,name:fieldservice_calendar.model_calendar_event +msgid "Calendar Event" +msgstr "Kalenderereignis" + +#. module: fieldservice_calendar +#: model:ir.model,name:fieldservice_calendar.model_fsm_order +msgid "Field Service Order" +msgstr "Field-Service Auftrag" + +#. module: fieldservice_calendar +#: model:ir.model,name:fieldservice_calendar.model_fsm_team +msgid "Field Service Team" +msgstr "Field-Service Team" + +#. module: fieldservice_calendar +#: model:ir.model.fields,field_description:fieldservice_calendar.field_fsm_order__calendar_event_id +msgid "Meeting" +msgstr "Meeting" + +#. module: fieldservice_calendar +#: model:ir.model.fields,field_description:fieldservice_calendar.field_calendar_event__fsm_order_id +msgid "Order id" +msgstr "Auftrags-Id" + +#. module: fieldservice_calendar +#: model:ir.model.fields,help:fieldservice_calendar.field_fsm_team__calendar_user_id +msgid "Responsible for orders's calendar" +msgstr "Zuständig für Auftragskalender" + +#. module: fieldservice_calendar +#: model:ir.model.fields,field_description:fieldservice_calendar.field_fsm_team__calendar_user_id +msgid "Team's calendar" +msgstr "Team-Kalender" diff --git a/fieldservice_calendar/i18n/es.po b/fieldservice_calendar/i18n/es.po new file mode 100644 index 0000000000..cb3f6ad9e2 --- /dev/null +++ b/fieldservice_calendar/i18n/es.po @@ -0,0 +1,52 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * fieldservice_calendar +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-07-22 21:08+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: none\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: fieldservice_calendar +#: model:ir.model,name:fieldservice_calendar.model_calendar_event +msgid "Calendar Event" +msgstr "Calendario de eventos" + +#. module: fieldservice_calendar +#: model:ir.model,name:fieldservice_calendar.model_fsm_order +msgid "Field Service Order" +msgstr "Orden de Servicio de Campo" + +#. module: fieldservice_calendar +#: model:ir.model,name:fieldservice_calendar.model_fsm_team +msgid "Field Service Team" +msgstr "Equipo de Servicio de Campo" + +#. module: fieldservice_calendar +#: model:ir.model.fields,field_description:fieldservice_calendar.field_fsm_order__calendar_event_id +msgid "Meeting" +msgstr "Reunión" + +#. module: fieldservice_calendar +#: model:ir.model.fields,field_description:fieldservice_calendar.field_calendar_event__fsm_order_id +msgid "Order id" +msgstr "Id de pedido" + +#. module: fieldservice_calendar +#: model:ir.model.fields,help:fieldservice_calendar.field_fsm_team__calendar_user_id +msgid "Responsible for orders's calendar" +msgstr "Responsable del calendario de pedidos" + +#. module: fieldservice_calendar +#: model:ir.model.fields,field_description:fieldservice_calendar.field_fsm_team__calendar_user_id +msgid "Team's calendar" +msgstr "Calendario del equipo" diff --git a/fieldservice_calendar/i18n/es_AR.po b/fieldservice_calendar/i18n/es_AR.po new file mode 100644 index 0000000000..71a65d3826 --- /dev/null +++ b/fieldservice_calendar/i18n/es_AR.po @@ -0,0 +1,64 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * fieldservice_calendar +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2021-10-03 21:34+0000\n" +"Last-Translator: Ignacio Buioli \n" +"Language-Team: none\n" +"Language: es_AR\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.3.2\n" + +#. module: fieldservice_calendar +#: model:ir.model,name:fieldservice_calendar.model_calendar_event +msgid "Calendar Event" +msgstr "Evento de Calendario" + +#. module: fieldservice_calendar +#: model:ir.model,name:fieldservice_calendar.model_fsm_order +msgid "Field Service Order" +msgstr "Pedido de Servicio de Campo" + +#. module: fieldservice_calendar +#: model:ir.model,name:fieldservice_calendar.model_fsm_team +msgid "Field Service Team" +msgstr "Equipo de Servicio de Campo" + +#. module: fieldservice_calendar +#: model:ir.model.fields,field_description:fieldservice_calendar.field_fsm_order__calendar_event_id +msgid "Meeting" +msgstr "Reunión" + +#. module: fieldservice_calendar +#: model:ir.model.fields,field_description:fieldservice_calendar.field_calendar_event__fsm_order_id +msgid "Order id" +msgstr "ID del Pedido" + +#. module: fieldservice_calendar +#: model:ir.model.fields,help:fieldservice_calendar.field_fsm_team__calendar_user_id +msgid "Responsible for orders's calendar" +msgstr "Responsable del calendario de pedidos" + +#. module: fieldservice_calendar +#: model:ir.model.fields,field_description:fieldservice_calendar.field_fsm_team__calendar_user_id +msgid "Team's calendar" +msgstr "Equipo del calendario" + +#~ msgid "Display Name" +#~ msgstr "Mostrar Nombre" + +#~ msgid "ID" +#~ msgstr "ID" + +#~ msgid "Last Modified on" +#~ msgstr "Última Modificación el" + +#~ msgid "Order" +#~ msgstr "Pedido" diff --git a/fieldservice_calendar/i18n/fieldservice_calendar.pot b/fieldservice_calendar/i18n/fieldservice_calendar.pot new file mode 100644 index 0000000000..7b464818ba --- /dev/null +++ b/fieldservice_calendar/i18n/fieldservice_calendar.pot @@ -0,0 +1,49 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * fieldservice_calendar +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: fieldservice_calendar +#: model:ir.model,name:fieldservice_calendar.model_calendar_event +msgid "Calendar Event" +msgstr "" + +#. module: fieldservice_calendar +#: model:ir.model,name:fieldservice_calendar.model_fsm_order +msgid "Field Service Order" +msgstr "" + +#. module: fieldservice_calendar +#: model:ir.model,name:fieldservice_calendar.model_fsm_team +msgid "Field Service Team" +msgstr "" + +#. module: fieldservice_calendar +#: model:ir.model.fields,field_description:fieldservice_calendar.field_fsm_order__calendar_event_id +msgid "Meeting" +msgstr "" + +#. module: fieldservice_calendar +#: model:ir.model.fields,field_description:fieldservice_calendar.field_calendar_event__fsm_order_id +msgid "Order id" +msgstr "" + +#. module: fieldservice_calendar +#: model:ir.model.fields,help:fieldservice_calendar.field_fsm_team__calendar_user_id +msgid "Responsible for orders's calendar" +msgstr "" + +#. module: fieldservice_calendar +#: model:ir.model.fields,field_description:fieldservice_calendar.field_fsm_team__calendar_user_id +msgid "Team's calendar" +msgstr "" diff --git a/fieldservice_calendar/i18n/it.po b/fieldservice_calendar/i18n/it.po new file mode 100644 index 0000000000..0312a86393 --- /dev/null +++ b/fieldservice_calendar/i18n/it.po @@ -0,0 +1,52 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * fieldservice_calendar +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2022-10-27 13:43+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.14.1\n" + +#. module: fieldservice_calendar +#: model:ir.model,name:fieldservice_calendar.model_calendar_event +msgid "Calendar Event" +msgstr "Evento calendario" + +#. module: fieldservice_calendar +#: model:ir.model,name:fieldservice_calendar.model_fsm_order +msgid "Field Service Order" +msgstr "Ordine assistenza sul campo" + +#. module: fieldservice_calendar +#: model:ir.model,name:fieldservice_calendar.model_fsm_team +msgid "Field Service Team" +msgstr "Squadra assistenza sul campo" + +#. module: fieldservice_calendar +#: model:ir.model.fields,field_description:fieldservice_calendar.field_fsm_order__calendar_event_id +msgid "Meeting" +msgstr "Riunione" + +#. module: fieldservice_calendar +#: model:ir.model.fields,field_description:fieldservice_calendar.field_calendar_event__fsm_order_id +msgid "Order id" +msgstr "ID ordine" + +#. module: fieldservice_calendar +#: model:ir.model.fields,help:fieldservice_calendar.field_fsm_team__calendar_user_id +msgid "Responsible for orders's calendar" +msgstr "Responsabile calendario ordini" + +#. module: fieldservice_calendar +#: model:ir.model.fields,field_description:fieldservice_calendar.field_fsm_team__calendar_user_id +msgid "Team's calendar" +msgstr "Calendario squadra" diff --git a/fieldservice_calendar/i18n/pt_BR.po b/fieldservice_calendar/i18n/pt_BR.po new file mode 100644 index 0000000000..dab025675b --- /dev/null +++ b/fieldservice_calendar/i18n/pt_BR.po @@ -0,0 +1,64 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * fieldservice_calendar +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2021-12-08 22:39+0000\n" +"Last-Translator: marcos-mendez \n" +"Language-Team: none\n" +"Language: pt_BR\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n > 1;\n" +"X-Generator: Weblate 4.3.2\n" + +#. module: fieldservice_calendar +#: model:ir.model,name:fieldservice_calendar.model_calendar_event +msgid "Calendar Event" +msgstr "Calendário de Eventos" + +#. module: fieldservice_calendar +#: model:ir.model,name:fieldservice_calendar.model_fsm_order +msgid "Field Service Order" +msgstr "Ordem de serviço de campo" + +#. module: fieldservice_calendar +#: model:ir.model,name:fieldservice_calendar.model_fsm_team +msgid "Field Service Team" +msgstr "Equipe de Serviço de Campo" + +#. module: fieldservice_calendar +#: model:ir.model.fields,field_description:fieldservice_calendar.field_fsm_order__calendar_event_id +msgid "Meeting" +msgstr "Reunião" + +#. module: fieldservice_calendar +#: model:ir.model.fields,field_description:fieldservice_calendar.field_calendar_event__fsm_order_id +msgid "Order id" +msgstr "Id Pedido" + +#. module: fieldservice_calendar +#: model:ir.model.fields,help:fieldservice_calendar.field_fsm_team__calendar_user_id +msgid "Responsible for orders's calendar" +msgstr "Responsável pelo calendário de pedidos" + +#. module: fieldservice_calendar +#: model:ir.model.fields,field_description:fieldservice_calendar.field_fsm_team__calendar_user_id +msgid "Team's calendar" +msgstr "Calendário da equipe" + +#~ msgid "Display Name" +#~ msgstr "Nome exibido" + +#~ msgid "ID" +#~ msgstr "ID" + +#~ msgid "Last Modified on" +#~ msgstr "Última modificação em" + +#~ msgid "Order" +#~ msgstr "Pedido" diff --git a/fieldservice_calendar/models/__init__.py b/fieldservice_calendar/models/__init__.py new file mode 100644 index 0000000000..8ba83cde4d --- /dev/null +++ b/fieldservice_calendar/models/__init__.py @@ -0,0 +1,3 @@ +from . import calendar +from . import fsm_order +from . import fsm_team diff --git a/fieldservice_calendar/models/calendar.py b/fieldservice_calendar/models/calendar.py new file mode 100644 index 0000000000..ec7d2866d9 --- /dev/null +++ b/fieldservice_calendar/models/calendar.py @@ -0,0 +1,52 @@ +# Copyright (C) 2021 Raphaël Reverdy +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class Meeting(models.Model): + _inherit = "calendar.event" + + fsm_order_id = fields.One2many( + string="Order id", + comodel_name="fsm.order", + inverse_name="calendar_event_id", + ) + + def _update_fsm_order_date(self): + self.ensure_one() + if self._context.get("recurse_order_calendar"): + # avoid recursion + return + to_apply = {} + to_apply["scheduled_date_start"] = self.start + to_apply["scheduled_duration"] = self.duration + self.fsm_order_id.with_context(recurse_order_calendar=True).write(to_apply) + + def _update_fsm_assigned(self): + # update back fsm_order when an attenndee is member of a team + self.ensure_one() + if self._context.get("recurse_order_calendar"): + # avoid recursion + return + person_id = None + for partner in self.partner_ids: + if partner.fsm_person: + person_id = ( + self.env["fsm.person"] + .search([["partner_id", "=", partner.id]], limit=1) + .id + ) + break + self.fsm_order_id.with_context(recurse_order_calendar=True).write( + {"person_id": person_id} + ) + + def write(self, values): + res = super().write(values) + if self.fsm_order_id: + if "start" in values or "duration" in values: + self._update_fsm_order_date() + if "partner_ids" in values: + self._update_fsm_assigned() + return res diff --git a/fieldservice_calendar/models/fsm_order.py b/fieldservice_calendar/models/fsm_order.py new file mode 100644 index 0000000000..d374099a78 --- /dev/null +++ b/fieldservice_calendar/models/fsm_order.py @@ -0,0 +1,117 @@ +# Copyright (C) 2021 Raphaël Reverdy +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class FSMOrder(models.Model): + _inherit = "fsm.order" + + calendar_event_id = fields.Many2one( + "calendar.event", + string="Meeting", + readonly=True, + ) + + @api.model_create_multi + def create(self, vals_list): + res = super().create(vals_list) + res._create_calendar_event() + return res + + def _create_calendar_event(self): + """Create entry in calendar of the team.""" + for order in self._should_have_calendar_event(): + order.calendar_event_id = ( + self.env["calendar.event"] + .with_context(no_mail_to_attendees=True) + .create(order._prepare_calendar_event()) + ) + + def _should_have_calendar_event(self): + return self.filtered("team_id.calendar_user_id").filtered( + "scheduled_date_start" + ) + + def _prepare_calendar_event(self): + model_id = self.env.ref("fieldservice.model_fsm_order").id + vals = { + "name": self.name, + "description": self.description, + "start": self.scheduled_date_start, + "stop": self.scheduled_date_end, + "allday": False, + "res_model_id": model_id, # link back with "Document" button + "res_id": self.id, # link back with "Document" button + "location": self._serialize_location(), + "user_id": self.team_id.calendar_user_id.id, + } + partners = self.team_id.calendar_user_id.partner_id | self.person_id.partner_id + vals["partner_ids"] = [(6, False, partners.ids)] + # we let calendar_user has a partner_ids in order + # to have the meeting in the team's calendar + return vals + + def write(self, vals): + old_persons = {} + for rec in self: + old_persons[rec.id] = rec.person_id + res = super().write(vals) + to_update = self.create_or_delete_calendar() + with_calendar = to_update.filtered("calendar_event_id") + if "scheduled_date_start" in vals or "scheduled_date_end" in vals: + with_calendar.update_calendar_date(vals) + if "location_id" in vals: + with_calendar.update_calendar_location() + if "person_id" in vals: + with_calendar.update_calendar_person(old_persons) + return res + + def unlink(self): + self._rm_calendar_event() + return super().unlink() + + def create_or_delete_calendar(self): + to_update = self._should_have_calendar_event() + to_rm = self - to_update + to_create = to_update.filtered(lambda x: x.calendar_event_id.id is False) + to_create._create_calendar_event() + to_rm._rm_calendar_event() + return to_update + + def _rm_calendar_event(self): + # it can be archived instead if desired + self.calendar_event_id.unlink() + + def update_calendar_date(self, vals): + if self._context.get("recurse_order_calendar"): + # avoid recursion + return + to_apply = {} + to_apply["start"] = self.scheduled_date_start + to_apply["stop"] = self.scheduled_date_end + # always write start and stop in order to calc duration + self.mapped("calendar_event_id").with_context( + recurse_order_calendar=True + ).write(to_apply) + + def update_calendar_location(self): + for rec in self: + rec.calendar_event_id.location = rec._serialize_location() + + def _serialize_location(self): + partner_id = self.location_id.partner_id + return f"{partner_id.name} {partner_id._display_address()}" + + def update_calendar_person(self, old_persons): + if self._context.get("recurse_order_calendar"): + # avoid recursion + return + for rec in self: + with_ctx = rec.calendar_event_id.with_context(recurse_order_calendar=True) + if old_persons.get(rec.id): + # remove buddy + with_ctx.partner_ids = [(3, old_persons[rec.id].partner_id.id, False)] + if rec.person_id: + # add the new one + with_ctx.partner_ids = [(4, rec.person_id.partner_id.id, False)] diff --git a/fieldservice_calendar/models/fsm_team.py b/fieldservice_calendar/models/fsm_team.py new file mode 100644 index 0000000000..7099726a29 --- /dev/null +++ b/fieldservice_calendar/models/fsm_team.py @@ -0,0 +1,14 @@ +# Copyright (C) 2021 Raphaël Reverdy +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class FSMTeam(models.Model): + _inherit = "fsm.team" + + calendar_user_id = fields.Many2one( + "res.users", + string="Team's calendar", + help="Responsible for orders's calendar", + ) diff --git a/fieldservice_calendar/pyproject.toml b/fieldservice_calendar/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/fieldservice_calendar/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/fieldservice_calendar/readme/CONFIGURE.md b/fieldservice_calendar/readme/CONFIGURE.md new file mode 100644 index 0000000000..4bdec5702a --- /dev/null +++ b/fieldservice_calendar/readme/CONFIGURE.md @@ -0,0 +1,3 @@ +A "calendar" user should be set on FSM Team. Events will be added to his +calendar. Then the FSM Order' person_id (worker) will be an attendee of +the calendar's event (Meeting). diff --git a/fieldservice_calendar/readme/CONTRIBUTORS.md b/fieldservice_calendar/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..67724837d0 --- /dev/null +++ b/fieldservice_calendar/readme/CONTRIBUTORS.md @@ -0,0 +1,4 @@ +- Raphaël Reverdy \<\> +- Freni Patel \<\> +- [APSL](https://apsl.tech): + - Antoni Marroig \<\> diff --git a/fieldservice_calendar/readme/DESCRIPTION.md b/fieldservice_calendar/readme/DESCRIPTION.md new file mode 100644 index 0000000000..20114c8d1e --- /dev/null +++ b/fieldservice_calendar/readme/DESCRIPTION.md @@ -0,0 +1 @@ +This modules creates calendar event from FSM Orders. diff --git a/fieldservice_calendar/static/description/icon.png b/fieldservice_calendar/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/fieldservice_calendar/static/description/icon.png differ diff --git a/fieldservice_calendar/static/description/index.html b/fieldservice_calendar/static/description/index.html new file mode 100644 index 0000000000..f78e3223ae --- /dev/null +++ b/fieldservice_calendar/static/description/index.html @@ -0,0 +1,434 @@ + + + + + +Field Service - Calendar + + + +
+

Field Service - Calendar

+ + +

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

+

This modules creates calendar event from FSM Orders.

+

Table of contents

+ +
+

Configuration

+

A “calendar” user should be set on FSM Team. Events will be added to his +calendar. Then the FSM Order’ person_id (worker) will be an attendee of +the calendar’s event (Meeting).

+
+
+

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 to smash it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Akretion
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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

+

Current maintainer:

+

hparfr

+

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_calendar/tests/__init__.py b/fieldservice_calendar/tests/__init__.py new file mode 100644 index 0000000000..2c306eb150 --- /dev/null +++ b/fieldservice_calendar/tests/__init__.py @@ -0,0 +1 @@ +from . import test_fsm_calendar diff --git a/fieldservice_calendar/tests/test_fsm_calendar.py b/fieldservice_calendar/tests/test_fsm_calendar.py new file mode 100644 index 0000000000..40cbeef62f --- /dev/null +++ b/fieldservice_calendar/tests/test_fsm_calendar.py @@ -0,0 +1,96 @@ +# Copyright (C) 2021 Raphaël Reverdy +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields +from odoo.tests.common import TransactionCase + + +class TestFSMOrder(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.Order = cls.env["fsm.order"] + cls.test_location = cls.env.ref("fieldservice.test_location") + cls.location_1 = cls.env.ref("fieldservice.location_1") + cls.team = cls.Order._default_team_id() + cls.team.calendar_user_id = cls.env.ref("base.partner_root").id + cls.person_id = cls.env.ref("fieldservice.person_2") + cls.person_id3 = cls.env.ref("fieldservice.person_3") + + def test_fsm_order_no_duration(self): + new = self.Order.create( + { + "location_id": self.test_location.id, + # no duration = no calendar + } + ) + evt = new.calendar_event_id + self.assertFalse(evt.exists()) + + def test_fsm_order_no_calendar_user(self): + self.team.calendar_user_id = False + # no calendar user_id = no calendar event + new = self.Order.create( + { + "location_id": self.test_location.id, + "scheduled_date_start": fields.Datetime.today(), + "scheduled_duration": 2, + } + ) + evt = new.calendar_event_id + self.assertFalse(evt.exists()) + self.team.calendar_user_id = self.env.ref("base.partner_root").id + + # update order + new.write({"scheduled_duration": 3}) + new.write({"location_id": self.location_1.id}) + evt = new.calendar_event_id + self.assertTrue(evt.exists()) + evt.with_context(recurse_order_calendar=False).write({"duration": 5}) + # ensure deletion + new.scheduled_date_start = False + evt = new.calendar_event_id + self.assertFalse(evt.exists()) + + def test_fsm_order_unlink(self): + # Create an Orders + new = self.Order.create( + { + "location_id": self.test_location.id, + "scheduled_date_start": fields.Datetime.today(), + "scheduled_duration": 2, + } + ) + evt = new.calendar_event_id + self.assertTrue(evt.exists()) + + # delete the order + new.unlink() + # ensure the evt is deleted + # this test may fail if another module + # archive instead of unlink (like gcalendar) + self.assertFalse(evt.exists()) + + def test_fsm_order_ensure_attendee(self): + # Create an Orders + new = self.Order.create( + { + "location_id": self.test_location.id, + "scheduled_date_start": fields.Datetime.today(), + "scheduled_duration": 2, + } + ) + evt = new.calendar_event_id + self.assertTrue( + len(evt.partner_ids) == 1, + "There should be no other attendees" " because there is no one assigned", + ) + # organiser is attendee + new.person_id = self.person_id + evt.with_context(recurse_order_calendar=False).write({"partner_ids": []}) + self.assertTrue(self.person_id.partner_id in evt.partner_ids) + new.person_id = self.person_id3 + self.assertTrue(self.person_id3.partner_id in evt.partner_ids) + self.assertTrue( + len(evt.partner_ids) == 2, "Not workers should be removed from attendees" + ) diff --git a/fieldservice_calendar/views/fsm_order.xml b/fieldservice_calendar/views/fsm_order.xml new file mode 100644 index 0000000000..d1b628eefa --- /dev/null +++ b/fieldservice_calendar/views/fsm_order.xml @@ -0,0 +1,11 @@ + + + fsm.order + + + + + + + + diff --git a/fieldservice_calendar/views/fsm_team.xml b/fieldservice_calendar/views/fsm_team.xml new file mode 100644 index 0000000000..ac52d1beb8 --- /dev/null +++ b/fieldservice_calendar/views/fsm_team.xml @@ -0,0 +1,12 @@ + + + fsm.team.form + fsm.team + + + + + + + +