From 1a645fe14431c0d13493742f94baf892dad668e3 Mon Sep 17 00:00:00 2001 From: Carolina Fernandez Date: Tue, 7 Nov 2023 16:02:12 -0300 Subject: [PATCH] [IMP] resource_booking: Add multiples requesters in booking --- migrations/15.0.1.4.0/post-migration.py | 33 ++++++++ migrations/15.0.1.4.0/pre-migration.py | 10 +++ resource_booking/README.rst | 2 +- resource_booking/__manifest__.py | 3 +- resource_booking/i18n/es.po | 5 ++ resource_booking/i18n/resource_booking.pot | 5 ++ resource_booking/models/resource_booking.py | 40 +++++---- .../security/resource_booking_security.xml | 5 +- .../static/description/index.html | 2 +- resource_booking/templates/portal.xml | 12 ++- resource_booking/tests/test_backend.py | 81 ++++++++++--------- resource_booking/tests/test_portal.py | 10 ++- .../views/resource_booking_views.xml | 14 ++-- 13 files changed, 151 insertions(+), 71 deletions(-) create mode 100644 migrations/15.0.1.4.0/post-migration.py create mode 100644 migrations/15.0.1.4.0/pre-migration.py diff --git a/migrations/15.0.1.4.0/post-migration.py b/migrations/15.0.1.4.0/post-migration.py new file mode 100644 index 00000000..4886ea88 --- /dev/null +++ b/migrations/15.0.1.4.0/post-migration.py @@ -0,0 +1,33 @@ +# Copyright 2023 Tecnativa - Carolina Fernandez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from psycopg2.extensions import AsIs + +from odoo import SUPERUSER_ID, api + + +def migrate(cr, version): + """Put partner_id in partner_ids""" + env = api.Environment(cr, SUPERUSER_ID, {}) + m2m_table = env["resource.booking"]._fields["partner_ids"].relation + column1 = env["resource.booking"]._fields["partner_ids"].column1 + column2 = env["resource.booking"]._fields["partner_ids"].column2 + cr.execute( + "SELECT rb.id FROM resource_booking rb " + "INNER JOIN %s rel ON rel.%s = rb.migrated_partner_id"( + AsIs(m2m_table), AsIs(column2) + ) + ) + exclude_ids = [x[0] for x in cr.fetchall()] + cr.execute( + "INSERT INTO %s " + "(%s, %s) " + "VALUES " + "SELECT id, migrated_partner_id FROM %s", + "WHERE id NOT IN %s"( + AsIs(m2m_table), + AsIs(column1), + AsIs(column2), + AsIs(env["resource.booking"]._table), + tuple(exclude_ids), + ), + ) diff --git a/migrations/15.0.1.4.0/pre-migration.py b/migrations/15.0.1.4.0/pre-migration.py new file mode 100644 index 00000000..670eee43 --- /dev/null +++ b/migrations/15.0.1.4.0/pre-migration.py @@ -0,0 +1,10 @@ +# Copyright 2023 Tecnativa - Carolina Fernandez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + + +def migrate(env): + env.cr.execute( + """ + ALTER TABLE resource_booking RENAME partner_id TO migrated_partner_id + """, + ) diff --git a/resource_booking/README.rst b/resource_booking/README.rst index da1aead0..f7c3f01e 100644 --- a/resource_booking/README.rst +++ b/resource_booking/README.rst @@ -7,7 +7,7 @@ Resource booking !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:c70889d0bc2b621cd88453d5d977084348dacfa9b664cffa568fb832076ac30a + !! source digest: sha256:12c8fe57d9a76b5ff44d26cdede1405ce562f2077a532346e1cffe9997c62b2c !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png diff --git a/resource_booking/__manifest__.py b/resource_booking/__manifest__.py index dc7f1668..161bbda8 100644 --- a/resource_booking/__manifest__.py +++ b/resource_booking/__manifest__.py @@ -1,11 +1,12 @@ # Copyright 2021 Tecnativa - Jairo Llopis # Copyright 2022 Tecnativa - Pedro M. Baeza +# Copyright 2023 Tecnativa - Carolina Fernandez # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). { "name": "Resource booking", "summary": "Manage appointments and resource booking", - "version": "15.0.1.3.0", + "version": "15.0.1.4.0", "development_status": "Production/Stable", "category": "Appointments", "website": "https://github.com/OCA/calendar", diff --git a/resource_booking/i18n/es.po b/resource_booking/i18n/es.po index a6fda32d..3b9ec2ac 100644 --- a/resource_booking/i18n/es.po +++ b/resource_booking/i18n/es.po @@ -896,6 +896,11 @@ msgstr "Aleatoria: el orden no es importante" msgid "Requester" msgstr "Solicitante" +#. module: resource_booking +#: model:ir.model.fields,field_description:resource_booking.field_resource_booking__partner_ids +msgid "Requesters" +msgstr "Solicitantes" + #. module: resource_booking #: model:ir.model.fields,field_description:resource_booking.field_resource_booking__requester_advice #: model:ir.model.fields,field_description:resource_booking.field_resource_booking_type__requester_advice diff --git a/resource_booking/i18n/resource_booking.pot b/resource_booking/i18n/resource_booking.pot index 6fec9bb6..b8a3dbac 100644 --- a/resource_booking/i18n/resource_booking.pot +++ b/resource_booking/i18n/resource_booking.pot @@ -860,6 +860,11 @@ msgstr "" msgid "Requester" msgstr "" +#. module: resource_booking +#: model:ir.model.fields,field_description:resource_booking.field_resource_booking__partner_ids +msgid "Requesters" +msgstr "" + #. module: resource_booking #: model:ir.model.fields,field_description:resource_booking.field_resource_booking__requester_advice #: model:ir.model.fields,field_description:resource_booking.field_resource_booking_type__requester_advice diff --git a/resource_booking/models/resource_booking.py b/resource_booking/models/resource_booking.py index 52e35a70..90837a14 100644 --- a/resource_booking/models/resource_booking.py +++ b/resource_booking/models/resource_booking.py @@ -125,9 +125,12 @@ class ResourceBooking(models.Model): description = fields.Html() partner_id = fields.Many2one( comodel_name="res.partner", + compute="_compute_partner_id", string="Requester", - index=True, - ondelete="cascade", + ) + partner_ids = fields.Many2many( + comodel_name="res.partner", + string="Requesters", required=True, tracking=True, help="Who requested this booking?", @@ -211,6 +214,11 @@ class ResourceBooking(models.Model): tracking=True, ) + @api.depends("partner_ids") + def _compute_partner_id(self): + for one in self: + one.partner_id = one.partner_ids[:1] + @api.model def _default_user_id(self): return self.env.user @@ -260,7 +268,7 @@ def _compute_is_modifiable(self): overdue = self.filtered("is_overdue") overdue.is_modifiable = False - @api.depends("name", "partner_id", "type_id", "meeting_id") + @api.depends("name", "partner_ids", "type_id", "meeting_id") @api.depends_context("uid", "using_portal") def _compute_display_name(self): """Overridden just for dependencies; see `name_get()` for implementation.""" @@ -302,7 +310,7 @@ def _compute_state(self): continue confirmed = False for attendee in one.meeting_id.attendee_ids: - if attendee.partner_id == one.partner_id: + if attendee.partner_id in one.partner_ids: confirmed = attendee.state == "accepted" break if confirmed: @@ -362,9 +370,10 @@ def _prepare_meeting_vals(self): duration=self.duration, location=self.location, videocall_location=self.videocall_location, - name=self.name or self._get_name_formatted(self.partner_id, self.type_id), + name=self.name + or self._get_name_formatted(self.partner_ids[0], self.type_id), partner_ids=[ - (4, partner.id, 0) for partner in self.partner_id | resource_partners + (4, partner.id, 0) for partner in self.partner_ids | resource_partners ], resource_booking_ids=[(6, 0, self.ids)], start=self.start, @@ -598,7 +607,7 @@ def name_get(self): elif not record.name: # Automatic name for backend users name = self._get_name_formatted( - record.partner_id, record.type_id, record.meeting_id + record.partner_ids[0], record.type_id, record.meeting_id ) new.append((id_, name)) return new @@ -632,11 +641,12 @@ def _message_get_suggested_recipients(self): """Suggest related partners.""" recipients = super()._message_get_suggested_recipients() for record in self: - record._message_add_suggested_recipient( - recipients, - partner=record.partner_id, - reason=self._fields["partner_id"].string, - ) + for partner in record.partner_ids: + record._message_add_suggested_recipient( + recipients, + partner=partner, + reason=self._fields["partner_ids"].string, + ) return recipients def action_schedule(self): @@ -673,12 +683,12 @@ def action_confirm(self): for booking in self: if not booking.meeting_id: continue - # Make sure requester and user resources are meeting attendees - booking.meeting_id.partner_ids |= booking.partner_id | booking.mapped( + # Make sure requesters and user resources are meeting attendees + booking.meeting_id.partner_ids |= booking.partner_ids | booking.mapped( "combination_id.resource_ids.user_id.partner_id" ) # Find meeting attendees that should be confirmed - partners_to_confirm = confirm_always | booking.partner_id + partners_to_confirm = confirm_always | booking.partner_ids for attendee in booking.meeting_id.attendee_ids: if attendee.partner_id & partners_to_confirm: # attendee.state='accepted' diff --git a/resource_booking/security/resource_booking_security.xml b/resource_booking/security/resource_booking_security.xml index e30cd8f1..761db05d 100644 --- a/resource_booking/security/resource_booking_security.xml +++ b/resource_booking/security/resource_booking_security.xml @@ -1,5 +1,6 @@ @@ -47,7 +48,7 @@ ['|', ('partner_id', 'child_of', user.partner_id.ids), ('message_partner_ids', 'child_of', user.partner_id.ids)] + >['|', ('partner_ids', 'child_of', user.partner_id.ids), ('message_partner_ids', 'child_of', user.partner_id.ids)] Resource booking user rule @@ -55,7 +56,7 @@ ['|', '|', ('partner_id', 'child_of', user.partner_id.ids), ('message_partner_ids', 'child_of', user.partner_id.ids), ('combination_id.resource_ids.user_id', 'in', user.ids)] + >['|', '|', ('partner_ids', 'child_of', user.partner_id.ids), ('message_partner_ids', 'child_of', user.partner_id.ids), ('combination_id.resource_ids.user_id', 'in', user.ids)] Resource booking manager rule diff --git a/resource_booking/static/description/index.html b/resource_booking/static/description/index.html index d463c963..76fef8a8 100644 --- a/resource_booking/static/description/index.html +++ b/resource_booking/static/description/index.html @@ -367,7 +367,7 @@

Resource booking

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:c70889d0bc2b621cd88453d5d977084348dacfa9b664cffa568fb832076ac30a +!! source digest: sha256:12c8fe57d9a76b5ff44d26cdede1405ce562f2077a532346e1cffe9997c62b2c !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Production/Stable License: AGPL-3 OCA/calendar Translate me on Weblate Try me on Runboat

This module adds a new app to allow you to book resource combinations in given diff --git a/resource_booking/templates/portal.xml b/resource_booking/templates/portal.xml index 648cbb1b..fc5165f5 100644 --- a/resource_booking/templates/portal.xml +++ b/resource_booking/templates/portal.xml @@ -1,5 +1,6 @@