*: website_event, website_event_sale, website_forum, website_sale, website_sale_slides, website_slides, website_slides_forum This commit removes the remaining controllers that are no longer used since the use of form views on website new content dialogs (following the website in backend merge at [1] and the many iterations afterwards). With the website in backend work, a feature was lost for the creation of events: dummy tickets were created. This commit actually removes the feature for good. Events default values are managed by templates. Moreover there are links in frontend to edit the event when being allowed to edit it (event groups), notably when there is no ticket in registration page. So it makes no sense to create dummy tickets, without price, for 1000 seats. Those values are random so they will have to be edited. Better let users create real tickets if necessary, than editing and/or removing dummy tickets. [1]: https://github.com/odoo/odoo/commit/31cc10b91dc7762e23b4bde9b945be0c4ce3fe3b task-2687506 closes odoo/odoo#102928 X-original-commit: d559ce5d1518ac1293db1c4f52efb8094daf5b49 Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com> Co-authored-by: qsm-odoo <qsm@odoo.com>
79 lines
3.2 KiB
Python
79 lines
3.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from collections import defaultdict
|
|
from odoo import _
|
|
from odoo.http import request, route
|
|
|
|
from odoo.addons.website_event.controllers.main import WebsiteEventController
|
|
|
|
|
|
class WebsiteEventSaleController(WebsiteEventController):
|
|
|
|
@route()
|
|
def event_register(self, event, **post):
|
|
event = event.with_context(pricelist=request.website.id)
|
|
if not request.context.get('pricelist'):
|
|
pricelist = request.website.pricelist_id
|
|
if pricelist:
|
|
event = event.with_context(pricelist=pricelist.id)
|
|
return super().event_register(event, **post)
|
|
|
|
def _process_tickets_form(self, event, form_details):
|
|
""" Add price information on ticket order """
|
|
res = super()._process_tickets_form(event, form_details)
|
|
for item in res:
|
|
item['price'] = item['ticket']['price'] if item['ticket'] else 0
|
|
return res
|
|
|
|
def _create_attendees_from_registration_post(self, event, registration_data):
|
|
# we have at least one registration linked to a ticket -> sale mode activate
|
|
if not any(info.get('event_ticket_id') for info in registration_data):
|
|
return super()._create_attendees_from_registration_post(event, registration_data)
|
|
|
|
order_sudo = request.website.sale_get_order(force_create=True)
|
|
|
|
tickets_data = defaultdict(int)
|
|
for data in registration_data:
|
|
event_ticket_id = data.get('event_ticket_id')
|
|
if event_ticket_id:
|
|
tickets_data[event_ticket_id] += 1
|
|
|
|
cart_data = {}
|
|
for ticket_id, count in tickets_data.items():
|
|
ticket_sudo = request.env['event.event.ticket'].sudo().browse(ticket_id)
|
|
cart_values = order_sudo._cart_update(
|
|
product_id=ticket_sudo.product_id.id,
|
|
add_qty=count,
|
|
event_ticket_id=ticket_id,
|
|
)
|
|
cart_data[ticket_id] = cart_values['line_id']
|
|
|
|
for data in registration_data:
|
|
event_ticket_id = data.get('event_ticket_id')
|
|
if event_ticket_id:
|
|
data['sale_order_id'] = order_sudo.id
|
|
data['sale_order_line_id'] = cart_data[event_ticket_id]
|
|
|
|
request.session['website_sale_cart_quantity'] = order_sudo.cart_quantity
|
|
|
|
return super()._create_attendees_from_registration_post(event, registration_data)
|
|
|
|
@route()
|
|
def registration_confirm(self, event, **post):
|
|
res = super().registration_confirm(event, **post)
|
|
|
|
registrations = self._process_attendees_form(event, post)
|
|
|
|
# we have at least one registration linked to a ticket -> sale mode activate
|
|
if any(info['event_ticket_id'] for info in registrations):
|
|
order_sudo = request.website.sale_get_order()
|
|
if order_sudo.amount_total:
|
|
return request.redirect("/shop/checkout")
|
|
# free tickets -> order with amount = 0: auto-confirm, no checkout
|
|
elif order_sudo:
|
|
order_sudo.action_confirm() # tde notsure: email sending ?
|
|
request.website.sale_reset()
|
|
|
|
return res
|