{sale, exhibitor, sale_exhibitor}
Specification:
- Currently, when a user books an event, it redirects to the checkout page;
however, if the user already has some items in their cart, they will appear
at the checkout; if they need to remove them, they must go to the cart page.
It's better to redirect users to the cart page rather than the checkout page.
- When a user enters the booth registration value, it fills the fields name,
email, phone, and mobile, but when the user enters the address of the
order, the same fields are filled by the user, so it is preferred that the
fields value entered in booth registration appears in the address of the
order as well.
This commit done following changes:
- Redirect the review order instead of the checkout order when booking
the event booth.
- By adding the partner to the order, it can propagate the values of the
fields name, phone, and email.
- When a partner is created in the website event booth, the email address is
stored in the name. This commit passes the name and email instead of the
email address so that the partner can be stored with the name.
- If the contact does not have a name or phone number, it will set the
sponsor's name or phone number as the contact.
- Adaptations to the tour to accommodate the above changes
task-3098295
closes odoo/odoo#112525
X-original-commit: ca2bac512000674d1ee55ed3151bbdace2311234
Signed-off-by: Warnon Aurélien (awa) <awa@odoo.com>
156 lines
6.8 KiB
Python
156 lines
6.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
import json
|
|
import werkzeug
|
|
from werkzeug.exceptions import Forbidden, NotFound
|
|
|
|
from odoo import exceptions, http, tools
|
|
from odoo.http import request
|
|
from odoo.addons.website_event.controllers.main import WebsiteEventController
|
|
|
|
|
|
class WebsiteEventBoothController(WebsiteEventController):
|
|
|
|
@http.route('/event/<model("event.event"):event>/booth', type='http', auth='public', website=True, sitemap=True)
|
|
def event_booth_main(self, event):
|
|
try:
|
|
event.check_access_rights('read')
|
|
event.check_access_rule('read')
|
|
except exceptions.AccessError:
|
|
raise Forbidden()
|
|
|
|
event_sudo = event.sudo()
|
|
values = {
|
|
'event': event_sudo,
|
|
'event_booths': event_sudo.event_booth_ids,
|
|
'available_booth_category_ids': event_sudo.event_booth_category_available_ids,
|
|
'main_object': event,
|
|
}
|
|
return request.render('website_event_booth.event_booth_registration', values)
|
|
|
|
@http.route('/event/<model("event.event"):event>/booth/register',
|
|
type='http', auth='public', methods=['POST'], website=True, sitemap=False)
|
|
def event_booth_register(self, event, booth_category_id, event_booth_ids):
|
|
# `event_booth_id` in `requests.params` only contains the first
|
|
# checkbox, we re-parse the form using getlist to get them all
|
|
event_booth_ids = request.httprequest.form.getlist('event_booth_ids')
|
|
|
|
return request.redirect(('/event/%s/booth/register_form?' % event.id) + werkzeug.urls.url_encode({
|
|
'booth_ids': ','.join(event_booth_ids),
|
|
'booth_category_id': int(booth_category_id),
|
|
}))
|
|
|
|
@http.route('/event/<model("event.event"):event>/booth/register_form',
|
|
type='http', auth='public', methods=['GET'], website=True, sitemap=False)
|
|
def event_booth_contact_form(self, event, booth_ids=None, booth_category_id=None):
|
|
if not booth_ids or not booth_category_id:
|
|
raise NotFound()
|
|
|
|
booth_category = request.env['event.booth.category'].sudo().browse(int(booth_category_id))
|
|
event_booths = request.env['event.booth'].sudo().browse([int(booth_id) for booth_id in booth_ids.split(',')])
|
|
default_contact = {}
|
|
if not request.env.user._is_public():
|
|
default_contact = {
|
|
'name': request.env.user.partner_id.name,
|
|
'email': request.env.user.partner_id.email,
|
|
'phone': request.env.user.partner_id.phone,
|
|
'mobile': request.env.user.partner_id.mobile,
|
|
}
|
|
else:
|
|
visitor = request.env['website.visitor']._get_visitor_from_request()
|
|
if visitor.email:
|
|
default_contact = {
|
|
'name': visitor.name,
|
|
'email': visitor.email,
|
|
'mobile': visitor.mobile,
|
|
}
|
|
return request.render(
|
|
'website_event_booth.event_booth_registration_details',
|
|
{'event': event.sudo(),
|
|
'default_contact': default_contact,
|
|
'booth_category': booth_category,
|
|
'event_booths': event_booths,
|
|
}
|
|
)
|
|
|
|
def _get_requested_booths(self, event, event_booth_ids):
|
|
booth_ids = json.loads(event_booth_ids)
|
|
booths = request.env['event.booth'].sudo().search([
|
|
('event_id', '=', event.id),
|
|
('state', '=', 'available'),
|
|
('id', 'in', booth_ids)
|
|
])
|
|
if booth_ids != booths.ids or len(booths.booth_category_id) != 1:
|
|
return request.env['event.booth']
|
|
return booths
|
|
|
|
@http.route('/event/<model("event.event"):event>/booth/confirm',
|
|
type='http', auth='public', methods=['POST'], website=True, sitemap=False)
|
|
def event_booth_registration_confirm(self, event, booth_category_id, event_booth_ids, **kwargs):
|
|
booths = self._get_requested_booths(event, event_booth_ids)
|
|
|
|
if not booths:
|
|
return json.dumps({'error': 'boothError'})
|
|
booth_values = self._prepare_booth_registration_values(event, kwargs)
|
|
booths.action_confirm(booth_values)
|
|
|
|
return self._prepare_booth_registration_success_values(event.name, booth_values)
|
|
|
|
def _prepare_booth_registration_values(self, event, kwargs):
|
|
return self._prepare_booth_registration_partner_values(event, kwargs)
|
|
|
|
def _prepare_booth_registration_partner_values(self, event, kwargs):
|
|
if request.env.user._is_public():
|
|
contact_name_email = tools.formataddr((kwargs['contact_name'], kwargs['contact_email']))
|
|
partner = request.env['res.partner'].sudo().find_or_create(contact_name_email)
|
|
if not partner.name and kwargs.get('contact_name'):
|
|
partner.name = kwargs['contact_name']
|
|
if not partner.phone and kwargs.get('contact_phone'):
|
|
partner.phone = kwargs['contact_phone']
|
|
if not partner.mobile and kwargs.get('contact_mobile'):
|
|
partner.mobile = kwargs['contact_mobile']
|
|
else:
|
|
partner = request.env.user.partner_id
|
|
return {
|
|
'partner_id': partner.id,
|
|
'contact_name': kwargs.get('contact_name') or partner.name,
|
|
'contact_email': kwargs.get('contact_email') or partner.email,
|
|
'contact_mobile': kwargs.get('contact_mobile') or partner.mobile,
|
|
'contact_phone': kwargs.get('contact_phone') or partner.phone,
|
|
}
|
|
|
|
def _prepare_booth_registration_success_values(self, event_name, booth_values):
|
|
return json.dumps({
|
|
'success': True,
|
|
'event_name': event_name,
|
|
'contact': {
|
|
'name': booth_values.get('contact_name'),
|
|
'email': booth_values.get('contact_email'),
|
|
'phone': booth_values.get('contact_phone'),
|
|
'mobile': booth_values.get('contact_mobile'),
|
|
},
|
|
})
|
|
|
|
@http.route('/event/booth/check_availability', type='json', auth='public', methods=['POST'])
|
|
def check_booths_availability(self, event_booth_ids=None):
|
|
if not event_booth_ids:
|
|
return {}
|
|
booths = request.env['event.booth'].sudo().browse(event_booth_ids)
|
|
return {
|
|
'unavailable_booths': booths.filtered(lambda booth: not booth.is_available).ids
|
|
}
|
|
|
|
@http.route(['/event/booth_category/get_available_booths'], type='json', auth='public')
|
|
def get_booth_category_available_booths(self, event_id, booth_category_id):
|
|
booth_ids = request.env['event.booth'].sudo().search([
|
|
('event_id', '=', int(event_id)),
|
|
('booth_category_id', '=', int(booth_category_id)),
|
|
('state', '=', 'available')
|
|
])
|
|
|
|
return [
|
|
{'id': booth.id, 'name': booth.name}
|
|
for booth in booth_ids
|
|
]
|