Skip to content

Commit

Permalink
[9.0][website_event_register_free_form_fields] Protect import.
Browse files Browse the repository at this point in the history
Yet another violation of OCA/maintainer-quality-tools#354.
  • Loading branch information
yajo committed Dec 19, 2016
1 parent 0cf2ef7 commit 3a752ae
Showing 1 changed file with 49 additions and 42 deletions.
91 changes: 49 additions & 42 deletions website_event_register_free_form_fields/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,52 +18,59 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
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

0 comments on commit 3a752ae

Please sign in to comment.