Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP+FIX] resource_booking: duration, location, involves me, hr_holidays_public #34

Merged
merged 5 commits into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion resource_booking/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "Resource booking",
"summary": "Manage appointments and resource booking",
"version": "13.0.1.0.0",
"version": "13.0.2.0.0",
"development_status": "Beta",
"category": "Appointments",
"website": "https://github.com/OCA/calendar",
Expand Down
2 changes: 1 addition & 1 deletion resource_booking/controllers/portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def _booking_get_page_view_values(self, booking_sudo, access_token, **kwargs):
)
def portal_my_bookings(self, page=1, **kwargs):
"""List bookings that I can access."""
Booking = request.env["resource.booking"]
Booking = request.env["resource.booking"].with_context(using_portal=True)
values = self._prepare_portal_layout_values()
pager = portal.pager(
url="/my/bookings",
Expand Down
55 changes: 55 additions & 0 deletions resource_booking/migrations/13.0.2.0.0/pre-migrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright 2021 Tecnativa - Jairo Llopis
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from openupgradelib import openupgrade


def remove_start_stop_together_constraint(cr):
"""Remove old unnecessary constraint.

This one is no longer needed because `stop` is now computed and readonly,
so it will always have or not have value automatically.
"""
openupgrade.logged_query(
cr,
"""
ALTER TABLE resource_booking
DROP CONSTRAINT IF EXISTS resource_booking_start_stop_together
""",
)


def fill_resource_booking_duration(env):
"""Pre-create and pre-fill resource.booking duration."""
openupgrade.add_fields(
env,
[
(
"duration",
"resource.booking",
"resource_booking",
"float",
None,
"resource_booking",
None,
)
],
)
openupgrade.logged_query(
env.cr,
"""
UPDATE resource_booking rb
SET duration = COALESCE(
-- See https://stackoverflow.com/a/952600/1468388
EXTRACT(EPOCH FROM rb.stop - rb.start) / 3600,
rbt.duration
)
FROM resource_booking_type rbt
WHERE rb.type_id = rbt.id
""",
)


@openupgrade.migrate()
def migrate(env, version):
remove_start_stop_together_constraint(env.cr)
fill_resource_booking_duration(env)
Loading