Skip to content

Commit

Permalink
[IMP] resource_booking: Add multiples requesters in booking
Browse files Browse the repository at this point in the history
  • Loading branch information
carolinafernandez-tecnativa committed Nov 9, 2023
1 parent 8d6f440 commit 1a645fe
Show file tree
Hide file tree
Showing 13 changed files with 151 additions and 71 deletions.
33 changes: 33 additions & 0 deletions migrations/15.0.1.4.0/post-migration.py
Original file line number Diff line number Diff line change
@@ -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),
),
)
10 changes: 10 additions & 0 deletions migrations/15.0.1.4.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -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
""",
)
2 changes: 1 addition & 1 deletion resource_booking/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion resource_booking/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
5 changes: 5 additions & 0 deletions resource_booking/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions resource_booking/i18n/resource_booking.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 25 additions & 15 deletions resource_booking/models/resource_booking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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?",
Expand Down Expand Up @@ -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]

Check warning on line 220 in resource_booking/models/resource_booking.py

View check run for this annotation

Codecov / codecov/patch

resource_booking/models/resource_booking.py#L220

Added line #L220 was not covered by tests

@api.model
def _default_user_id(self):
return self.env.user
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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'
Expand Down
5 changes: 3 additions & 2 deletions resource_booking/security/resource_booking_security.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2021 Tecnativa - Jairo Llopis
Copyright 2023 Tecnativa - Carolina Fernandez
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<data>
<record id="category_resource_booking" model="ir.module.category">
Expand Down Expand Up @@ -47,15 +48,15 @@
<field name="groups" eval="[(4, ref('base.group_portal'))]" />
<field
name="domain_force"
>['|', ('partner_id', 'child_of', user.partner_id.ids), ('message_partner_ids', 'child_of', user.partner_id.ids)]</field>
>['|', ('partner_ids', 'child_of', user.partner_id.ids), ('message_partner_ids', 'child_of', user.partner_id.ids)]</field>
</record>
<record id="rule_resource_booking_user" model="ir.rule">
<field name="name">Resource booking user rule</field>
<field name="model_id" ref="model_resource_booking" />
<field name="groups" eval="[(4, ref('group_user'))]" />
<field
name="domain_force"
>['|', '|', ('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)]</field>
>['|', '|', ('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)]</field>
</record>
<record id="rule_resource_booking_manager" model="ir.rule">
<field name="name">Resource booking manager rule</field>
Expand Down
2 changes: 1 addition & 1 deletion resource_booking/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Resource booking</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:c70889d0bc2b621cd88453d5d977084348dacfa9b664cffa568fb832076ac30a
!! source digest: sha256:12c8fe57d9a76b5ff44d26cdede1405ce562f2077a532346e1cffe9997c62b2c
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/calendar/tree/15.0/resource_booking"><img alt="OCA/calendar" src="https://img.shields.io/badge/github-OCA%2Fcalendar-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/calendar-15-0/calendar-15-0-resource_booking"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/calendar&amp;target_branch=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module adds a new app to allow you to book resource combinations in given
Expand Down
12 changes: 11 additions & 1 deletion resource_booking/templates/portal.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2021 Tecnativa - Jairo Llopis
Copyright 2023 Tecnativa - Carolina Fernandez
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<data>
<!--
Expand Down Expand Up @@ -348,7 +349,16 @@
</div>
<div class="mb-1">
<strong>Requested by:</strong>
<span t-field="booking_sudo.partner_id.display_name" />
<ul>
<t
t-foreach="booking_sudo.partner_ids"
t-as="partner"
>
<li>
<span t-field="partner.display_name" />
</li>
</t>
</ul>
</div>
<div class="mb-1">
<strong>Booked resources:</strong>
Expand Down
Loading

0 comments on commit 1a645fe

Please sign in to comment.