2013-08-02 04:35:26 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2013-09-24 10:52:06 +00:00
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
# Copyright (C) 2013-Today OpenERP SA (<http://www.openerp.com>).
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
##############################################################################
|
2013-08-02 04:35:26 +00:00
|
|
|
|
2013-08-06 09:31:15 +00:00
|
|
|
from openerp import SUPERUSER_ID
|
2013-08-02 04:35:26 +00:00
|
|
|
from openerp.addons.web import http
|
|
|
|
from openerp.addons.web.http import request
|
2013-08-02 10:11:22 +00:00
|
|
|
from openerp.tools.translate import _
|
2013-08-28 09:34:16 +00:00
|
|
|
from openerp.addons import website_sale
|
2013-10-01 08:57:39 +00:00
|
|
|
from openerp.addons.website.models import website
|
2013-11-04 15:52:30 +00:00
|
|
|
from openerp.addons.website.controllers.main import Website as controllers
|
|
|
|
controllers = controllers()
|
|
|
|
|
2013-08-02 10:11:22 +00:00
|
|
|
|
|
|
|
from datetime import datetime
|
|
|
|
from dateutil.relativedelta import relativedelta
|
|
|
|
from openerp import tools
|
2013-08-05 10:21:10 +00:00
|
|
|
import urllib
|
|
|
|
|
2013-08-02 04:35:26 +00:00
|
|
|
|
2013-08-05 16:16:00 +00:00
|
|
|
class website_event(http.Controller):
|
2013-09-26 15:07:29 +00:00
|
|
|
@website.route(['/event/', '/event/page/<int:page>/'], type='http', auth="public", multilang=True)
|
2013-08-12 13:43:12 +00:00
|
|
|
def events(self, page=1, **searches):
|
2013-09-24 11:19:57 +00:00
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
2013-08-05 12:44:28 +00:00
|
|
|
event_obj = request.registry['event.event']
|
2013-09-24 11:19:57 +00:00
|
|
|
type_obj = request.registry['event.type']
|
|
|
|
country_obj = request.registry['res.country']
|
2013-08-05 12:44:28 +00:00
|
|
|
|
2013-08-05 10:21:10 +00:00
|
|
|
searches.setdefault('date', 'all')
|
2013-08-05 12:44:28 +00:00
|
|
|
searches.setdefault('type', 'all')
|
2013-08-05 13:04:20 +00:00
|
|
|
searches.setdefault('country', 'all')
|
2013-08-05 15:03:19 +00:00
|
|
|
|
2013-08-05 12:44:28 +00:00
|
|
|
domain_search = {}
|
2013-08-02 10:45:04 +00:00
|
|
|
|
2013-11-11 21:07:59 +00:00
|
|
|
def sdn(date):
|
|
|
|
return date.strftime('%Y-%m-%d 23:59:59')
|
2013-08-02 10:11:22 +00:00
|
|
|
def sd(date):
|
2013-08-02 10:45:04 +00:00
|
|
|
return date.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT)
|
2013-08-02 10:11:22 +00:00
|
|
|
today = datetime.today()
|
|
|
|
dates = [
|
2013-11-11 21:07:59 +00:00
|
|
|
['all', _('Next Events'), [("date_end", ">", sd(today))], 0],
|
2013-08-02 10:11:22 +00:00
|
|
|
['today', _('Today'), [
|
2013-11-11 21:07:59 +00:00
|
|
|
("date_end", ">", sd(today)),
|
|
|
|
("date_begin", "<", sdn(today))],
|
2013-08-02 10:11:22 +00:00
|
|
|
0],
|
|
|
|
['week', _('This Week'), [
|
2013-11-11 21:07:59 +00:00
|
|
|
("date_end", ">=", sd(today + relativedelta(days=-today.weekday()))),
|
|
|
|
("date_begin", "<", sdn(today + relativedelta(days=6-today.weekday())))],
|
2013-08-02 10:11:22 +00:00
|
|
|
0],
|
|
|
|
['nextweek', _('Next Week'), [
|
2013-11-11 21:07:59 +00:00
|
|
|
("date_end", ">=", sd(today + relativedelta(days=7-today.weekday()))),
|
|
|
|
("date_begin", "<", sdn(today + relativedelta(days=13-today.weekday())))],
|
2013-08-02 10:11:22 +00:00
|
|
|
0],
|
|
|
|
['month', _('This month'), [
|
2013-11-11 21:07:59 +00:00
|
|
|
("date_end", ">=", sd(today.replace(day=1))),
|
|
|
|
("date_begin", "<", (today.replace(day=1) + relativedelta(months=1)).strftime('%Y-%m-%d 00:00:00'))],
|
|
|
|
0],
|
|
|
|
['nextmonth', _('Next month'), [
|
|
|
|
("date_end", ">=", sd(today.replace(day=1) + relativedelta(months=1))),
|
|
|
|
("date_begin", "<", (today.replace(day=1) + relativedelta(months=2)).strftime('%Y-%m-%d 00:00:00'))],
|
|
|
|
0],
|
|
|
|
['old', _('Old Events'), [
|
|
|
|
("date_end", "<", today.strftime('%Y-%m-%d 00:00:00'))],
|
2013-08-02 10:11:22 +00:00
|
|
|
0],
|
|
|
|
]
|
|
|
|
|
2013-08-02 10:45:04 +00:00
|
|
|
# search domains
|
2013-11-10 12:42:44 +00:00
|
|
|
current_date = None
|
2013-09-24 11:19:57 +00:00
|
|
|
current_type = None
|
|
|
|
current_country = None
|
2013-08-02 10:45:04 +00:00
|
|
|
for date in dates:
|
2013-09-24 11:19:57 +00:00
|
|
|
if searches["date"] == date[0]:
|
2013-08-05 10:21:10 +00:00
|
|
|
domain_search["date"] = date[2]
|
2013-11-10 12:42:44 +00:00
|
|
|
if date[0] != 'all':
|
|
|
|
current_date = date[1]
|
2013-09-24 11:19:57 +00:00
|
|
|
if searches["type"] != 'all':
|
|
|
|
current_type = type_obj.browse(cr, uid, int(searches['type']), context=context)
|
|
|
|
domain_search["type"] = [("type", "=", int(searches["type"]))]
|
|
|
|
if searches["country"] != 'all':
|
|
|
|
current_country = country_obj.browse(cr, uid, int(searches['country']), context=context)
|
|
|
|
domain_search["country"] = [("country_id", "=", int(searches["country"]))]
|
2013-08-05 13:04:20 +00:00
|
|
|
|
|
|
|
def dom_without(without):
|
2013-11-11 21:24:33 +00:00
|
|
|
domain = [('state', "in", ['draft','confirm','done'])]
|
2013-08-05 13:04:20 +00:00
|
|
|
for key, search in domain_search.items():
|
|
|
|
if key != without:
|
|
|
|
domain += search
|
|
|
|
return domain
|
2013-08-02 10:45:04 +00:00
|
|
|
|
|
|
|
# count by domains without self search
|
|
|
|
for date in dates:
|
2013-11-11 21:07:59 +00:00
|
|
|
if date[0] <> 'old':
|
|
|
|
date[3] = event_obj.search(
|
|
|
|
request.cr, request.uid, dom_without('date') + date[2],
|
|
|
|
count=True, context=request.context)
|
2013-08-02 10:45:04 +00:00
|
|
|
|
2013-08-05 13:04:20 +00:00
|
|
|
domain = dom_without('type')
|
2013-09-05 15:18:03 +00:00
|
|
|
types = event_obj.read_group(
|
|
|
|
request.cr, request.uid, domain, ["id", "type"], groupby="type",
|
|
|
|
orderby="type", context=request.context)
|
|
|
|
type_count = event_obj.search(request.cr, request.uid, domain,
|
|
|
|
count=True, context=request.context)
|
|
|
|
types.insert(0, {
|
|
|
|
'type_count': type_count,
|
|
|
|
'type': ("all", _("All Categories"))
|
|
|
|
})
|
2013-08-05 10:21:10 +00:00
|
|
|
|
2013-08-05 13:04:20 +00:00
|
|
|
domain = dom_without('country')
|
2013-09-05 15:18:03 +00:00
|
|
|
countries = event_obj.read_group(
|
|
|
|
request.cr, request.uid, domain, ["id", "country_id"],
|
|
|
|
groupby="country_id", orderby="country_id", context=request.context)
|
|
|
|
country_id_count = event_obj.search(request.cr, request.uid, domain,
|
|
|
|
count=True, context=request.context)
|
|
|
|
countries.insert(0, {
|
|
|
|
'country_id_count': country_id_count,
|
|
|
|
'country_id': ("all", _("All Countries"))
|
|
|
|
})
|
2013-08-05 10:21:10 +00:00
|
|
|
|
2013-08-12 13:43:12 +00:00
|
|
|
step = 5
|
2013-09-05 15:18:03 +00:00
|
|
|
event_count = event_obj.search(
|
|
|
|
request.cr, request.uid, dom_without("none"), count=True,
|
|
|
|
context=request.context)
|
2013-09-10 13:41:33 +00:00
|
|
|
pager = request.website.pager(url="/event/", total=event_count, page=page, step=step, scope=5)
|
2013-11-11 21:07:59 +00:00
|
|
|
|
|
|
|
order = 'website_published desc, date_begin'
|
|
|
|
if searches.get('date','all') == 'old':
|
|
|
|
order = 'website_published desc, date_begin desc'
|
2013-09-05 15:18:03 +00:00
|
|
|
obj_ids = event_obj.search(
|
|
|
|
request.cr, request.uid, dom_without("none"), limit=step,
|
2013-11-11 21:07:59 +00:00
|
|
|
offset=pager['offset'], order=order, context=request.context)
|
2013-09-05 15:18:03 +00:00
|
|
|
events_ids = event_obj.browse(request.cr, request.uid, obj_ids,
|
|
|
|
context=request.context)
|
2013-08-02 10:45:04 +00:00
|
|
|
|
2013-09-04 15:32:36 +00:00
|
|
|
values = {
|
2013-09-24 11:19:57 +00:00
|
|
|
'current_date': current_date,
|
|
|
|
'current_country': current_country,
|
|
|
|
'current_type': current_type,
|
2013-09-05 15:18:03 +00:00
|
|
|
'event_ids': events_ids,
|
2013-08-02 10:11:22 +00:00
|
|
|
'dates': dates,
|
2013-08-05 12:44:28 +00:00
|
|
|
'types': types,
|
2013-08-05 13:04:20 +00:00
|
|
|
'countries': countries,
|
2013-08-12 13:43:12 +00:00
|
|
|
'pager': pager,
|
2013-08-05 10:21:10 +00:00
|
|
|
'searches': searches,
|
|
|
|
'search_path': "?%s" % urllib.urlencode(searches),
|
2013-09-04 15:32:36 +00:00
|
|
|
}
|
2013-08-02 04:35:26 +00:00
|
|
|
|
2013-09-10 13:41:33 +00:00
|
|
|
return request.website.render("website_event.index", values)
|
2013-08-02 04:35:26 +00:00
|
|
|
|
2013-09-26 15:07:29 +00:00
|
|
|
@website.route(['/event/<int:event_id>'], type='http', auth="public", multilang=True)
|
2013-08-02 10:45:04 +00:00
|
|
|
def event(self, event_id=None, **post):
|
2013-09-05 15:18:03 +00:00
|
|
|
event_obj = request.registry['event.event']
|
2013-10-17 08:35:34 +00:00
|
|
|
event = event_obj.browse(request.cr, request.uid, event_id, dict(request.context, show_address_only=1))
|
2013-09-04 15:32:36 +00:00
|
|
|
values = {
|
2013-10-17 08:35:34 +00:00
|
|
|
'event_id': event,
|
|
|
|
'main_object': event,
|
2013-09-28 19:13:47 +00:00
|
|
|
'range': range,
|
|
|
|
'float': float,
|
2013-09-04 15:32:36 +00:00
|
|
|
}
|
2013-09-24 10:52:06 +00:00
|
|
|
return request.website.render("website_event.event_description_full", values)
|
2013-08-05 15:03:19 +00:00
|
|
|
|
2013-09-26 15:07:29 +00:00
|
|
|
@website.route(['/event/<int:event_id>/add_cart'], type='http', auth="public", multilang=True)
|
2013-08-05 15:03:19 +00:00
|
|
|
def add_cart(self, event_id=None, **post):
|
2013-08-28 09:34:16 +00:00
|
|
|
user_obj = request.registry['res.users']
|
2013-08-07 13:45:47 +00:00
|
|
|
order_line_obj = request.registry.get('sale.order.line')
|
|
|
|
ticket_obj = request.registry.get('event.event.ticket')
|
|
|
|
|
2013-09-10 14:15:02 +00:00
|
|
|
order = request.context['website_sale_order']
|
2013-08-28 09:34:16 +00:00
|
|
|
if not order:
|
|
|
|
order = website_sale.controllers.main.get_order()
|
|
|
|
|
2013-09-05 15:18:03 +00:00
|
|
|
partner_id = user_obj.browse(request.cr, SUPERUSER_ID, request.uid,
|
|
|
|
context=request.context).partner_id.id
|
2013-08-07 13:45:47 +00:00
|
|
|
|
|
|
|
fields = [k for k, v in order_line_obj._columns.items()]
|
2013-09-05 15:18:03 +00:00
|
|
|
values = order_line_obj.default_get(request.cr, SUPERUSER_ID, fields,
|
|
|
|
context=request.context)
|
2013-08-07 13:45:47 +00:00
|
|
|
|
|
|
|
_values = None
|
|
|
|
for key, value in post.items():
|
2013-10-30 16:29:09 +00:00
|
|
|
try:
|
|
|
|
quantity = int(value)
|
|
|
|
except:
|
|
|
|
quantity = None
|
2013-08-07 13:45:47 +00:00
|
|
|
ticket_id = key.split("-")[0] == 'ticket' and int(key.split("-")[1]) or None
|
|
|
|
if not ticket_id or not quantity:
|
|
|
|
continue
|
2013-09-05 15:18:03 +00:00
|
|
|
ticket = ticket_obj.browse(request.cr, request.uid, ticket_id,
|
|
|
|
context=request.context)
|
2013-08-07 13:45:47 +00:00
|
|
|
|
|
|
|
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)
|
2013-08-05 15:03:19 +00:00
|
|
|
|
2013-08-07 13:45:47 +00:00
|
|
|
ticket.check_registration_limits_before(quantity)
|
|
|
|
|
|
|
|
# change and record value
|
|
|
|
pricelist_id = order.pricelist_id and order.pricelist_id.id or False
|
2013-09-05 15:18:03 +00:00
|
|
|
_values = order_line_obj.product_id_change(
|
|
|
|
request.cr, SUPERUSER_ID, [], pricelist_id, ticket.product_id.id,
|
|
|
|
partner_id=partner_id, context=request.context)['value']
|
2013-08-07 13:45:47 +00:00
|
|
|
_values.update(values)
|
|
|
|
|
2013-09-05 15:18:03 +00:00
|
|
|
order_line_id = order_line_obj.create(request.cr, SUPERUSER_ID,
|
|
|
|
_values, context=request.context)
|
|
|
|
order.write({'order_line': [(4, order_line_id)]}, context=request.context)
|
2013-08-07 13:45:47 +00:00
|
|
|
|
|
|
|
if not _values:
|
2013-09-26 15:07:29 +00:00
|
|
|
return request.redirect("/event/%s/" % event_id)
|
|
|
|
return request.redirect("/shop/checkout")
|
2013-11-04 15:52:30 +00:00
|
|
|
|
|
|
|
@website.route(['/event/publish'], type='json', auth="public")
|
|
|
|
def publish(self, id, object):
|
|
|
|
# if a user publish an event, he publish all linked res.partner
|
|
|
|
event = request.registry[object].browse(request.cr, request.uid, int(id))
|
|
|
|
if not event.website_published:
|
|
|
|
if event.organizer_id and not event.organizer_id.website_published:
|
|
|
|
event.organizer_id.write({'website_published': True})
|
|
|
|
if event.address_id and not event.address_id.website_published:
|
|
|
|
event.address_id.write({'website_published': True})
|
|
|
|
|
|
|
|
return controllers.publish(id, object)
|