Skip to content

Commit 1c9bcce

Browse files
author
Anusha
committed
[DON'T MERGE] test-requirements.txt
1 parent 9f9cf06 commit 1c9bcce

File tree

6 files changed

+296
-237
lines changed

6 files changed

+296
-237
lines changed

test-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
odoo-addon-sale_resource_booking @ git+https://github.com/OCA/sale-workflow.git@refs/pull/3781/head#subdirectory=sale_resource_booking

website_sale_resource_booking/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
],
1919
"assets": {
2020
"web.assets_tests": [
21-
"/website_sale_resource_booking/static/tests/tours/tour.esm.js",
21+
"/website_sale_resource_booking/static/src/js/tour_checkout.esm.js",
2222
],
2323
},
2424
}

website_sale_resource_booking/controllers/main.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Copyright 2021 Tecnativa - Jairo Llopis
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3-
from datetime import datetime
3+
from datetime import timezone
44
from urllib.parse import quote_plus
55

66
from dateutil.parser import isoparse
@@ -43,11 +43,11 @@ def _booking_redirection(self, booking, index):
4343
def _check_cart(self, order_sudo):
4444
"""Redirect to scheduling bookings if still not done."""
4545
order_sudo.order_line._sync_resource_bookings()
46-
bookings = order_sudo.mapped("order_line.resource_booking_ids")
46+
bookings = order_sudo.mapped("order_line.resource_booking_ids").filtered(
47+
lambda r: r.state == "pending"
48+
)
4749
if bookings:
48-
for booking in bookings:
49-
if booking.state == "pending":
50-
return request.redirect("/shop/booking/1/schedule")
50+
return request.redirect("/shop/booking/1/schedule")
5151
return super()._check_cart(order_sudo)
5252

