Skip to content

Commit

Permalink
[IMP] resource_booking: add freezegun as a python external dependency
Browse files Browse the repository at this point in the history
[IMP] resource_booking: fix failling BackendCase. test_booking_from_calendar_view

[IMP] resource_booking: fix typo in help parameter for combination_assignment field from resource_booking_type

[IMP] resource_booking: fix failing PortalCase.test_portal_no_bookings

Test was failling cause there was no bookings link on portal home for external users, then no trigger.
Also I had to tweak eslintrc config cause precommit was failling due to ECMA version.

[IMP] resource_booking: No create/unlink call if nothing to do

[FIX] resource_booking: error CalendarQuickCreate title is not a string when scheduling a booking

[FIX] resource_booking: portal responsive booking calendar table going wider and no x scroll
  • Loading branch information
rrebollo authored and victoralmau committed Mar 12, 2024
1 parent b31f313 commit 3a89b2a
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 110 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ env:

# See https://github.com/OCA/odoo-community.org/issues/37#issuecomment-470686449
parserOptions:
ecmaVersion: 2019
ecmaVersion: 11
sourceType: module

overrides:
- files:
Expand Down
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:69da76a920e2d581cfc27db05479e5705f196298cbbe67e881c92bf1ea6363af
!! source digest: sha256:1a00b2b5ad7b830fbe275ea34e4efe05037f94243149329f9a6b5fdbb6b02749
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
Expand Down
9 changes: 7 additions & 2 deletions resource_booking/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,13 @@
"views/menus.xml",
],
"assets": {
"web.assets_frontend": ["resource_booking/static/src/scss/portal.scss"],
"web.assets_tests": ["resource_booking/static/src/js/resource_booking_tour.js"],
"web.assets_frontend": [
"resource_booking/static/src/js/booking_portal.js",
"resource_booking/static/src/scss/portal.scss",
],
"web.assets_tests": [
"resource_booking/static/src/js/tours/resource_booking_tour.js"
],
},
"demo": ["demo/res_users_demo.xml"],
}
2 changes: 1 addition & 1 deletion resource_booking/models/resource_booking.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ def action_schedule(self):
self.duration, False
),
default_resource_booking_ids=[(6, 0, self.ids)],
default_name=self.name,
default_name=self.name or "",
),
"name": _("Schedule booking"),
"res_model": "calendar.event",
Expand Down
2 changes: 1 addition & 1 deletion resource_booking/models/resource_booking_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ResourceBookingType(models.Model):
default="random",
help=(
"Choose how to auto-assign resource combinations. "
"It has no effect if assiged manually."
"It has no effect if assigned manually."
),
)
combination_rel_ids = fields.One2many(
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:69da76a920e2d581cfc27db05479e5705f196298cbbe67e881c92bf1ea6363af
!! source digest: sha256:1a00b2b5ad7b830fbe275ea34e4efe05037f94243149329f9a6b5fdbb6b02749
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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/16.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-16-0/calendar-16-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=16.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
13 changes: 13 additions & 0 deletions resource_booking/static/src/js/booking_portal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/** @odoo-module */

import publicWidget from "web.public.widget";
import "portal.portal"; // Force dependencies

publicWidget.registry.PortalHomeCounters.include({
/**
* @override
*/
_getCountersAlwaysDisplayed() {
return this._super(...arguments).concat(["booking_count"]);
},
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
odoo.define("resource_booking.tour", function (require) {
"use strict";

var tour = require("web_tour.tour");

tour.register(
Expand Down
209 changes: 110 additions & 99 deletions resource_booking/templates/portal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,110 +33,117 @@
</a>
</div>
<!-- Monthly calendar -->
<table class="table table-responsive-md text-center">
<thead t-if="booking.requester_advice">
<tr>
<td colspan="7">
<div t-field="booking.requester_advice" />
</td>
</tr>
</thead>
<thead class="thead-dark">
<tr>
<th class="text-left">
<a
t-if="start > now"
t-att-href="booking.get_portal_url(suffix='/schedule/%d/%d' % (start_previous.year, start_previous.month))"
class="btn btn-secondary"
title="Previous month"
>
<i class="fa fa-chevron-left" />
</a>
</th>
<th
class="align-middle"
colspan="5"
t-out="start.strftime('%B %Y')"
/>
<th class="text-right">
<a
t-att-href="booking.get_portal_url(suffix='/schedule/%d/%d' % (start_next.year, start_next.month))"
class="btn btn-secondary"
title="Next month"
>
<i class="fa fa-chevron-right" />
</a>
</th>
</tr>
</thead>
<thead>
<tr>
<t t-foreach="calendar.iterweekdays()" t-as="weekday">
<div class="table-responsive-md">
<table class="table text-center">
<thead t-if="booking.requester_advice">
<tr>
<td colspan="7">
<div t-field="booking.requester_advice" />
</td>
</tr>
</thead>
<thead class="thead-dark">
<tr>
<th class="text-left">
<a
t-if="start > now"
t-att-href="booking.get_portal_url(suffix='/schedule/%d/%d' % (start_previous.year, start_previous.month))"
class="btn btn-secondary"
title="Previous month"
>
<i class="fa fa-chevron-left" />
</a>
</th>
<th
t-att-title="weekday_names[str(weekday + 1)]"
t-out="weekday_names[str(weekday + 1)][:3]"
class="align-middle"
colspan="5"
t-out="start.strftime('%B %Y')"
/>
</t>
</tr>
</thead>
<tbody>
<t
t-foreach="calendar.monthdatescalendar(start.year, start.month)"
t-as="week"
>
<tr>
<t t-foreach="week" t-as="day">
<td
t-att-class="day.month != start.month and 'text-muted'"
<th class="text-right">
<a
t-att-href="booking.get_portal_url(suffix='/schedule/%d/%d' % (start_next.year, start_next.month))"
class="btn btn-secondary"
title="Next month"
>
<t
t-if="day.month == start.month and slots.get(day)"
<i class="fa fa-chevron-right" />
</a>
</th>
</tr>
</thead>
<thead>
<tr>
<t t-foreach="calendar.iterweekdays()" t-as="weekday">
<th
t-att-title="weekday_names[str(weekday + 1)]"
t-out="weekday_names[str(weekday + 1)][:3]"
/>
</t>
</tr>
</thead>
<tbody>
<t
t-foreach="calendar.monthdatescalendar(start.year, start.month)"
t-as="week"
>
<tr>
<t t-foreach="week" t-as="day">
<td
t-att-class="day.month != start.month and 'text-muted'"
>
<!-- Day dropdown -->
<div class="dropdown">
<button
class="btn btn-primary dropdown-toggle"
type="button"
data-bs-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false"
t-out="day.day"
t-attf-id="dropdown-trigger-#{day.isoformat()}"
/>
<div
class="dropdown-menu slots-dropdown"
t-attf-aria-labelledby="dropdown-trigger-#{day.isoformat()}"
>
<t t-foreach="slots[day]" t-as="slot">
<!-- Hour item to open confirmation -->
<button
class="dropdown-item"
type="button"
data-bs-toggle="modal"
t-attf-data-bs-target="#modal-confirm-#{int(slot.timestamp())}"
t-out="slot.strftime(time_format)"
/>
</t>
<t
t-if="day.month == start.month and slots.get(day)"
>
<!-- Day dropdown -->
<div class="dropdown">
<button
class="btn btn-primary dropdown-toggle"
type="button"
data-bs-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false"
t-out="day.day"
t-attf-id="dropdown-trigger-#{day.isoformat()}"
/>
<div
class="dropdown-menu slots-dropdown"
t-attf-aria-labelledby="dropdown-trigger-#{day.isoformat()}"
>
<t
t-foreach="slots[day]"
t-as="slot"
>
<!-- Hour item to open confirmation -->
<button
class="dropdown-item"
type="button"
data-bs-toggle="modal"
t-attf-data-bs-target="#modal-confirm-#{int(slot.timestamp())}"
t-out="slot.strftime(time_format)"
/>
</t>
</div>
</div>
</div>
</t>
<t t-else="">
<t t-out="day.day" />
</t>
</td>
</t>
</t>
<t t-else="">
<t t-out="day.day" />
</t>
</td>
</t>
</tr>
</t>
</tbody>
<tfoot>
<tr>
<td
colspan="7"
> All times are displayed using this timezone: <strong
t-field="booking.type_id.resource_calendar_id.tz"
/>
</td>
</tr>
</t>
</tbody>
<tfoot>
<tr>
<td colspan="7">
All times are displayed using this timezone:
<strong t-field="booking.type_id.resource_calendar_id.tz" />
</td>
</tr>
</tfoot>
</table>
</tfoot>
</table>
</div>
<!-- Hour confirmation modals -->
<t
t-foreach="calendar.monthdatescalendar(start.year, start.month)"
Expand Down Expand Up @@ -249,7 +256,11 @@
</t>
</xpath>
</template>
<template id="portal_my_home" inherit_id="portal.portal_my_home">
<template
id="portal_my_home"
inherit_id="portal.portal_my_home"
customize_show="True"
>
<xpath expr="//div[hasclass('o_portal_docs')]" position="inside">
<t t-call="portal.portal_docs_entry">
<t t-set="title">Bookings</t>
Expand Down
4 changes: 2 additions & 2 deletions resource_booking/tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,9 @@ def test_booking_from_calendar_view(self):
self.assertEqual(self.rbt.duration, 0.5)
# Change it to 45 minutes
self.rbt.duration = 0.75
# Bookings smart button configures calendar with slots of 45 minutes
# Bookings smart button configures calendar with slots from slot duration field
button_context = self.rbt.action_open_bookings()["context"]
self.assertEqual(button_context["calendar_slot_duration"], "00:45")
self.assertEqual(button_context["calendar_slot_duration"], "00:30:00")
self.assertEqual(button_context["default_duration"], 0.75)
# When you click & drag on calendar to create an event, it adds the
# start and duration as default; we imitate that here to book a meeting
Expand Down
1 change: 1 addition & 0 deletions test_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
freezegun

0 comments on commit 3a89b2a

Please sign in to comment.