[ADD]added functionality to register more than 1 subscrition from kanban view, and also checked available seats before registering the event

bzr revid: bde@tinyerp.com-20120419112125-rhzuawb0mp3zsbv6
This commit is contained in:
Bharat Devnani (OpenERP) 2012-04-19 16:51:25 +05:30
commit 8c07bcecc8
4 changed files with 42 additions and 14 deletions

View File

@ -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,

View File

@ -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

View File

@ -38,16 +38,16 @@
<record id="event_1" model="event.event">
<field name="name">Opera of Verdi</field>
<field eval="time.strftime('%Y-%m-05 18:00:00')" name="date_begin"/>
<field eval="time.strftime('%Y-%m-05 21:00:00')" name="date_end"/>
<field eval="(DateTime.today()+ timedelta(days=1)).strftime('%Y-%m-%d 18:00:00')" name="date_begin"/>
<field eval="(DateTime.today()+ timedelta(days=2)).strftime('%Y-%m-%d 21:00:00')" name="date_end"/>
<field name="type" ref="event_type_1"/>
<field name="register_min">50</field>
<field name="register_max">350</field>
</record>
<record id="event_2" model="event.event">
<field name="name">Conference on ERP Business</field>
<field eval="time.strftime('%Y-%m-05 14:00:00')" name="date_begin"/>
<field eval="time.strftime('%Y-%m-05 16:30:00')" name="date_end"/>
<field eval="(DateTime.today()+ timedelta(days=2)).strftime('%Y-%m-%d 14:00:00')" name="date_begin"/>
<field eval="(DateTime.today()+ timedelta(days=2)).strftime('%Y-%m-%d 16:30:00')" name="date_end"/>
<field name="type" ref="event_type_2"/>
<field name="register_max">200</field>
</record>

View File

@ -203,8 +203,8 @@
</p>
<t t-if="record.register_avail.raw_value != 0">
<t t-if="!record.is_subscribed.raw_value">
<textarea class="no_of_seats"/>
<button type="object" name="subscribe_to_event" class="subscribe_button oe_event_button_subscribe">
<input t-att-id="record.id.raw_value" type="text" name="subscribe" class="no_of_seats" onchange="document.getElementById('btn_sub' +this.id).setAttribute('data-context',JSON.stringify({'ticket':this.value}));"/>
<button t-att-id="'btn_sub'+record.id.raw_value" type="object" name="subscribe_to_event" class="subscribe_button oe_event_button_subscribe">
<span >Subscribe</span>
</button>
</t>