[IMP] website_event: create order_line and check registration_limits
bzr revid: chm@openerp.com-20130807134547-rbsrcswsozmna03w
This commit is contained in:
parent
95e8504d5c
commit
c012e3bdc6
|
@ -77,7 +77,7 @@ class sale_order_line(osv.osv):
|
|||
context = {}
|
||||
registration_obj = self.pool.get('event.registration')
|
||||
for order_line in self.browse(cr, uid, ids, context=context):
|
||||
if order_line.event_id.id:
|
||||
if order_line.event_id:
|
||||
dic = {
|
||||
'name': order_line.order_id.partner_invoice_id.name,
|
||||
'partner_id': order_line.order_id.partner_id.id,
|
||||
|
@ -91,8 +91,8 @@ class sale_order_line(osv.osv):
|
|||
print dic
|
||||
|
||||
if order_line.event_ticket_id:
|
||||
if order_line.event_ticket_id.register_avail != 9999 and dic['nb_register'] < order_line.event_ticket_id.register_avail:
|
||||
raise osv.except_osv(_('Error!'), _('There are not enough tickets available (%s).' % order_line.event_ticket_id.register_avail))
|
||||
if order_line.event_ticket_id.register_avail != 9999 and dic['nb_register'] > order_line.event_ticket_id.register_avail:
|
||||
raise osv.except_osv(_('Error!'), _('There are not enough tickets available (%s) for %s' % (order_line.event_ticket_id.register_avail, order_line.event_ticket_id.name)))
|
||||
message = _("The registration has been created for event <i>%s</i> with the ticket <i>%s</i> from the Sale Order %s. ") % (order_line.event_id.name, order_line.event_ticket_id.name, order_line.order_id.name)
|
||||
else:
|
||||
message = _("The registration has been created for event <i>%s</i> from the Sale Order %s. ") % (order_line.event_id.name, order_line.order_id.name)
|
||||
|
@ -107,7 +107,7 @@ class sale_order_line(osv.osv):
|
|||
return {'value': {'price_unit': price}}
|
||||
|
||||
|
||||
class event(osv.osv):
|
||||
class event_event(osv.osv):
|
||||
_inherit = 'event.event'
|
||||
|
||||
def _get_register_max(self, cr, uid, ids, field_name, arg, context=None):
|
||||
|
@ -130,6 +130,12 @@ class event(osv.osv):
|
|||
type='integer', store=True)
|
||||
}
|
||||
|
||||
def check_registration_limits(self, cr, uid, ids, context=None):
|
||||
for event in self.browse(cr, uid, ids, context=context):
|
||||
if event.event_ticket_ids:
|
||||
event.event_ticket_ids.check_registration_limits_before(0)
|
||||
return super(event_event, self).check_registration_limits(cr, uid, ids, context=context)
|
||||
|
||||
|
||||
class event_ticket(osv.osv):
|
||||
_name = 'event.event.ticket'
|
||||
|
@ -181,6 +187,15 @@ class event_ticket(osv.osv):
|
|||
'register_attended': fields.function(_get_register, string='# of Participations', type='integer', multi='register_numbers'),
|
||||
}
|
||||
|
||||
def check_registration_limits_before(self, cr, uid, ids, number, context=None):
|
||||
for ticket in self.browse(cr, uid, ids, context=context):
|
||||
if ticket.register_max:
|
||||
if not ticket.register_avail:
|
||||
raise osv.except_osv(_('Warning!'),_('No Tickets Available for "%s"' % ticket.name))
|
||||
elif number + ticket.register_current > ticket.register_max:
|
||||
raise osv.except_osv(_('Warning!'), _('There only %d tickets available for "%s"' % (ticket.register_avail, ticket.name)))
|
||||
return True
|
||||
|
||||
def onchange_product_id(self, cr, uid, ids, product_id=False, context=None):
|
||||
return {'value': {'price': self.pool.get("product.product").browse(cr, uid, product_id).list_price or 0}}
|
||||
|
||||
|
@ -191,3 +206,11 @@ class event_registration(osv.osv):
|
|||
_columns = {
|
||||
'event_ticket_id': fields.many2one('event.event.ticket', 'Event Ticket'),
|
||||
}
|
||||
|
||||
def registration_open(self, cr, uid, ids, context=None):
|
||||
""" Open Registration
|
||||
"""
|
||||
for registration in self.browse(cr, uid, ids, context=context):
|
||||
if registration.event_ticket_id:
|
||||
registration.event_ticket_id.check_registration_limits_before(1)
|
||||
return super(event_registration, self).registration_open(cr, uid, ids, context=context)
|
||||
|
|
|
@ -10,6 +10,7 @@ from dateutil.relativedelta import relativedelta
|
|||
from openerp import tools
|
||||
import urllib
|
||||
import werkzeug
|
||||
from openerp.osv import osv
|
||||
|
||||
|
||||
class website_event(http.Controller):
|
||||
|
@ -105,9 +106,45 @@ class website_event(http.Controller):
|
|||
|
||||
@http.route(['/event/<int:event_id>/add_cart'], type='http', auth="public")
|
||||
def add_cart(self, event_id=None, **post):
|
||||
if not post:
|
||||
return werkzeug.utils.redirect("/event/%s/" % event_id)
|
||||
order_line_obj = request.registry.get('sale.order.line')
|
||||
ticket_obj = request.registry.get('event.event.ticket')
|
||||
|
||||
order = request.registry['website'].get_rendering_context()['order']
|
||||
partner_id = request.registry.get('res.users').browse(request.cr, SUPERUSER_ID, request.uid).partner_id.id
|
||||
|
||||
context = {}
|
||||
|
||||
fields = [k for k, v in order_line_obj._columns.items()]
|
||||
values = order_line_obj.default_get(request.cr, SUPERUSER_ID, fields, context=context)
|
||||
|
||||
_values = None
|
||||
for key, value in post.items():
|
||||
quantity = int(value)
|
||||
ticket_id = key.split("-")[0] == 'ticket' and int(key.split("-")[1]) or None
|
||||
if not ticket_id or not quantity:
|
||||
continue
|
||||
ticket = ticket_obj.browse(request.cr, request.uid, ticket_id)
|
||||
|
||||
values['product_id'] = ticket.product_id.id
|
||||
values['event_id'] = ticket.event_id.id
|
||||
values['event_ticket_id'] = ticket.id
|
||||
values['product_uom_qty'] = quantity
|
||||
values['price_unit'] = ticket.price
|
||||
values['order_id'] = order.id
|
||||
values['name'] = "%s: %s" % (ticket.event_id.name, ticket.name)
|
||||
|
||||
ticket.check_registration_limits_before(quantity)
|
||||
|
||||
# change and record value
|
||||
pricelist_id = order.pricelist_id and order.pricelist_id.id or False
|
||||
_values = order_line_obj.product_id_change(request.cr, SUPERUSER_ID, [], pricelist_id, ticket.product_id.id, partner_id=partner_id, context=context)['value']
|
||||
_values.update(values)
|
||||
|
||||
order_line_id = order_line_obj.create(request.cr, SUPERUSER_ID, _values, context=context)
|
||||
order.write({'order_line': [(4, order_line_id)]}, context=context)
|
||||
|
||||
if not _values:
|
||||
return werkzeug.utils.redirect("/event/%s/" % event_id)
|
||||
return werkzeug.utils.redirect("/shop/checkout")
|
||||
|
||||
@http.route(['/event/publish'], type='http', auth="public")
|
||||
|
@ -120,3 +157,4 @@ class website_event(http.Controller):
|
|||
obj = data_obj.browse(request.cr, request.uid, obj_id)
|
||||
|
||||
return obj.website_published and "1" or "0"
|
||||
|
||||
|
|
|
@ -171,9 +171,10 @@
|
|||
<td t-field="ticket.price"/>
|
||||
<td><span t-if="ticket.register_max"><t t-esc="ticket.register_current"/>/<t t-field="ticket.register_max"/></span></td>
|
||||
<td>
|
||||
<select t-att-name="'product[%%s]' %% ticket.id">
|
||||
<t t-foreach="range(0,10)" t-as="nb"><option t-esc="nb"/></t>
|
||||
<select t-if="ticket.register_avail" t-att-name="'ticket-%%s' %% ticket.id">
|
||||
<t t-foreach="range(0, ticket.register_avail > 9 and 10 or ticket.register_avail+1 )" t-as="nb"><option t-esc="nb"/></t>
|
||||
</select>
|
||||
<span t-if="not ticket.register_avail">Not ticket available</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
|
|
@ -189,15 +189,16 @@ class Ecommerce(http.Controller):
|
|||
|
||||
my_pids = [line.product_id.id for line in order.order_line]
|
||||
values = website.get_rendering_context({
|
||||
"recommended_products": self.recommended_product(my_pids)
|
||||
"recommended_products": self.recommended_product(my_pids),
|
||||
})
|
||||
|
||||
print values
|
||||
|
||||
return website.render("website_sale.mycart", values)
|
||||
|
||||
@http.route(['/shop/add_cart'], type='http', auth="public")
|
||||
def add_cart(self, product_id=0, remove=False):
|
||||
website = request.registry['website']
|
||||
values = website.get_rendering_context()
|
||||
context = {}
|
||||
|
||||
order_line_obj = request.registry.get('sale.order.line')
|
||||
|
@ -209,6 +210,7 @@ class Ecommerce(http.Controller):
|
|||
quantity = 0
|
||||
|
||||
# values initialisation
|
||||
values = {}
|
||||
order_line_ids = order_line_obj.search(request.cr, openerp.SUPERUSER_ID, [('order_id', '=', order.id), ('product_id', '=', product_id)], context=context)
|
||||
if order_line_ids:
|
||||
order_line = order_line_obj.read(request.cr, openerp.SUPERUSER_ID, order_line_ids, [], context=context)[0]
|
||||
|
@ -235,6 +237,7 @@ class Ecommerce(http.Controller):
|
|||
order_line_id = order_line_obj.create(request.cr, openerp.SUPERUSER_ID, values, context=context)
|
||||
order.write({'order_line': [(4, order_line_id)]}, context=context)
|
||||
|
||||
values = website.get_rendering_context()
|
||||
html = website.render("website_sale.total", values)
|
||||
return simplejson.dumps({"quantity": quantity, "totalHTML": html})
|
||||
|
||||
|
|
|
@ -260,7 +260,7 @@
|
|||
<tbody>
|
||||
<t t-foreach="order.order_line or []" t-as="line">
|
||||
<tr>
|
||||
<td><t t-esc="line.product_id.name"/></td>
|
||||
<td><t t-esc="line.name"/></td>
|
||||
<td><t t-esc="int(line.product_uom_qty)"/></td>
|
||||
<td class="css_alignright"><t t-esc="line.product_id.list_price"/> €</td>
|
||||
</tr>
|
||||
|
|
Loading…
Reference in New Issue