5353
@route(
@@ -101,28 +101,27 @@ def booking_schedule(self, index, year=None, month=None, error=None, **post):
101101
)
102102
def booking_confirm(self, index, partner_name, partner_email, when, **post):
103103
"""Pre-reserve resource booking."""
104-
try:
105-
booking_sudo = (
106-
self._get_indexed_booking(index)
107-
.sudo()
108-
.with_context(
109-
# Avoid calendar notifications now, SO is still draft
110-
dont_notify=True,
111-
no_mail_to_attendees=True,
112-
)
104+
booking_sudo = (
105+
self._get_indexed_booking(index)
106+
.sudo()
107+
.with_context(
108+
# Avoid calendar notifications now, SO is still draft
109+
dont_notify=True,
110+
no_mail_to_attendees=True,
113111
)
114-
except IndexError:
112+
)
113+
if not booking_sudo:
115114
return request.redirect("/shop/checkout")
116115
redirection = self._booking_redirection(booking_sudo, index)
117116
if redirection:
118117
return redirection
119118
when_tz_aware = isoparse(when)
120-
when_naive = datetime.utcfromtimestamp(when_tz_aware.timestamp())
119+
when_naive = when_tz_aware.astimezone(timezone.utc).replace(tzinfo=None)
121120
try:
122121
with Form(booking_sudo) as booking_form:
123122
booking_form.start = when_naive
124123
except ValidationError as error:
125-
url = f"/shop/booking/{index}/schedule?error={quote_plus(error.name)}"
124+
url = f"/shop/booking/{index}/schedule?error={quote_plus(str(error))}"
126125
return request.redirect(url)
127126
# Store partner info to autocreate and autoconfirm later
128127
product = booking_sudo.sale_order_line_id.product_id
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
/** @odoo-module */
2+
/* Copyright 2021 Tecnativa - Jairo Llopis
3+
Copyright 2025 Tecnativa - Víctor Martínez
4+
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */
5+
6+
import {registry} from "@web/core/registry";
7+
import * as tourUtils from "@website_sale/js/tours/tour_utils";
8+
9+
registry.category("web_tour.tours").add("website_sale_resource_booking", {
10+
url: "/shop",
11+
steps: () => [
12+
...tourUtils.searchProduct("test not bookable product"),
13+
{
14+
content: "select test not bookable product",
15+
trigger: '.oe_product_cart:first a:contains("test not bookable product")',
16+
run: "click",
17+
},
18+
{
19+
content: "click on add to cart",
20+
trigger: '#product_detail form[action^="/shop/cart/update"] #add_to_cart',
21+
run: "click",
22+
},
23+
...tourUtils.searchProduct("test bookable product"),
24+
{
25+
trigger: 'form input[name="search"]',
26+
run: "edit test bookable product",
27+
},
28+
{
29+
trigger: 'form:has(input[name="search"]) .oe_search_button',
30+
},
31+
{
32+
content: "select test bookable product",
33+
trigger: '.oe_product_cart:first a:contains("test bookable product")',
34+
run: "click",
35+
},
36+
{
37+
content: "change quantity",
38+
trigger:
39+
'#product_detail form[action^="/shop/cart/update"] input[name=add_qty]',
40+
run: "edit 3",
41+
},
42+
{
43+
content: "click on add to cart",
44+
trigger: '#product_detail form[action^="/shop/cart/update"] #add_to_cart',
45+
run: "click",
46+
},
47+
48+
tourUtils.goToCart({quantity: 4}),
49+
{
50+
// Go to next step
51+
trigger: "a[name='website_sale_main_button']:contains('Schedule bookings')",
52+
run: "click",
53+
},
54+
{
55+
content: "Calendar is loaded",
56+
trigger: ".o_booking_calendar",
57+
},
58+
{
59+
content: "Validate calendar title is shown",
60+
trigger: "h3:contains('Pre-schedule your booking')",
61+
},
62+
{
63+
content: "Try next month if no slots",
64+
trigger: ".alert-danger a:contains('Try next month')",
65+
run: "click",
66+
},
67+
{
68+
content: "Open March 1 calendar dropdown",
69+
trigger: "#dropdown-trigger-2021-03-01",
70+
run: "click",
71+
},
72+
{
73+
trigger:
74+
".dropdown:has(#dropdown-trigger-2021-03-01) .dropdown-menu button:contains('09:00')",
75+
run: "click",
76+
},
77+
{
78+
trigger:
79+
'.modal.show input[name="partner_name"], .modal input[name="partner_name"]',
80+
run: "edit Mr. A",
81+
},
82+
{
83+
trigger:
84+
'.modal.show input[name="partner_email"], .modal input[name="partner_email"], .modal input[name="email"]',
85+
run: "edit mr.a@example.com",
86+
},
87+
{
88+
trigger: ".modal-dialog .btn:contains('Confirm booking')",
89+
run: "click",
90+
},
91+
// Booking 2 of 3 (almost same as above)
92+
{
93+
content: "Try next month if no slots",
94+
trigger: ".alert-danger a:contains('Try next month')",
95+
run: "click",
96+
},
97+
{
98+
content: "Open March 1 calendar dropdown",
99+
trigger: "#dropdown-trigger-2021-03-01",
100+
run: "click",
101+
},
102+
103+
{
104+
trigger:
105+
".dropdown:has(#dropdown-trigger-2021-03-01) .dropdown-menu button:contains('09:00')",
106+
run: "click",
107+
},
108+
// Enter Mr. B details, and confirm
109+
{
110+
trigger:
111+
'.modal.show input[name="partner_name"], .modal input[name="partner_name"]',
112+
run: "edit Mr. B",
113+
},
114+
{
115+
trigger:
116+
'.modal.show input[name="partner_email"], .modal input[name="partner_email"], .modal input[name="email"]',
117+
run: "edit mr.b@example.com",
118+
},
119+
{
120+
trigger: ".modal-dialog .btn:contains('Confirm booking')",
121+
run: "click",
122+
},
123+
{
124+
content: "Try next month if no slots",
125+
trigger: ".alert-danger a:contains('Try next month')",
126+
run: "click",
127+
},
128+
{
129+
content: "Open March 1 calendar dropdown",
130+
trigger: "#dropdown-trigger-2021-03-01",
131+
run: "click",
132+
},
133+
134+
{
135+
trigger:
136+
".dropdown:has(#dropdown-trigger-2021-03-01) .dropdown-menu button:contains('09:30')",
137+
run: "click",
138+
},
139+
// Enter Mr. B details, and confirm
140+
{
141+
trigger:
142+
'.modal.show input[name="partner_name"], .modal input[name="partner_name"]',
143+
run: "edit Mr. C",
144+
},
145+
{
146+
trigger:
147+
'.modal.show input[name="partner_email"], .modal input[name="partner_email"], .modal input[name="email"]',
148+
run: "edit mr.c@example.com",
149+
},
150+
{
151+
trigger: ".modal-dialog .btn:contains('Confirm booking')",
152+
run: "click",
153+
},
154+
tourUtils.goToCheckout(),
155+
{
156+
trigger: ".oe_website_sale",
157+
run: function () {
158+
$('input[name="phone"]').val("+32 485 118.218");
159+
$('input[name="street"]').val("Street A");
160+
$('input[name="city"]').val("City A");
161+
$('input[name="zip"]').val("18503");
162+
$("#country_id option:eq(1)").attr("selected", true);
163+
// Integration with website_sale_vat_required
164+
$('input[name="vat"]').val("US01234567891");
165+
// Integration with website_sale_require_legal
166+
$(".oe_website_sale input[name=accepted_legal_terms]").prop(
167+
"checked",
168+
true
169+
);
170+
},
171+
},
172+
{
173+
trigger: ".btn-primary:contains('Save address')",
174+
},
175+
tourUtils.goToCheckout(),
176+
],
177+
});

0 commit comments

Comments
 (0)