[REF] website_event(_sale): create registrations in batch when buying tickets

PURPOSE

Create event registrations in batch. It will allow to customize group-creation
of registrations, notably with automated rules for crm / event synchronization.

SPECIFICATIONS

Instead of creating registrations one by one when processing registration
form details, simply batch-ize their creation.

Instead of creating registrations one by one when adding a new line in cart
simply let website_event handle its job, or the confirmation action of a
sale order that already populates registrations.

Creating registrations when adding a cart line has no real use as we have
no specific information to create that registration. It is better to let
the flow finish and create additional registrations in batch once SO is
confirmed.

LINKS

Task ID 2258685
Prepare Task ID 2166679 (create leads from registrations)
PR odoo/odoo#51341

Co-Authored-By: Jeremy Hennecart <jeh@odoo.com>
Co-Authored-By: Thibault Delavallée <tde@odoo.com>
This commit is contained in:
Jérémy Hennecart
2020-05-18 11:58:56 +00:00
committed by Thibault Delavallée
co-authored by Thibault Delavallée
parent 83a7fb5f92
commit d01144e17d
3 changed files with 9 additions and 16 deletions
+3 -4
View File
@@ -332,15 +332,14 @@ class WebsiteEventController(http.Controller):
return list(registrations.values())
def _create_attendees_from_registration_post(self, event, registration_data):
attendees_sudo = request.env['event.registration'].sudo()
registrations_to_create = []
for registration_values in registration_data:
registration_values['event_id'] = event.id
if not registration_values.get('partner_id'):
registration_values['partner_id'] = request.env.user.partner_id.id
attendees_sudo += request.env['event.registration'].sudo().create(registration_values)
registrations_to_create.append(registration_values)
return attendees_sudo
return request.env['event.registration'].sudo().create(registrations_to_create)
@http.route(['''/event/<model("event.event"):event>/registration/confirm'''], type='http', auth="public", methods=['POST'], website=True)
def registration_confirm(self, event, **post):
@@ -29,17 +29,13 @@ class WebsiteEventSaleController(WebsiteEventController):
if any(info.get('event_ticket_id') for info in registration_data):
order = request.website.sale_get_order(force_create=1)
order_attendee_ids = set()
for info in [r for r in registration_data if r.get('event_ticket_id')]:
ticket = request.env['event.event.ticket'].sudo().browse(info['event_ticket_id'])
cart_values = order.with_context(event_ticket_id=ticket.id, fixed_price=True)._cart_update(product_id=ticket.product_id.id, add_qty=1, registration_data=[info])
order_attendee_ids |= set(cart_values.get('attendee_ids', []))
cart_values = order.with_context(event_ticket_id=ticket.id, fixed_price=True)._cart_update(product_id=ticket.product_id.id, add_qty=1)
info['sale_order_id'] = order.id
info['sale_order_line_id'] = cart_values.get('line_id')
attendees_sudo = super(WebsiteEventSaleController, self)._create_attendees_from_registration_post(event, [r for r in registration_data if not r['event_ticket_id']])
if order_attendee_ids:
attendees_sudo |= request.env['event.registration'].sudo().browse(order_attendee_ids)
return attendees_sudo
return super(WebsiteEventSaleController, self)._create_attendees_from_registration_post(event, registration_data)
@http.route()
def registration_confirm(self, event, **post):
@@ -91,10 +91,8 @@ class SaleOrder(models.Model):
attendees.action_cancel()
# adding attendees
elif ticket and new_qty > old_qty:
line = OrderLine.browse(values['line_id'])
line._update_registrations(confirm=False, cancel_to_draft=True, registration_data=kwargs.get('registration_data', []))
# add in return values the registrations, to display them on website (or not)
values['attendee_ids'] = self.env['event.registration'].search([('sale_order_line_id', '=', line.id), ('state', '!=', 'cancel')]).ids
# do not do anything, attendees will be created at SO confirmation if not given previously
pass
return values