From 3a752ae9ce1204470a1e9fc8ad9f38ac113a8e93 Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Mon, 19 Dec 2016 10:48:25 +0100 Subject: [PATCH] [9.0][website_event_register_free_form_fields] Protect import. Yet another violation of https://github.com/OCA/maintainer-quality-tools/pull/354. --- .../controllers/main.py | 91 ++++++++++--------- 1 file changed, 49 insertions(+), 42 deletions(-) diff --git a/website_event_register_free_form_fields/controllers/main.py b/website_event_register_free_form_fields/controllers/main.py index 2293af2188..8b03915576 100644 --- a/website_event_register_free_form_fields/controllers/main.py +++ b/website_event_register_free_form_fields/controllers/main.py @@ -18,52 +18,59 @@ # along with this program. If not, see . # ############################################################################## -from openerp.addons.website_event_register_free_with_sale.\ - controllers.website_sale import WebsiteSale -from openerp.http import request +import logging +_logger = logging.getLogger(__name__) +try: + from openerp.addons.website_event_register_free_with_sale.\ + controllers.website_sale import WebsiteSale +except ImportError: + _logger.info("ImportError raised while loading module.") + _logger.debug("ImportError details:", exc_info=True) +else: + from openerp.http import request -class WebsiteSale(WebsiteSale): + class WebsiteSale(WebsiteSale): + def checkout_values(self, data=None): + values = super(WebsiteSale, self).checkout_values(data=data) + values['free_tickets'] = request.session.get('free_tickets') + values['has_paid_tickets'] = request.session.get( + 'has_paid_tickets') + if values['free_tickets']: + event = request.env['event.event'].sudo().browse( + int(request.session['event_id'])) - def checkout_values(self, data=None): - values = super(WebsiteSale, self).checkout_values(data=data) - values['free_tickets'] = request.session.get('free_tickets') - values['has_paid_tickets'] = request.session.get('has_paid_tickets') - if values['free_tickets']: - event = request.env['event.event'].sudo().browse( - int(request.session['event_id'])) + extra_fields = [] + select_option = [] - extra_fields = [] - select_option = [] + if 'phone' in self.mandatory_free_registration_fields: + self.mandatory_free_registration_fields.remove('phone') + if 'zip' in self.mandatory_free_registration_fields: + self.mandatory_free_registration_fields.remove('zip') + if 'city' in self.mandatory_free_registration_fields: + self.mandatory_free_registration_fields.remove('city') + if 'street' in self.mandatory_free_registration_fields: + self.mandatory_free_registration_fields.remove('street') + if 'street2' in self.mandatory_free_registration_fields: + self.mandatory_free_registration_fields.remove('street2') - if 'phone' in self.mandatory_free_registration_fields: - self.mandatory_free_registration_fields.remove('phone') - if 'zip' in self.mandatory_free_registration_fields: - self.mandatory_free_registration_fields.remove('zip') - if 'city' in self.mandatory_free_registration_fields: - self.mandatory_free_registration_fields.remove('city') - if 'street' in self.mandatory_free_registration_fields: - self.mandatory_free_registration_fields.remove('street') - if 'street2' in self.mandatory_free_registration_fields: - self.mandatory_free_registration_fields.remove('street2') - - for field in event.available_fields: - extra_fields.append(field.field_id.key) - self.optional_free_registration_fields.append( - field.field_id.key) - if field.is_required: - self.mandatory_free_registration_fields.append( + for field in event.available_fields: + extra_fields.append(field.field_id.key) + self.optional_free_registration_fields.append( field.field_id.key) - if 'options_model' in field and field.options_model: - model = str(field['options_model']) - list_values = field['options_available'].split(',') - for option in list_values: - model_obj = request.env[model].sudo().search( - [('name', '=', option)]) - if model_obj: - select_option.append(option) + if field.is_required: + self.mandatory_free_registration_fields.append( + field.field_id.key) + if 'options_model' in field and field.options_model: + model = str(field['options_model']) + list_values = field['options_available'].split(',') + for option in list_values: + model_obj = request.env[model].sudo().search( + [('name', '=', option)]) + if model_obj: + select_option.append(option) - values['extra_fields'] = extra_fields - if select_option: - values['select_option'] = select_option - return values + values['extra_fields'] = extra_fields + if select_option: + values['select_option'] = select_option + return values