[IMP] website_sale: clean code and fix for website_event
bzr revid: chm@openerp.com-20131127111658-qkp3ovoa64n3dwp2
This commit is contained in:
parent
b45dfac7fe
commit
3bb30b1337
|
@ -25,6 +25,7 @@ from openerp.addons.web.http import request
|
|||
from openerp.tools.translate import _
|
||||
from openerp.addons.website.models import website
|
||||
from openerp.addons.website.controllers.main import Website as controllers
|
||||
from openerp.addons.website_sale.controllers.main import Ecommerce as Ecommerce
|
||||
controllers = controllers()
|
||||
|
||||
|
||||
|
@ -33,6 +34,9 @@ from dateutil.relativedelta import relativedelta
|
|||
from openerp import tools
|
||||
import urllib
|
||||
|
||||
# remove product event from the website content grid and list view (not removed in detail view)
|
||||
Ecommerce.domain += [('event_ok', '=', False)]
|
||||
|
||||
class website_event(http.Controller):
|
||||
@website.route(['/event/', '/event/page/<int:page>'], type='http', auth="public", multilang=True)
|
||||
def events(self, page=1, **searches):
|
||||
|
|
|
@ -262,7 +262,16 @@
|
|||
<div><small t-field="ticket.product_id.description_sale"/></div>
|
||||
</td>
|
||||
<td><span t-field="ticket.deadline"/></td>
|
||||
<td><span t-field="ticket.price"/></td>
|
||||
<td>
|
||||
<t t-if="ticket.price or editable"><span t-field="ticket.price" t-field-options='{
|
||||
"widget": "monetary",
|
||||
"display_currency": "website.pricelist_id.currency_id"
|
||||
}'/>
|
||||
</t>
|
||||
<t t-if="not ticket.price and not editable">
|
||||
<span>Free</span>
|
||||
</t>
|
||||
</td>
|
||||
<td>
|
||||
<span t-if="ticket.register_max and ((ticket.register_current or 0)*100 / ticket.register_max)>75" class="text-muted">
|
||||
<t t-esc="ticket.register_max - ticket.register_current"/> <span>left</span>
|
||||
|
|
|
@ -1,2 +1 @@
|
|||
import website
|
||||
import main
|
||||
|
|
|
@ -69,6 +69,12 @@ class Ecommerce(http.Controller):
|
|||
|
||||
return (categories, full_category_ids)
|
||||
|
||||
def get_pricelist(self):
|
||||
return request.registry.get('website').get_pricelist_id(request.cr, request.uid, None, context=request.context)
|
||||
|
||||
def change_pricelist(self):
|
||||
return request.registry.get('website').change_pricelist_id(request.cr, request.uid, None, context=request.context)
|
||||
|
||||
def get_bin_packing_products(self, product_ids, fill_hole, col_number=4):
|
||||
"""
|
||||
Packing all products of the search into a table of #col_number columns in function of the product sizes
|
||||
|
@ -368,42 +374,13 @@ class Ecommerce(http.Controller):
|
|||
|
||||
return request.redirect("/shop/product/%s/?enable_editor=1" % product.product_tmpl_id.id)
|
||||
|
||||
def get_pricelist(self):
|
||||
if not request.httprequest.session.get('ecommerce_pricelist'):
|
||||
self.change_pricelist(None)
|
||||
return request.httprequest.session.get('ecommerce_pricelist')
|
||||
|
||||
def change_pricelist(self, code):
|
||||
request.httprequest.session.setdefault('ecommerce_pricelist', False)
|
||||
|
||||
pricelist_id = False
|
||||
if code:
|
||||
pricelist_obj = request.registry.get('product.pricelist')
|
||||
pricelist_ids = pricelist_obj.search(request.cr, SUPERUSER_ID, [('code', '=', code)], context=request.context)
|
||||
if pricelist_ids:
|
||||
pricelist_id = pricelist_ids[0]
|
||||
|
||||
if not pricelist_id:
|
||||
partner_id = request.registry.get('res.users').browse(request.cr, SUPERUSER_ID, request.uid, request.context).partner_id.id
|
||||
pricelist_id = request.registry['sale.order'].onchange_partner_id(request.cr, SUPERUSER_ID, [], partner_id, context=request.context)['value']['pricelist_id']
|
||||
|
||||
request.httprequest.session['ecommerce_pricelist'] = pricelist_id
|
||||
|
||||
order = request.registry['website'].get_current_order(request.cr, request.uid, context=request.context)
|
||||
if order:
|
||||
values = {'pricelist_id': pricelist_id}
|
||||
values.update(order.onchange_pricelist_id(pricelist_id, None)['value'])
|
||||
order.write(values)
|
||||
for line in order.order_line:
|
||||
self.add_product_to_cart(order_line_id=line.id, number=0)
|
||||
|
||||
def add_product_to_cart(self, product_id=0, order_line_id=0, number=1, set_number=-1):
|
||||
order_line_obj = request.registry.get('sale.order.line')
|
||||
order_obj = request.registry.get('sale.order')
|
||||
|
||||
order = request.registry.get('website').get_current_order(request.cr, request.uid, context=request.context)
|
||||
order = website.get_current_order(request.cr, request.uid, context=request.context)
|
||||
if not order:
|
||||
order = request.registry.get('website')._get_order(request.cr, request.uid, context=request.context)
|
||||
order = website._get_order(request.cr, request.uid, context=request.context)
|
||||
|
||||
request.context = dict(request.context, pricelist=self.get_pricelist())
|
||||
|
||||
|
|
|
@ -1,84 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import uuid
|
||||
|
||||
from openerp import SUPERUSER_ID
|
||||
from openerp.osv import osv
|
||||
from openerp.addons.web.http import request
|
||||
|
||||
|
||||
class Website(osv.Model):
|
||||
_inherit = "website"
|
||||
|
||||
def _get_order(self, cr, uid, order_id=None, context=None):
|
||||
order_obj = request.registry.get('sale.order')
|
||||
# check if order allready exists and have access
|
||||
if order_id:
|
||||
if not order_id in order_obj.exists(cr, uid, [order_id], context=context):
|
||||
return False
|
||||
try:
|
||||
order = order_obj.browse(cr, uid, order_id, context=context)
|
||||
if order:
|
||||
return order
|
||||
except:
|
||||
return False
|
||||
|
||||
fields = [k for k, v in order_obj._columns.items()]
|
||||
order_value = order_obj.default_get(cr, SUPERUSER_ID, fields, context=context)
|
||||
if request.httprequest.session.get('ecommerce_pricelist'):
|
||||
order_value['pricelist_id'] = request.httprequest.session['ecommerce_pricelist']
|
||||
order_value['partner_id'] = request.registry.get('res.users').browse(cr, SUPERUSER_ID, uid, context=context).partner_id.id
|
||||
order_value.update(order_obj.onchange_partner_id(cr, SUPERUSER_ID, [], order_value['partner_id'], context=context)['value'])
|
||||
|
||||
# add website_session_id key for access rules
|
||||
if not request.httprequest.session.get('website_session_id'):
|
||||
request.httprequest.session['website_session_id'] = str(uuid.uuid4())
|
||||
|
||||
order_value["website_session_id"] = request.httprequest.session['website_session_id']
|
||||
order_id = order_obj.create(cr, SUPERUSER_ID, order_value, context=context)
|
||||
order = order_obj.browse(cr, SUPERUSER_ID, order_id, context=context)
|
||||
request.httprequest.session['ecommerce_order_id'] = order.id
|
||||
|
||||
return order_obj.browse(cr, uid, order_id,
|
||||
context=dict(request.context, pricelist=order.pricelist_id.id))
|
||||
|
||||
def get_current_order(self, cr, uid, context=None):
|
||||
if request.httprequest.session.get('ecommerce_order_id'):
|
||||
order = self._get_order(cr, uid, order_id=request.httprequest.session['ecommerce_order_id'], context=context)
|
||||
if not order:
|
||||
request.httprequest.session['ecommerce_order_id'] = False
|
||||
return order
|
||||
return False
|
||||
|
||||
def _get_transaction(self, cr, uid, tx_id=None, context=None):
|
||||
transaction_obj = request.registry['payment.transaction']
|
||||
if tx_id:
|
||||
tx_ids = transaction_obj.search(cr, uid, [('id', '=', tx_id), ('state', 'not in', ['cancel'])], context=context)
|
||||
if tx_ids:
|
||||
return transaction_obj.browse(cr, uid, tx_ids[0], context=context)
|
||||
return False
|
||||
|
||||
def get_current_transaction(self, cr, uid, context=None):
|
||||
if request.httprequest.session.get('website_sale_transaction_id'):
|
||||
tx = self._get_transaction(cr, uid, tx_id=request.httprequest.session['website_sale_transaction_id'], context=context)
|
||||
if not tx:
|
||||
request.httprequest.session['website_sale_transaction_id'] = False
|
||||
return tx
|
||||
return False
|
||||
|
||||
def sale_reset_order(self, cr, uid, context=None):
|
||||
request.httprequest.session.update({
|
||||
'ecommerce_order_id': False,
|
||||
'ecommerce_pricelist': False,
|
||||
'website_sale_transaction_id': False,
|
||||
})
|
||||
request.context.update({
|
||||
'website_sale_order': False,
|
||||
'website_sale_transaction': False,
|
||||
})
|
||||
|
||||
def preprocess_request(self, cr, uid, ids, request, context=None):
|
||||
request.context.update({
|
||||
'website_sale_order': self.get_current_order(cr, uid, context=context),
|
||||
'website_sale_transaction': self.get_current_transaction(cr, uid, context=context)
|
||||
})
|
||||
return super(Website, self).preprocess_request(cr, uid, ids, request, context=None)
|
|
@ -1,6 +1,8 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import uuid
|
||||
from openerp.osv import orm, fields
|
||||
from openerp.addons.web import http
|
||||
from openerp.addons.web.http import request
|
||||
from openerp import SUPERUSER_ID
|
||||
|
||||
|
||||
class Website(orm.Model):
|
||||
|
@ -8,7 +10,7 @@ class Website(orm.Model):
|
|||
|
||||
def _get_pricelist(self, cr, uid, ids, field_name, arg, context=None):
|
||||
# FIXME: oh god kill me now
|
||||
pricelist_id = http.request.httprequest.session['ecommerce_pricelist']
|
||||
pricelist_id = self.get_pricelist_id(cr, uid, ids, context=context)
|
||||
return dict.fromkeys(
|
||||
ids, self.pool['product.pricelist'].browse(
|
||||
cr, uid, pricelist_id, context=context))
|
||||
|
@ -18,6 +20,109 @@ class Website(orm.Model):
|
|||
_get_pricelist, type='many2one', obj='product.pricelist')
|
||||
}
|
||||
|
||||
def _get_order(self, cr, uid, order_id=None, context=None):
|
||||
order_obj = self.pool.get('sale.order')
|
||||
# check if order allready exists and have access
|
||||
if order_id:
|
||||
if not order_id in order_obj.exists(cr, uid, [order_id], context=context):
|
||||
return False
|
||||
try:
|
||||
order = order_obj.browse(cr, uid, order_id, context=context)
|
||||
if order:
|
||||
return order
|
||||
except:
|
||||
return False
|
||||
|
||||
fields = [k for k, v in order_obj._columns.items()]
|
||||
order_value = order_obj.default_get(cr, SUPERUSER_ID, fields, context=context)
|
||||
if request.httprequest.session.get('ecommerce_pricelist'):
|
||||
order_value['pricelist_id'] = request.httprequest.session['ecommerce_pricelist']
|
||||
order_value['partner_id'] = self.pool.get('res.users').browse(cr, SUPERUSER_ID, uid, context=context).partner_id.id
|
||||
order_value.update(order_obj.onchange_partner_id(cr, SUPERUSER_ID, [], order_value['partner_id'], context=context)['value'])
|
||||
|
||||
# add website_session_id key for access rules
|
||||
if not request.httprequest.session.get('website_session_id'):
|
||||
request.httprequest.session['website_session_id'] = str(uuid.uuid4())
|
||||
|
||||
order_value["website_session_id"] = request.httprequest.session['website_session_id']
|
||||
order_id = order_obj.create(cr, SUPERUSER_ID, order_value, context=context)
|
||||
order = order_obj.browse(cr, SUPERUSER_ID, order_id, context=context)
|
||||
request.httprequest.session['ecommerce_order_id'] = order.id
|
||||
|
||||
return order_obj.browse(cr, uid, order_id,
|
||||
context=dict(request.context, pricelist=order.pricelist_id.id))
|
||||
|
||||
def get_current_order(self, cr, uid, context=None):
|
||||
if request.httprequest.session.get('ecommerce_order_id'):
|
||||
order = self._get_order(cr, uid, order_id=request.httprequest.session['ecommerce_order_id'], context=context)
|
||||
if not order:
|
||||
request.httprequest.session['ecommerce_order_id'] = False
|
||||
return order
|
||||
return False
|
||||
|
||||
def _get_transaction(self, cr, uid, tx_id=None, context=None):
|
||||
transaction_obj = self.pool.get('payment.transaction')
|
||||
if tx_id:
|
||||
tx_ids = transaction_obj.search(cr, uid, [('id', '=', tx_id), ('state', 'not in', ['cancel'])], context=context)
|
||||
if tx_ids:
|
||||
return transaction_obj.browse(cr, uid, tx_ids[0], context=context)
|
||||
return False
|
||||
|
||||
def get_current_transaction(self, cr, uid, context=None):
|
||||
if request.httprequest.session.get('website_sale_transaction_id'):
|
||||
tx = self._get_transaction(cr, uid, tx_id=request.httprequest.session['website_sale_transaction_id'], context=context)
|
||||
if not tx:
|
||||
request.httprequest.session['website_sale_transaction_id'] = False
|
||||
return tx
|
||||
return False
|
||||
|
||||
def sale_reset_order(self, cr, uid, context=None):
|
||||
request.httprequest.session.update({
|
||||
'ecommerce_order_id': False,
|
||||
'ecommerce_pricelist': False,
|
||||
'website_sale_transaction_id': False,
|
||||
})
|
||||
request.context.update({
|
||||
'website_sale_order': False,
|
||||
'website_sale_transaction': False,
|
||||
})
|
||||
|
||||
def preprocess_request(self, cr, uid, ids, request, context=None):
|
||||
request.context.update({
|
||||
'website_sale_order': self.get_current_order(cr, uid, context=context),
|
||||
'website_sale_transaction': self.get_current_transaction(cr, uid, context=context)
|
||||
})
|
||||
return super(Website, self).preprocess_request(cr, uid, ids, request, context=None)
|
||||
|
||||
def get_pricelist_id(self, cr, uid, ids, context=None):
|
||||
if not request.httprequest.session.get('ecommerce_pricelist'):
|
||||
self.change_pricelist_id(cr, uid, ids, None, context=context)
|
||||
return request.httprequest.session.get('ecommerce_pricelist')
|
||||
|
||||
def change_pricelist_id(self, cr, uid, ids, code, context=None):
|
||||
request.httprequest.session.setdefault('ecommerce_pricelist', False)
|
||||
|
||||
pricelist_id = False
|
||||
if code:
|
||||
pricelist_obj = self.pool.get('product.pricelist')
|
||||
pricelist_ids = pricelist_obj.search(cr, SUPERUSER_ID, [('code', '=', code)], context=context)
|
||||
if pricelist_ids:
|
||||
pricelist_id = pricelist_ids[0]
|
||||
|
||||
if not pricelist_id:
|
||||
partner_id = self.pool.get('res.users').browse(cr, SUPERUSER_ID, uid, context).partner_id.id
|
||||
pricelist_id = self.pool.get('sale.order').onchange_partner_id(cr, SUPERUSER_ID, [], partner_id, context=context)['value']['pricelist_id']
|
||||
|
||||
request.httprequest.session['ecommerce_pricelist'] = pricelist_id
|
||||
|
||||
order = self.get_current_order(cr, uid, context=context)
|
||||
if order:
|
||||
values = {'pricelist_id': pricelist_id}
|
||||
values.update(order.onchange_pricelist_id(pricelist_id, None)['value'])
|
||||
order.write(values)
|
||||
for line in order.order_line:
|
||||
self.add_product_to_cart(order_line_id=line.id, number=0)
|
||||
|
||||
|
||||
class PaymentTransaction(orm.Model):
|
||||
_inherit = 'payment.transaction'
|
||||
|
|
Loading…
Reference in New Issue