diff --git a/addons/event/__openerp__.py b/addons/event/__openerp__.py
index b9753835aeb..ea0e4316ef5 100644
--- a/addons/event/__openerp__.py
+++ b/addons/event/__openerp__.py
@@ -54,9 +54,6 @@ Note that:
'demo_xml': ['event_demo.xml'],
'test': ['test/process/event_draft2done.yml'],
'css': ['static/src/css/event.css'],
- 'js': [
- #'static/src/js/event.js',
- ],
'installable': True,
'application': True,
'auto_install': False,
diff --git a/addons/event/event.py b/addons/event/event.py
index 27b8269db20..27b6ea657e6 100644
--- a/addons/event/event.py
+++ b/addons/event/event.py
@@ -102,6 +102,25 @@ class event_event(osv.osv):
total_confirmed = self.event.register_current
if total_confirmed < self.event.register_min or total_confirmed > self.event.register_max and self.event.register_max!=0:
raise osv.except_osv(_('Error!'),_("The total of confirmed registration for the event '%s' does not meet the expected minimum/maximum. You should maybe reconsider those limits before going further") % (self.event.name))
+
+ def check_available_seats(self, cr, uid, ids, context=None):
+ if isinstance(ids, list):
+ ids = ids[0]
+ else:
+ ids = ids
+ total_confirmed = self.browse(cr, uid, ids, context=context).register_current
+ register_max = self.browse(cr, uid, ids, context=context).register_max
+ available_seats = register_max - total_confirmed
+ return available_seats
+
+ def check_registration_limits_before(self, cr, uid, ids, no_of_registration, context=None):
+ available_seats = self.check_available_seats(cr, uid, ids, context=context)
+ if no_of_registration > available_seats:
+ if available_seats == 0:
+ raise osv.except_osv(_('Warning!'),_("No Tickets Available!"))
+ else:
+ raise osv.except_osv(_('Warning!'),_("Only %d Seats are Available!") % (available_seats))
+
def confirm_event(self, cr, uid, ids, context=None):
register_pool = self.pool.get('event.registration')
@@ -212,16 +231,25 @@ class event_event(osv.osv):
}
def subscribe_to_event(self, cr, uid, ids, context=None):
+ num_of_seats = int(context['ticket'])
+ available_seats = self.check_available_seats(cr, uid, ids, context=context)
+
+ if num_of_seats > available_seats:
+
+ if available_seats == 0:
+ raise osv.except_osv(_('Warning!'),_("No Tickets Available!"))
+ else:
+ raise osv.except_osv(_('Warning!'),_("Only %d Seats are Available!") % (available_seats))
+
register_pool = self.pool.get('event.registration')
user_pool = self.pool.get('res.users')
user = user_pool.browse(cr, uid, uid, context=context)
- print "user", user
curr_reg_ids = register_pool.search(cr, uid, [('user_id', '=', user.id), ('event_id', '=' , ids[0])])
- print "curr_reg_ids", curr_reg_ids
#the subscription is done with UID = 1 because in case we share the kanban view, we want anyone to be able to subscribe
if not curr_reg_ids:
- curr_reg_ids = [register_pool.create(cr, 1, {'event_id': ids[0] ,'email': user.user_email, 'name':user.name, 'user_id': user.id, 'nb_register': 5})]
- print "::::::::::::::", curr_reg_ids
+ curr_reg_ids = [register_pool.create(cr, 1, {'event_id': ids[0] ,'email': user.user_email, 'name':user.name, 'user_id': user.id, 'nb_register': num_of_seats})]
+ else:
+ register_pool.write(cr, uid, curr_reg_ids, {'nb_register': num_of_seats}, context=context)
return register_pool.confirm_registration(cr, 1, curr_reg_ids, context=context)
def unsubscribe_to_event(self, cr, uid, ids, context=None):
@@ -291,7 +319,6 @@ class event_registration(osv.osv):
return self.write(cr, uid, ids, {'state': 'draft'}, context=context)
def confirm_registration(self, cr, uid, ids, context=None):
- print "confirm_registrationconfirm_registration"
self.message_append(cr, uid, ids,_('State set to open'),body_text= _('Open'))
return self.write(cr, uid, ids, {'state': 'open'}, context=context)
@@ -299,6 +326,10 @@ class event_registration(osv.osv):
def registration_open(self, cr, uid, ids, context=None):
""" Open Registration
"""
+ event_obj = self.pool.get('event.event')
+ event_id = self.browse(cr, uid, ids, context=context)[0].event_id.id
+ no_of_registration = self.browse(cr, uid, ids, context=context)[0].nb_register
+ event_obj.check_registration_limits_before(cr, uid, event_id, no_of_registration, context=context)
res = self.confirm_registration(cr, uid, ids, context=context)
self.mail_user(cr, uid, ids, context=context)
return res
diff --git a/addons/event/event_demo.xml b/addons/event/event_demo.xml
index 96bc64e12aa..81dad07b5e4 100644
--- a/addons/event/event_demo.xml
+++ b/addons/event/event_demo.xml
@@ -38,16 +38,16 @@