Debian Codegraph @

addons/website_event_booth_sale/controllers/event_booth.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 # Part of Odoo. See LICENSE file for full copyright and licensing details.
3
4 import json
5
6 from odoo.http import request, route
7 from odoo.addons.website_event.controllers.main import WebsiteEventController
8
9
10 class WebsiteEventBoothController(WebsiteEventController):
11
12 @route()
13 def event_booth_registration_confirm(self, event, booth_category_id, event_booth_ids, **kwargs):
14 """Override: Doesn't call the parent method because we go through the checkout
15 process which will confirm the booths when receiving the payment."""
16 booths = self._get_requested_booths(event, event_booth_ids)
17 booth_category = request.env['event.booth.category'].sudo().browse(int(booth_category_id))
18 error_code = self._check_booth_registration_values(
19 booths,
20 kwargs['contact_email'],
21 booth_category=booth_category)
22 if error_code:
23 return json.dumps({'error': error_code})
24
25 booth_values = self._prepare_booth_registration_values(event, kwargs)
26 order_sudo = request.cart or request.website._create_cart()
27 if order_sudo._is_anonymous_cart():
28 order_sudo._update_address(booth_values['partner_id'], ['partner_id'])
29 order_sudo._cart_add(
30 product_id=booth_category.product_id.id,
31 quantity=1,
32 event_booth_pending_ids=booths.ids,
33 registration_values=booth_values,
34 )
35 if order_sudo.amount_total:
36 return json.dumps({'redirect': '/shop/cart'})
37 else:
38 order_sudo.action_confirm()
39 request.website.sale_reset()
40
41 return self._prepare_booth_registration_success_values(event.name, booth_values)
42
43 def _prepare_booth_contact_form_values(self, event, booth_ids, booth_category_id):
44 values = super()._prepare_booth_contact_form_values(event, booth_ids, booth_category_id)
45 values['has_payment_step'] = request.cart.amount_total or \
46 values.get('booth_category', request.env['event.booth.category']).price
47 return values
48
49 def _prepare_booth_main_values(self, event, booth_category_id=False, booth_ids=False):
50 values = super()._prepare_booth_main_values(event, booth_category_id=booth_category_id, booth_ids=booth_ids)
51 values['has_payment_step'] = request.cart.amount_total or \
52 any(booth_category.price for booth_category in values.get('available_booth_category_ids', request.env['event.booth.category']))
53 return values