2013-06-28 16:28:04 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2013-10-30 13:30:19 +00:00
|
|
|
import random
|
|
|
|
import uuid
|
|
|
|
import urllib
|
|
|
|
import simplejson
|
|
|
|
|
|
|
|
import werkzeug.exceptions
|
2013-06-28 16:28:04 +00:00
|
|
|
|
2013-08-13 12:43:06 +00:00
|
|
|
from openerp import SUPERUSER_ID
|
2013-08-05 16:16:00 +00:00
|
|
|
from openerp.osv import osv
|
2013-06-28 16:28:04 +00:00
|
|
|
from openerp.addons.web import http
|
|
|
|
from openerp.addons.web.http import request
|
2013-10-01 08:57:39 +00:00
|
|
|
from openerp.addons.website.models import website
|
2013-06-28 16:28:04 +00:00
|
|
|
|
2013-08-05 16:16:00 +00:00
|
|
|
def get_order(order_id=None):
|
|
|
|
order_obj = request.registry.get('sale.order')
|
2013-10-08 15:22:33 +00:00
|
|
|
# check if order allready exists and have access
|
2013-08-05 16:16:00 +00:00
|
|
|
if order_id:
|
|
|
|
try:
|
2013-10-08 15:22:33 +00:00
|
|
|
order = order_obj.browse(request.cr, request.uid, order_id, context=request.context)
|
2013-08-07 14:03:34 +00:00
|
|
|
order.pricelist_id
|
2013-10-08 15:22:33 +00:00
|
|
|
if order:
|
|
|
|
return order
|
2013-08-05 16:16:00 +00:00
|
|
|
except:
|
2013-10-08 15:22:33 +00:00
|
|
|
return False
|
|
|
|
|
|
|
|
fields = [k for k, v in order_obj._columns.items()]
|
|
|
|
order_value = order_obj.default_get(request.cr, SUPERUSER_ID, fields, context=request.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(request.cr, SUPERUSER_ID, request.uid, context=request.context).partner_id.id
|
|
|
|
order_value.update(order_obj.onchange_partner_id(request.cr, SUPERUSER_ID, [], order_value['partner_id'], context=request.context)['value'])
|
2013-10-22 15:16:55 +00:00
|
|
|
|
2013-10-08 15:22:33 +00:00
|
|
|
# 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(request.cr, SUPERUSER_ID, order_value, context=request.context)
|
|
|
|
order = order_obj.browse(request.cr, SUPERUSER_ID, order_id, context=request.context)
|
|
|
|
request.httprequest.session['ecommerce_order_id'] = order.id
|
|
|
|
|
|
|
|
return order_obj.browse(request.cr, request.uid, order_id,
|
2013-09-09 10:00:59 +00:00
|
|
|
context=dict(request.context, pricelist=order.pricelist_id.id))
|
2013-08-05 16:16:00 +00:00
|
|
|
|
|
|
|
def get_current_order():
|
2013-08-23 09:40:17 +00:00
|
|
|
if request.httprequest.session.get('ecommerce_order_id'):
|
2013-10-08 15:22:33 +00:00
|
|
|
order = get_order(request.httprequest.session.get('ecommerce_order_id'))
|
|
|
|
if not order:
|
|
|
|
request.httprequest.session['ecommerce_order_id'] = False
|
|
|
|
return order
|
2013-08-23 09:40:17 +00:00
|
|
|
else:
|
|
|
|
return False
|
2013-08-05 16:16:00 +00:00
|
|
|
|
2013-09-04 15:32:36 +00:00
|
|
|
class Website(osv.osv):
|
2013-08-05 16:16:00 +00:00
|
|
|
_inherit = "website"
|
2013-09-10 13:41:33 +00:00
|
|
|
def preprocess_request(self, cr, uid, ids, *args, **kwargs):
|
|
|
|
request.context.update({
|
2013-09-10 14:15:02 +00:00
|
|
|
'website_sale_order': get_current_order(),
|
2013-09-04 15:32:36 +00:00
|
|
|
})
|
2013-09-10 13:41:33 +00:00
|
|
|
return super(Website, self).preprocess_request(cr, uid, ids, *args, **kwargs)
|
2013-06-28 16:28:04 +00:00
|
|
|
|
|
|
|
class Ecommerce(http.Controller):
|
|
|
|
|
2013-09-26 14:19:35 +00:00
|
|
|
_order = 'website_sequence desc, website_published desc'
|
2013-09-26 11:18:54 +00:00
|
|
|
|
2013-10-15 08:27:26 +00:00
|
|
|
def get_attribute_ids(self):
|
|
|
|
attributes_obj = request.registry.get('product.attribute')
|
|
|
|
attributes_ids = attributes_obj.search(request.cr, request.uid, [(1, "=", 1)], context=request.context)
|
|
|
|
return attributes_obj.browse(request.cr, request.uid, attributes_ids, context=request.context)
|
|
|
|
|
2013-07-24 09:42:18 +00:00
|
|
|
def get_categories(self):
|
2013-09-24 10:28:34 +00:00
|
|
|
domain = [('parent_id', '=', False)]
|
|
|
|
|
2013-08-28 15:16:58 +00:00
|
|
|
category_obj = request.registry.get('product.public.category')
|
2013-09-24 10:28:34 +00:00
|
|
|
category_ids = category_obj.search(request.cr, SUPERUSER_ID, domain, context=request.context)
|
2013-09-04 15:32:36 +00:00
|
|
|
categories = category_obj.browse(request.cr, SUPERUSER_ID, category_ids, context=request.context)
|
2013-09-24 10:28:34 +00:00
|
|
|
|
|
|
|
product_obj = request.registry.get('product.product')
|
|
|
|
groups = product_obj.read_group(request.cr, SUPERUSER_ID, [("sale_ok", "=", True), ('website_published', '=', True)], ['public_categ_id'], 'public_categ_id', context=request.context)
|
|
|
|
full_category_ids = [group['public_categ_id'][0] for group in groups if group['public_categ_id']]
|
2013-09-24 12:19:44 +00:00
|
|
|
|
2013-09-24 10:28:34 +00:00
|
|
|
for cat_id in category_obj.browse(request.cr, SUPERUSER_ID, full_category_ids, context=request.context):
|
|
|
|
while cat_id.parent_id:
|
|
|
|
cat_id = cat_id.parent_id
|
|
|
|
full_category_ids.append(cat_id.id)
|
|
|
|
full_category_ids.append(1)
|
|
|
|
|
|
|
|
return (categories, full_category_ids)
|
2013-08-01 12:48:50 +00:00
|
|
|
|
2013-09-26 07:46:44 +00:00
|
|
|
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
|
2013-09-27 10:31:48 +00:00
|
|
|
The website_size_x, website_size_y is use for fill table (default 1x1)
|
|
|
|
The website_style_ids datas are concatenate in a html class
|
2013-09-26 07:46:44 +00:00
|
|
|
|
|
|
|
@values:
|
|
|
|
|
|
|
|
product_ids: list of product template
|
|
|
|
fill_hole: list of extra product template use to fill the holes
|
|
|
|
col_number: number of columns
|
|
|
|
|
|
|
|
@return:
|
|
|
|
|
|
|
|
table (list of list of #col_number items)
|
|
|
|
items: {
|
|
|
|
'product': browse of product template,
|
|
|
|
'x': size x,
|
|
|
|
'y': size y,
|
|
|
|
'class': html class
|
|
|
|
}
|
|
|
|
"""
|
2013-09-25 18:05:38 +00:00
|
|
|
product_obj = request.registry.get('product.template')
|
2013-09-26 13:09:54 +00:00
|
|
|
style_obj = request.registry.get('website.product.style')
|
2013-09-27 14:46:36 +00:00
|
|
|
request.context['pricelist'] = self.get_pricelist()
|
2013-09-25 18:05:38 +00:00
|
|
|
|
2013-09-26 11:18:54 +00:00
|
|
|
# search for checking of access rules and keep order
|
2013-10-24 11:04:53 +00:00
|
|
|
product_ids = product_obj.search(request.cr, request.uid, [("id", 'in', product_ids)], context=request.context)
|
2013-09-25 18:05:38 +00:00
|
|
|
|
|
|
|
size_ids = {}
|
2013-09-26 13:09:54 +00:00
|
|
|
style_ids = style_obj.search(request.cr, SUPERUSER_ID, [('html_class', 'like', 'size_%')], context=request.context)
|
|
|
|
for style in style_obj.browse(request.cr, SUPERUSER_ID, style_ids, context=request.context):
|
|
|
|
size_ids[style.id] = [int(style.html_class[-3]), int(style.html_class[-1])]
|
2013-09-25 18:05:38 +00:00
|
|
|
|
|
|
|
product_list = []
|
|
|
|
bin_packing = {}
|
|
|
|
bin_packing[0] = {}
|
|
|
|
|
|
|
|
for product in product_obj.browse(request.cr, SUPERUSER_ID, product_ids, context=request.context):
|
|
|
|
index = len(product_list)
|
|
|
|
|
|
|
|
# get size and all html classes
|
2013-09-27 10:31:48 +00:00
|
|
|
x = product.website_size_x or 1
|
|
|
|
y = product.website_size_y or 1
|
|
|
|
html_class = " ".join([str(style_id.html_class) for style_id in product.website_style_ids])
|
|
|
|
|
|
|
|
product_list.append({'product': product, 'x': x, 'y': y, 'class': html_class })
|
2013-09-25 18:05:38 +00:00
|
|
|
|
|
|
|
# bin packing products
|
|
|
|
insert = False
|
|
|
|
line = 0
|
|
|
|
while not insert:
|
|
|
|
# if not full column get next line
|
2013-09-26 07:46:44 +00:00
|
|
|
if len(bin_packing.setdefault(line, {})) >= col_number:
|
2013-09-25 18:05:38 +00:00
|
|
|
line += 1
|
|
|
|
continue
|
|
|
|
|
|
|
|
col = 0
|
2013-09-26 07:46:44 +00:00
|
|
|
while col < col_number:
|
2013-09-25 18:05:38 +00:00
|
|
|
if bin_packing[line].get(col, None) != None:
|
|
|
|
col += 1
|
|
|
|
continue
|
|
|
|
|
|
|
|
insert = True
|
|
|
|
|
2013-09-26 07:46:44 +00:00
|
|
|
# check if the box can be inserted
|
2013-09-25 18:05:38 +00:00
|
|
|
copy_line = line
|
|
|
|
copy_y = y
|
|
|
|
while copy_y > 0:
|
|
|
|
copy_col = col
|
|
|
|
copy_x = x
|
|
|
|
while copy_x > 0:
|
2013-09-26 07:46:44 +00:00
|
|
|
if copy_col >= col_number or bin_packing.setdefault(copy_line, {}).get(copy_col, None) != None:
|
2013-09-25 18:05:38 +00:00
|
|
|
insert = False
|
|
|
|
break
|
|
|
|
copy_col += 1
|
|
|
|
copy_x -= 1
|
|
|
|
if not insert:
|
|
|
|
break
|
|
|
|
copy_line += 1
|
|
|
|
copy_y -= 1
|
|
|
|
|
|
|
|
if not insert:
|
|
|
|
col += 1
|
|
|
|
continue
|
|
|
|
|
2013-09-26 07:46:44 +00:00
|
|
|
# insert the box
|
2013-09-25 18:05:38 +00:00
|
|
|
copy_y = y
|
|
|
|
while copy_y > 0:
|
|
|
|
copy_y -= 1
|
|
|
|
copy_x = x
|
|
|
|
while copy_x > 0:
|
|
|
|
copy_x -= 1
|
|
|
|
bin_packing[line + copy_y][col + copy_x] = False
|
|
|
|
bin_packing[line + copy_y][col + copy_x] = product_list[index]
|
|
|
|
break
|
2013-10-22 15:16:55 +00:00
|
|
|
|
2013-09-25 18:05:38 +00:00
|
|
|
if not insert:
|
|
|
|
line += 1
|
|
|
|
else:
|
|
|
|
break
|
|
|
|
|
|
|
|
length = len(bin_packing)
|
|
|
|
|
2013-09-26 07:46:44 +00:00
|
|
|
# browse product to fill the holes
|
|
|
|
if fill_hole:
|
|
|
|
fill_hole_products = []
|
2013-09-26 11:18:54 +00:00
|
|
|
# search for checking of access rules and keep order
|
|
|
|
fill_hole = [id for id in fill_hole if id in product_obj.search(request.cr, request.uid, [("id", 'in', fill_hole)], context=request.context)]
|
2013-10-02 08:37:50 +00:00
|
|
|
for product in product_obj.browse(request.cr, request.uid, fill_hole, context=request.context):
|
2013-09-26 07:46:44 +00:00
|
|
|
fill_hole_products.append(product)
|
|
|
|
fill_hole_products.reverse()
|
2013-09-25 18:05:38 +00:00
|
|
|
|
2013-09-26 07:46:44 +00:00
|
|
|
# packaging in list (from dict)
|
2013-09-25 18:05:38 +00:00
|
|
|
bin_packing_list = []
|
|
|
|
line = 0
|
|
|
|
while line < length:
|
|
|
|
bin_packing_list.append([])
|
|
|
|
col = 0
|
2013-09-26 07:46:44 +00:00
|
|
|
while col < col_number:
|
|
|
|
if fill_hole and fill_hole_products and bin_packing[line].get(col) == None:
|
2013-09-27 10:31:48 +00:00
|
|
|
bin_packing[line][col] = {'product': fill_hole_products.pop(), 'x': 1, 'y': 1, 'class': "" }
|
2013-09-26 07:46:44 +00:00
|
|
|
bin_packing_list[line].append(bin_packing[line].get(col))
|
2013-09-25 18:05:38 +00:00
|
|
|
col += 1
|
|
|
|
line += 1
|
2013-09-26 07:46:44 +00:00
|
|
|
|
2013-09-25 18:05:38 +00:00
|
|
|
return bin_packing_list
|
|
|
|
|
2013-09-26 07:46:44 +00:00
|
|
|
def get_products(self, product_ids):
|
|
|
|
product_obj = request.registry.get('product.template')
|
2013-09-27 14:46:36 +00:00
|
|
|
request.context['pricelist'] = self.get_pricelist()
|
2013-09-26 11:18:54 +00:00
|
|
|
# search for checking of access rules and keep order
|
|
|
|
product_ids = [id for id in product_ids if id in product_obj.search(request.cr, request.uid, [("id", 'in', product_ids)], context=request.context)]
|
2013-10-02 08:37:50 +00:00
|
|
|
return product_obj.browse(request.cr, request.uid, product_ids, context=request.context)
|
2013-09-26 07:46:44 +00:00
|
|
|
|
2013-11-05 15:09:28 +00:00
|
|
|
def has_search_filter(self, attribute_id, value_id=None):
|
|
|
|
if request.httprequest.args.get('filter'):
|
|
|
|
filter = simplejson.loads(request.httprequest.args['filter'])
|
2013-10-15 08:27:26 +00:00
|
|
|
else:
|
2013-11-05 15:09:28 +00:00
|
|
|
filter = []
|
|
|
|
for key_val in filter:
|
2013-10-15 08:27:26 +00:00
|
|
|
if key_val[0] == attribute_id and (not value_id or value_id in key_val[1:]):
|
|
|
|
return key_val
|
|
|
|
return False
|
|
|
|
|
2013-11-05 15:09:28 +00:00
|
|
|
@website.route(['/shop/filter/'], type='http', auth="public", multilang=True)
|
|
|
|
def filter(self, add_filter="", **post):
|
2013-11-05 15:14:17 +00:00
|
|
|
index = []
|
2013-11-05 15:09:28 +00:00
|
|
|
filter = []
|
|
|
|
if add_filter:
|
|
|
|
filter = simplejson.loads(add_filter)
|
2013-11-05 15:14:17 +00:00
|
|
|
for filt in filter:
|
|
|
|
index.append(filt[0])
|
2013-10-15 08:27:26 +00:00
|
|
|
for key, val in post.items():
|
|
|
|
cat = key.split("-")
|
|
|
|
if len(cat) < 3 or cat[2] in ('max','minmem','maxmem'):
|
|
|
|
continue
|
|
|
|
cat_id = int(cat[1])
|
|
|
|
if cat[2] == 'min':
|
|
|
|
minmem = float(post.pop("att-%s-minmem" % cat[1]))
|
|
|
|
maxmem = float(post.pop("att-%s-maxmem" % cat[1]))
|
|
|
|
_max = int(post.pop("att-%s-max" % cat[1]))
|
|
|
|
_min = int(val)
|
|
|
|
if (minmem != _min or maxmem != _max) and cat_id not in index:
|
2013-11-05 15:09:28 +00:00
|
|
|
filter.append([cat_id , [_min, _max] ])
|
2013-10-15 08:27:26 +00:00
|
|
|
index.append(cat_id)
|
|
|
|
elif cat_id not in index:
|
2013-11-05 15:09:28 +00:00
|
|
|
filter.append([ cat_id, int(cat[2]) ])
|
2013-10-15 08:27:26 +00:00
|
|
|
index.append(cat_id)
|
|
|
|
else:
|
2013-11-05 15:14:17 +00:00
|
|
|
cat[2] = int(cat[2])
|
|
|
|
if cat[2] not in filter[index.index(cat_id)][1:]:
|
|
|
|
filter[index.index(cat_id)].append( cat[2] )
|
2013-10-15 08:27:26 +00:00
|
|
|
post.pop(key)
|
|
|
|
|
2013-11-05 16:17:37 +00:00
|
|
|
return request.redirect("/shop/?filter=%s%s%s%s" % (
|
2013-11-06 17:57:43 +00:00
|
|
|
simplejson.dumps(filter),
|
2013-11-05 15:09:28 +00:00
|
|
|
add_filter and "&add_filter=%s" % add_filter or "",
|
2013-11-05 16:17:37 +00:00
|
|
|
post.get("search") and "&search=%s" % post.get("search") or "",
|
|
|
|
post.get("category") and "&category=%s" % post.get("category") or ""
|
2013-11-05 15:09:28 +00:00
|
|
|
))
|
2013-10-15 08:27:26 +00:00
|
|
|
|
|
|
|
def attributes_to_ids(self, attributes):
|
2013-10-15 09:33:50 +00:00
|
|
|
obj = request.registry.get('product.attribute.product')
|
|
|
|
domain = [(1, '=', 1)]
|
2013-10-15 08:27:26 +00:00
|
|
|
for key_val in attributes:
|
2013-10-15 09:33:50 +00:00
|
|
|
domain += [("attribute_id", "=", key_val[0])]
|
2013-10-15 08:27:26 +00:00
|
|
|
if isinstance(key_val[1], list):
|
2013-10-15 09:33:50 +00:00
|
|
|
domain += [("value", ">=", key_val[1][0]), ("value", "<=", key_val[1][1])]
|
2013-10-15 08:27:26 +00:00
|
|
|
else:
|
2013-10-15 09:33:50 +00:00
|
|
|
domain += [("value_id", "in", key_val[1:])]
|
|
|
|
att_ids = obj.search(request.cr, request.uid, domain, context=request.context)
|
|
|
|
att = obj.read(request.cr, request.uid, att_ids, ["product_id"], context=request.context)
|
|
|
|
return [r["product_id"][0] for r in att]
|
2013-10-15 08:27:26 +00:00
|
|
|
|
|
|
|
@website.route(['/shop/', '/shop/page/<int:page>/'], type='http', auth="public", multilang=True)
|
2013-11-05 15:09:28 +00:00
|
|
|
def category(self, category=0, filter="", page=0, **post):
|
2013-10-24 11:04:53 +00:00
|
|
|
# TDE-NOTE: shouldn't we do somethign about product_template without variants ???
|
|
|
|
# TDE-NOTE: is there a reason to call a method category when the route is
|
|
|
|
# basically a shop without category_id speceified ?
|
2013-08-06 09:23:44 +00:00
|
|
|
|
2013-08-23 09:40:17 +00:00
|
|
|
if 'promo' in post:
|
2013-08-23 14:37:57 +00:00
|
|
|
self.change_pricelist(post.get('promo'))
|
2013-08-20 14:12:03 +00:00
|
|
|
product_obj = request.registry.get('product.template')
|
2013-07-01 16:12:47 +00:00
|
|
|
|
2013-08-02 03:55:04 +00:00
|
|
|
domain = [("sale_ok", "=", True)]
|
2013-08-06 14:18:48 +00:00
|
|
|
|
2013-08-14 10:35:51 +00:00
|
|
|
if post.get("search"):
|
2013-08-14 10:54:00 +00:00
|
|
|
domain += ['|', '|', '|',
|
2013-10-22 15:16:55 +00:00
|
|
|
('name', 'ilike', "%%%s%%" % post.get("search")),
|
2013-08-14 10:35:51 +00:00
|
|
|
('description', 'ilike', "%%%s%%" % post.get("search")),
|
2013-08-23 13:36:04 +00:00
|
|
|
('website_description', 'ilike', "%%%s%%" % post.get("search")),
|
2013-08-28 15:16:58 +00:00
|
|
|
('product_variant_ids.public_categ_id.name', 'ilike', "%%%s%%" % post.get("search"))]
|
2013-07-10 15:03:39 +00:00
|
|
|
|
2013-10-15 08:33:31 +00:00
|
|
|
if category:
|
|
|
|
cat_id = int(category)
|
|
|
|
domain = [('product_variant_ids.public_categ_id.id', 'child_of', cat_id)] + domain
|
|
|
|
|
2013-11-05 15:09:28 +00:00
|
|
|
if filter:
|
|
|
|
filter = simplejson.loads(filter)
|
|
|
|
if filter:
|
|
|
|
ids = self.attributes_to_ids(filter)
|
2013-10-15 08:33:31 +00:00
|
|
|
domain = [('id', 'in', ids or [0] )] + domain
|
2013-10-15 08:27:26 +00:00
|
|
|
|
2013-08-12 13:43:12 +00:00
|
|
|
step = 20
|
2013-09-05 15:18:03 +00:00
|
|
|
product_count = len(product_obj.search(request.cr, request.uid, domain, context=request.context))
|
2013-10-22 15:16:55 +00:00
|
|
|
pager = request.website.pager(url="/shop/", total=product_count, page=page, step=step, scope=7, url_args=post)
|
2013-08-06 09:23:44 +00:00
|
|
|
|
2013-09-05 15:18:03 +00:00
|
|
|
request.context['pricelist'] = self.get_pricelist()
|
2013-09-26 11:18:54 +00:00
|
|
|
|
|
|
|
product_ids = product_obj.search(request.cr, request.uid, domain, limit=step, offset=pager['offset'], order=self._order, context=request.context)
|
|
|
|
fill_hole = product_obj.search(request.cr, request.uid, domain, limit=step, offset=pager['offset']+step, order=self._order, context=request.context)
|
2013-08-19 13:19:29 +00:00
|
|
|
|
2013-09-27 10:31:48 +00:00
|
|
|
styles = []
|
|
|
|
if not request.context['is_public_user']:
|
|
|
|
style_obj = request.registry.get('website.product.style')
|
|
|
|
style_ids = style_obj.search(request.cr, request.uid, [(1, '=', 1)], context=request.context)
|
|
|
|
styles = style_obj.browse(request.cr, request.uid, style_ids, context=request.context)
|
|
|
|
|
2013-09-04 15:32:36 +00:00
|
|
|
values = {
|
2013-10-15 08:27:26 +00:00
|
|
|
'Ecommerce': self,
|
2013-09-26 07:46:44 +00:00
|
|
|
'product_ids': product_ids,
|
|
|
|
'product_ids_for_holes': fill_hole,
|
2013-11-06 17:57:43 +00:00
|
|
|
'search': {
|
|
|
|
'search': post.get('search') or '',
|
|
|
|
'category': category,
|
|
|
|
'filter': filter or '',
|
|
|
|
},
|
2013-08-12 13:43:12 +00:00
|
|
|
'pager': pager,
|
2013-09-27 10:31:48 +00:00
|
|
|
'styles': styles,
|
2013-10-15 08:27:26 +00:00
|
|
|
'style_in_product': lambda style, product: style.id in [s.id for s in product.website_style_ids],
|
2013-09-04 15:32:36 +00:00
|
|
|
}
|
2013-09-10 13:41:33 +00:00
|
|
|
return request.website.render("website_sale.products", values)
|
2013-06-28 16:28:04 +00:00
|
|
|
|
2013-10-02 07:12:39 +00:00
|
|
|
@website.route(['/shop/product/<int:product_id>/'], type='http', auth="public", multilang=True)
|
2013-10-15 08:27:26 +00:00
|
|
|
def product(self, product_id=0, **post):
|
2013-08-23 09:40:17 +00:00
|
|
|
|
|
|
|
if 'promo' in post:
|
2013-08-23 14:37:57 +00:00
|
|
|
self.change_pricelist(post.get('promo'))
|
2013-08-23 09:40:17 +00:00
|
|
|
|
2013-08-20 14:12:03 +00:00
|
|
|
product_obj = request.registry.get('product.template')
|
2013-09-04 08:49:58 +00:00
|
|
|
category_obj = request.registry.get('product.public.category')
|
2013-07-11 14:24:34 +00:00
|
|
|
|
2013-09-05 15:18:03 +00:00
|
|
|
category_ids = category_obj.search(request.cr, request.uid, [(1, '=', 1)], context=request.context)
|
2013-10-02 07:12:39 +00:00
|
|
|
category_list = category_obj.name_get(request.cr, request.uid, category_ids, context=request.context)
|
2013-09-04 08:49:58 +00:00
|
|
|
category_list = sorted(category_list, key=lambda category: category[1])
|
|
|
|
|
2013-09-22 19:33:56 +00:00
|
|
|
category = None
|
2013-11-05 16:25:58 +00:00
|
|
|
if post.get('category') and int(post.get('category')):
|
|
|
|
category = category_obj.browse(request.cr, request.uid, int(post.get('category')), context=request.context)
|
2013-09-22 19:33:56 +00:00
|
|
|
|
2013-10-02 07:12:39 +00:00
|
|
|
request.context['pricelist'] = self.get_pricelist()
|
2013-09-05 15:18:03 +00:00
|
|
|
product = product_obj.browse(request.cr, request.uid, product_id, context=request.context)
|
2013-09-26 13:09:54 +00:00
|
|
|
|
2013-09-04 15:32:36 +00:00
|
|
|
values = {
|
2013-10-15 08:27:26 +00:00
|
|
|
'Ecommerce': self,
|
2013-09-22 19:33:56 +00:00
|
|
|
'category': category,
|
2013-09-04 08:49:58 +00:00
|
|
|
'category_list': category_list,
|
2013-10-10 13:29:07 +00:00
|
|
|
'main_object': product,
|
2013-08-19 13:19:29 +00:00
|
|
|
'product': product,
|
2013-11-06 17:57:43 +00:00
|
|
|
'search': {
|
|
|
|
'search': post.get('search') or '',
|
|
|
|
'category': post.get('category') or '',
|
|
|
|
'filter': post.get('filter') or '',
|
|
|
|
}
|
2013-09-04 15:32:36 +00:00
|
|
|
}
|
2013-09-10 13:41:33 +00:00
|
|
|
return request.website.render("website_sale.product", values)
|
2013-07-01 16:12:47 +00:00
|
|
|
|
2013-10-02 07:12:39 +00:00
|
|
|
@website.route(['/shop/add_product/', '/shop/category/<int:cat_id>/add_product/'], type='http', auth="public", multilang=True)
|
2013-09-10 12:26:46 +00:00
|
|
|
def add_product(self, cat_id=0, **post):
|
2013-10-30 13:30:19 +00:00
|
|
|
if request.httprequest.method != 'POST':
|
|
|
|
return werkzeug.exceptions.MethodNotAllowed(valid_methods=['POST'])
|
|
|
|
|
|
|
|
Product = request.registry.get('product.product')
|
|
|
|
product_id = Product.create(request.cr, request.uid, {
|
|
|
|
'name': 'New Product', 'public_categ_id': cat_id
|
|
|
|
}, context=request.context)
|
|
|
|
product = Product.browse(request.cr, request.uid, product_id, context=request.context)
|
|
|
|
|
|
|
|
return request.redirect("/shop/product/%s/?enable_editor=1" % product.product_tmpl_id.id)
|
2013-09-04 08:49:58 +00:00
|
|
|
|
2013-08-23 14:37:57 +00:00
|
|
|
def get_pricelist(self):
|
|
|
|
if not request.httprequest.session.get('ecommerce_pricelist'):
|
|
|
|
self.change_pricelist(None)
|
|
|
|
return request.httprequest.session.get('ecommerce_pricelist')
|
|
|
|
|
2013-08-23 09:40:17 +00:00
|
|
|
def change_pricelist(self, code):
|
2013-08-23 14:37:57 +00:00
|
|
|
request.httprequest.session.setdefault('ecommerce_pricelist', False)
|
2013-08-23 09:40:17 +00:00
|
|
|
|
2013-08-23 14:37:57 +00:00
|
|
|
pricelist_id = False
|
|
|
|
if code:
|
2013-08-23 09:40:17 +00:00
|
|
|
pricelist_obj = request.registry.get('product.pricelist')
|
2013-09-05 15:18:03 +00:00
|
|
|
pricelist_ids = pricelist_obj.search(request.cr, SUPERUSER_ID, [('code', '=', code)], context=request.context)
|
2013-08-23 09:40:17 +00:00
|
|
|
if pricelist_ids:
|
|
|
|
pricelist_id = pricelist_ids[0]
|
|
|
|
|
2013-08-23 14:37:57 +00:00
|
|
|
if not pricelist_id:
|
2013-09-05 15:18:03 +00:00
|
|
|
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']
|
2013-10-22 15:16:55 +00:00
|
|
|
|
2013-08-23 14:37:57 +00:00
|
|
|
request.httprequest.session['ecommerce_pricelist'] = pricelist_id
|
|
|
|
|
|
|
|
order = get_current_order()
|
|
|
|
if order:
|
2013-08-23 09:40:17 +00:00
|
|
|
values = {'pricelist_id': pricelist_id}
|
|
|
|
values.update(order.onchange_pricelist_id(pricelist_id, None)['value'])
|
|
|
|
order.write(values)
|
|
|
|
for line in order.order_line:
|
2013-09-02 10:46:46 +00:00
|
|
|
self.add_product_to_cart(order_line_id=line.id, number=0)
|
2013-08-23 09:40:17 +00:00
|
|
|
|
2013-09-02 10:46:46 +00:00
|
|
|
def add_product_to_cart(self, product_id=0, order_line_id=0, number=1, set_number=-1):
|
2013-07-01 16:12:47 +00:00
|
|
|
order_line_obj = request.registry.get('sale.order.line')
|
2013-10-08 15:22:33 +00:00
|
|
|
order_obj = request.registry.get('sale.order')
|
2013-07-01 16:12:47 +00:00
|
|
|
|
2013-08-05 16:16:00 +00:00
|
|
|
order = get_current_order()
|
2013-08-23 09:40:17 +00:00
|
|
|
if not order:
|
|
|
|
order = get_order()
|
2013-07-02 12:06:25 +00:00
|
|
|
|
2013-10-02 07:12:39 +00:00
|
|
|
request.context = dict(request.context, pricelist=self.get_pricelist())
|
2013-08-23 14:37:57 +00:00
|
|
|
|
2013-07-02 12:06:25 +00:00
|
|
|
quantity = 0
|
2013-07-01 16:12:47 +00:00
|
|
|
|
|
|
|
# values initialisation
|
2013-08-07 13:45:47 +00:00
|
|
|
values = {}
|
2013-09-02 10:46:46 +00:00
|
|
|
|
|
|
|
domain = [('order_id', '=', order.id)]
|
|
|
|
if order_line_id:
|
|
|
|
domain += [('id', '=', order_line_id)]
|
|
|
|
else:
|
|
|
|
domain += [('product_id', '=', product_id)]
|
|
|
|
|
2013-10-02 07:12:39 +00:00
|
|
|
order_line_ids = order_line_obj.search(request.cr, SUPERUSER_ID, domain, context=request.context)
|
2013-07-01 16:12:47 +00:00
|
|
|
if order_line_ids:
|
2013-10-02 07:12:39 +00:00
|
|
|
order_line = order_line_obj.read(request.cr, SUPERUSER_ID, order_line_ids, [], context=request.context)[0]
|
2013-09-02 10:46:46 +00:00
|
|
|
if not product_id:
|
|
|
|
product_id = order_line['product_id'][0]
|
2013-08-13 10:39:48 +00:00
|
|
|
if set_number >= 0:
|
|
|
|
quantity = set_number
|
|
|
|
else:
|
|
|
|
quantity = order_line['product_uom_qty'] + number
|
2013-08-23 09:40:17 +00:00
|
|
|
if quantity < 0:
|
|
|
|
quantity = 0
|
2013-07-01 16:12:47 +00:00
|
|
|
else:
|
|
|
|
fields = [k for k, v in order_line_obj._columns.items()]
|
2013-10-02 07:12:39 +00:00
|
|
|
values = order_line_obj.default_get(request.cr, SUPERUSER_ID, fields, context=request.context)
|
2013-07-01 16:12:47 +00:00
|
|
|
quantity = 1
|
2013-08-23 09:40:17 +00:00
|
|
|
|
2013-08-30 14:56:24 +00:00
|
|
|
# change and record value
|
2013-10-02 07:12:39 +00:00
|
|
|
vals = order_line_obj._recalculate_product_values(request.cr, request.uid, order_line_ids, product_id, context=request.context)
|
2013-08-30 14:56:24 +00:00
|
|
|
values.update(vals)
|
2013-08-30 14:48:52 +00:00
|
|
|
|
2013-07-01 16:12:47 +00:00
|
|
|
values['product_uom_qty'] = quantity
|
|
|
|
values['product_id'] = product_id
|
2013-07-02 12:06:25 +00:00
|
|
|
values['order_id'] = order.id
|
2013-07-01 16:12:47 +00:00
|
|
|
|
2013-08-23 09:40:17 +00:00
|
|
|
if order_line_ids:
|
2013-10-02 07:12:39 +00:00
|
|
|
order_line_obj.write(request.cr, SUPERUSER_ID, order_line_ids, values, context=request.context)
|
2013-08-23 09:40:17 +00:00
|
|
|
if not quantity:
|
2013-10-02 07:12:39 +00:00
|
|
|
order_line_obj.unlink(request.cr, SUPERUSER_ID, order_line_ids, context=request.context)
|
2013-08-23 09:40:17 +00:00
|
|
|
else:
|
2013-10-02 07:12:39 +00:00
|
|
|
order_line_id = order_line_obj.create(request.cr, SUPERUSER_ID, values, context=request.context)
|
2013-10-08 15:22:33 +00:00
|
|
|
order_obj.write(request.cr, SUPERUSER_ID, [order.id], {'order_line': [(4, order_line_id)]}, context=request.context)
|
2013-11-05 13:27:47 +00:00
|
|
|
return quantity
|
2013-08-08 14:23:41 +00:00
|
|
|
|
2013-09-26 14:54:48 +00:00
|
|
|
@website.route(['/shop/mycart/'], type='http', auth="public", multilang=True)
|
2013-08-23 14:37:57 +00:00
|
|
|
def mycart(self, **post):
|
|
|
|
order = get_current_order()
|
|
|
|
prod_obj = request.registry.get('product.product')
|
|
|
|
|
|
|
|
if 'promo' in post:
|
|
|
|
self.change_pricelist(post.get('promo'))
|
|
|
|
|
|
|
|
suggested_ids = []
|
2013-10-02 16:28:10 +00:00
|
|
|
product_ids = []
|
2013-08-23 14:37:57 +00:00
|
|
|
if order:
|
|
|
|
for line in order.order_line:
|
2013-09-02 10:46:46 +00:00
|
|
|
suggested_ids += [p.id for p in line.product_id and line.product_id.suggested_product_ids or [] for line in order.order_line]
|
2013-10-02 16:28:10 +00:00
|
|
|
product_ids.append(line.product_id.id)
|
|
|
|
suggested_ids = list(set(suggested_ids) - set(product_ids))
|
|
|
|
if suggested_ids:
|
|
|
|
suggested_ids = prod_obj.search(request.cr, request.uid, [('id', 'in', suggested_ids)], context=request.context)
|
2013-09-24 12:19:44 +00:00
|
|
|
|
2013-08-23 14:37:57 +00:00
|
|
|
# select 3 random products
|
|
|
|
suggested_products = []
|
|
|
|
while len(suggested_products) < 3 and suggested_ids:
|
|
|
|
index = random.randrange(0, len(suggested_ids))
|
|
|
|
suggested_products.append(suggested_ids.pop(index))
|
|
|
|
|
2013-09-04 15:32:36 +00:00
|
|
|
values = {
|
2013-09-30 22:51:05 +00:00
|
|
|
'int': int,
|
2013-09-24 10:28:34 +00:00
|
|
|
'get_categories': self.get_categories,
|
2013-09-05 15:18:03 +00:00
|
|
|
'suggested_products': prod_obj.browse(request.cr, request.uid, suggested_products, request.context),
|
2013-09-04 15:32:36 +00:00
|
|
|
}
|
2013-09-10 13:41:33 +00:00
|
|
|
return request.website.render("website_sale.mycart", values)
|
2013-08-23 14:37:57 +00:00
|
|
|
|
2013-09-26 14:54:48 +00:00
|
|
|
@website.route(['/shop/<path:path>/add_cart/', '/shop/add_cart/'], type='http', auth="public", multilang=True)
|
|
|
|
def add_cart(self, path=None, product_id=None, order_line_id=None, remove=None, **kw):
|
2013-10-02 07:12:39 +00:00
|
|
|
self.add_product_to_cart(product_id=product_id and int(product_id), order_line_id=order_line_id and int(order_line_id), number=(remove and -1 or 1))
|
2013-09-26 14:54:48 +00:00
|
|
|
return request.redirect("/shop/mycart/")
|
2013-09-26 14:07:50 +00:00
|
|
|
|
|
|
|
@website.route(['/shop/add_cart_json/'], type='json', auth="public")
|
|
|
|
def add_cart_json(self, product_id=None, order_line_id=None, remove=None):
|
2013-11-05 13:27:47 +00:00
|
|
|
quantity = self.add_product_to_cart(product_id=product_id, order_line_id=order_line_id, number=(remove and -1 or 1))
|
|
|
|
order = get_current_order()
|
|
|
|
return [quantity, order.get_total_quantity(), order.amount_total, request.website.render("website_sale.total", {
|
|
|
|
'website_sale_order': order
|
|
|
|
}).strip()]
|
2013-09-26 14:07:50 +00:00
|
|
|
|
|
|
|
@website.route(['/shop/set_cart_json/'], type='json', auth="public")
|
|
|
|
def set_cart_json(self, path=None, product_id=None, order_line_id=None, set_number=0, json=None):
|
|
|
|
return self.add_product_to_cart(product_id=product_id, order_line_id=order_line_id, set_number=set_number)
|
2013-07-01 16:12:47 +00:00
|
|
|
|
2013-09-26 14:54:48 +00:00
|
|
|
@website.route(['/shop/checkout/'], type='http', auth="public", multilang=True)
|
2013-07-24 09:42:18 +00:00
|
|
|
def checkout(self, **post):
|
2013-09-30 22:51:05 +00:00
|
|
|
classic_fields = ["name", "phone", "email", "street", "city", "state_id", "zip"]
|
2013-09-24 12:42:53 +00:00
|
|
|
rel_fields = ['country_id', 'state_id']
|
|
|
|
|
2013-08-05 16:16:00 +00:00
|
|
|
order = get_current_order()
|
2013-07-24 09:42:18 +00:00
|
|
|
|
2013-09-24 12:42:53 +00:00
|
|
|
if not order or order.state != 'draft' or not order.order_line:
|
2013-07-24 09:42:18 +00:00
|
|
|
return self.mycart(**post)
|
|
|
|
|
2013-07-02 13:29:40 +00:00
|
|
|
partner_obj = request.registry.get('res.partner')
|
2013-07-10 14:29:08 +00:00
|
|
|
user_obj = request.registry.get('res.users')
|
2013-07-23 15:16:07 +00:00
|
|
|
country_obj = request.registry.get('res.country')
|
2013-07-23 15:42:11 +00:00
|
|
|
country_state_obj = request.registry.get('res.country.state')
|
2013-07-02 13:29:40 +00:00
|
|
|
|
2013-09-04 15:32:36 +00:00
|
|
|
values = {
|
2013-08-13 10:39:48 +00:00
|
|
|
'shipping': post.get("shipping"),
|
|
|
|
'error': post.get("error") and dict.fromkeys(post.get("error").split(","), 'error') or {}
|
2013-09-04 15:32:36 +00:00
|
|
|
}
|
2013-08-13 10:39:48 +00:00
|
|
|
|
2013-09-24 12:42:53 +00:00
|
|
|
checkout = dict((field_name, '') for field_name in classic_fields + rel_fields)
|
2013-09-10 13:41:33 +00:00
|
|
|
if not request.context['is_public_user']:
|
2013-09-05 15:18:03 +00:00
|
|
|
partner = user_obj.browse(request.cr, request.uid, request.uid, request.context).partner_id
|
2013-09-24 12:42:53 +00:00
|
|
|
checkout.update(dict((field_name, getattr(partner, field_name)) for field_name in classic_fields if getattr(partner, field_name)))
|
|
|
|
checkout['state_id'] = partner.state_id and partner.state_id.id or ''
|
|
|
|
checkout['country_id'] = partner.country_id and partner.country_id.id or ''
|
2013-08-13 10:39:48 +00:00
|
|
|
checkout['company'] = partner.parent_id and partner.parent_id.name or ''
|
|
|
|
|
2013-09-24 12:42:53 +00:00
|
|
|
shipping_ids = partner_obj.search(request.cr, request.uid, [("parent_id", "=", partner.id), ('type', "=", 'delivery')], context=request.context)
|
2013-07-24 09:42:18 +00:00
|
|
|
if shipping_ids:
|
2013-09-24 12:42:53 +00:00
|
|
|
for k, v in partner_obj.read(request.cr, request.uid, shipping_ids[0], request.context).items():
|
2013-08-13 10:39:48 +00:00
|
|
|
checkout['shipping_'+k] = v or ''
|
|
|
|
|
|
|
|
values['checkout'] = checkout
|
2013-09-05 15:18:03 +00:00
|
|
|
countries_ids = country_obj.search(request.cr, SUPERUSER_ID, [(1, "=", 1)], context=request.context)
|
|
|
|
values['countries'] = country_obj.browse(request.cr, SUPERUSER_ID, countries_ids, request.context)
|
|
|
|
states_ids = country_state_obj.search(request.cr, SUPERUSER_ID, [(1, "=", 1)], context=request.context)
|
|
|
|
values['states'] = country_state_obj.browse(request.cr, SUPERUSER_ID, states_ids, request.context)
|
2013-07-23 15:16:07 +00:00
|
|
|
|
2013-09-10 13:41:33 +00:00
|
|
|
return request.website.render("website_sale.checkout", values)
|
2013-07-02 13:29:40 +00:00
|
|
|
|
2013-09-26 14:54:48 +00:00
|
|
|
@website.route(['/shop/confirm_order/'], type='http', auth="public", multilang=True)
|
2013-07-24 09:42:18 +00:00
|
|
|
def confirm_order(self, **post):
|
2013-08-05 16:16:00 +00:00
|
|
|
order = get_current_order()
|
|
|
|
|
2013-08-08 14:23:41 +00:00
|
|
|
error = []
|
2013-07-02 13:29:40 +00:00
|
|
|
partner_obj = request.registry.get('res.partner')
|
2013-08-01 12:48:50 +00:00
|
|
|
user_obj = request.registry.get('res.users')
|
2013-07-23 13:39:23 +00:00
|
|
|
|
2013-08-01 12:48:50 +00:00
|
|
|
if order.state != 'draft':
|
2013-09-26 14:54:48 +00:00
|
|
|
return request.redirect("/shop/checkout/")
|
2013-08-01 12:48:50 +00:00
|
|
|
if not order.order_line:
|
2013-08-08 14:23:41 +00:00
|
|
|
error.append("empty_cart")
|
2013-09-26 14:54:48 +00:00
|
|
|
return request.redirect("/shop/checkout/")
|
2013-07-24 09:42:18 +00:00
|
|
|
|
2013-07-23 13:39:23 +00:00
|
|
|
# check values
|
2013-08-08 14:23:41 +00:00
|
|
|
request.session['checkout'] = post
|
2013-07-23 15:16:07 +00:00
|
|
|
required_field = ['phone', 'zip', 'email', 'street', 'city', 'name', 'country_id']
|
2013-07-23 13:39:23 +00:00
|
|
|
for key in required_field:
|
2013-07-23 15:16:07 +00:00
|
|
|
if not post.get(key):
|
2013-08-08 14:23:41 +00:00
|
|
|
error.append(key)
|
|
|
|
if post.get('shipping_different') and key != 'email' and not post.get("shipping_%s" % key):
|
|
|
|
error.append("shipping_%s" % key)
|
|
|
|
if error:
|
2013-09-26 14:54:48 +00:00
|
|
|
return request.redirect("/shop/checkout/?error=%s&shipping=%s" % (",".join(error), post.get('shipping_different') and 'on' or ''))
|
2013-07-23 13:39:23 +00:00
|
|
|
|
|
|
|
# search or create company
|
2013-07-23 15:42:11 +00:00
|
|
|
company_id = None
|
2013-07-23 13:39:23 +00:00
|
|
|
if post['company']:
|
2013-09-05 15:18:03 +00:00
|
|
|
company_ids = partner_obj.search(request.cr, SUPERUSER_ID, [("name", "ilike", post['company']), ('is_company', '=', True)], context=request.context)
|
2013-07-23 15:42:11 +00:00
|
|
|
company_id = company_ids and company_ids[0] or None
|
|
|
|
if not company_id:
|
2013-09-05 15:18:03 +00:00
|
|
|
company_id = partner_obj.create(request.cr, SUPERUSER_ID, {'name': post['company'], 'is_company': True}, request.context)
|
2013-07-23 13:39:23 +00:00
|
|
|
|
|
|
|
partner_value = {
|
2013-07-23 15:16:07 +00:00
|
|
|
'phone': post['phone'],
|
2013-07-23 13:39:23 +00:00
|
|
|
'zip': post['zip'],
|
|
|
|
'email': post['email'],
|
|
|
|
'street': post['street'],
|
|
|
|
'city': post['city'],
|
|
|
|
'name': post['name'],
|
2013-07-23 15:42:11 +00:00
|
|
|
'parent_id': company_id,
|
2013-07-23 15:16:07 +00:00
|
|
|
'country_id': post['country_id'],
|
2013-07-23 15:42:11 +00:00
|
|
|
'state_id': post['state_id'],
|
2013-07-23 13:39:23 +00:00
|
|
|
}
|
2013-09-10 13:41:33 +00:00
|
|
|
if not request.context['is_public_user']:
|
2013-10-08 15:22:33 +00:00
|
|
|
partner_id = user_obj.browse(request.cr, request.uid, request.uid, context=request.context).partner_id.id
|
|
|
|
partner_obj.write(request.cr, request.uid, [partner_id], partner_value, context=request.context)
|
2013-07-23 13:39:23 +00:00
|
|
|
else:
|
2013-10-08 15:22:33 +00:00
|
|
|
partner_id = partner_obj.create(request.cr, SUPERUSER_ID, partner_value, context=request.context)
|
|
|
|
|
2013-07-23 13:39:23 +00:00
|
|
|
|
2013-07-23 16:13:19 +00:00
|
|
|
shipping_id = None
|
2013-09-05 09:59:33 +00:00
|
|
|
if post.get('shipping_different'):
|
2013-07-23 13:39:23 +00:00
|
|
|
shipping_value = {
|
2013-07-23 15:16:07 +00:00
|
|
|
'phone': post['shipping_phone'],
|
2013-07-23 13:39:23 +00:00
|
|
|
'zip': post['shipping_zip'],
|
|
|
|
'street': post['shipping_street'],
|
|
|
|
'city': post['shipping_city'],
|
|
|
|
'name': post['shipping_name'],
|
2013-07-23 16:13:19 +00:00
|
|
|
'type': 'delivery',
|
|
|
|
'parent_id': partner_id,
|
2013-07-23 15:16:07 +00:00
|
|
|
'country_id': post['shipping_country_id'],
|
2013-07-23 15:42:11 +00:00
|
|
|
'state_id': post['shipping_state_id'],
|
2013-07-23 13:39:23 +00:00
|
|
|
}
|
2013-09-05 09:59:33 +00:00
|
|
|
domain = [(key, '_id' in key and '=' or 'ilike', '_id' in key and value and int(value) or False)
|
2013-07-24 09:42:18 +00:00
|
|
|
for key, value in shipping_value.items() if key in required_field + ["type", "parent_id"]]
|
2013-09-05 09:59:33 +00:00
|
|
|
|
2013-09-05 15:18:03 +00:00
|
|
|
shipping_ids = partner_obj.search(request.cr, SUPERUSER_ID, domain, context=request.context)
|
2013-07-24 09:42:18 +00:00
|
|
|
if shipping_ids:
|
|
|
|
shipping_id = shipping_ids[0]
|
2013-09-05 15:18:03 +00:00
|
|
|
partner_obj.write(request.cr, SUPERUSER_ID, [shipping_id], shipping_value, request.context)
|
2013-07-24 09:42:18 +00:00
|
|
|
else:
|
2013-09-05 15:18:03 +00:00
|
|
|
shipping_id = partner_obj.create(request.cr, SUPERUSER_ID, shipping_value, request.context)
|
2013-07-02 12:06:25 +00:00
|
|
|
|
2013-07-24 09:42:18 +00:00
|
|
|
order_value = {
|
2013-07-23 16:13:19 +00:00
|
|
|
'partner_id': partner_id,
|
2013-10-08 15:22:33 +00:00
|
|
|
'message_follower_ids': [(4, partner_id)],
|
2013-07-23 16:13:19 +00:00
|
|
|
'partner_invoice_id': partner_id,
|
|
|
|
'partner_shipping_id': shipping_id or partner_id
|
2013-07-24 09:42:18 +00:00
|
|
|
}
|
2013-09-05 15:18:03 +00:00
|
|
|
order_value.update(request.registry.get('sale.order').onchange_partner_id(request.cr, SUPERUSER_ID, [], order.partner_id.id, context=request.context)['value'])
|
2013-08-01 12:48:50 +00:00
|
|
|
order.write(order_value)
|
2013-07-23 16:13:19 +00:00
|
|
|
|
2013-09-26 14:54:48 +00:00
|
|
|
return request.redirect("/shop/payment/")
|
2013-07-24 09:42:18 +00:00
|
|
|
|
2013-09-26 14:54:48 +00:00
|
|
|
@website.route(['/shop/payment/'], type='http', auth="public", multilang=True)
|
2013-08-08 14:23:41 +00:00
|
|
|
def payment(self, **post):
|
2013-08-23 09:40:17 +00:00
|
|
|
order = get_current_order()
|
2013-07-24 09:42:18 +00:00
|
|
|
|
2013-08-23 09:40:17 +00:00
|
|
|
if not order or not order.order_line:
|
2013-07-24 09:42:18 +00:00
|
|
|
return self.mycart(**post)
|
|
|
|
|
2013-09-04 15:32:36 +00:00
|
|
|
values = {
|
2013-08-08 14:23:41 +00:00
|
|
|
'partner': False,
|
|
|
|
'order': order
|
2013-09-04 15:32:36 +00:00
|
|
|
}
|
2013-07-24 09:42:18 +00:00
|
|
|
|
2013-08-08 14:23:41 +00:00
|
|
|
payment_obj = request.registry.get('portal.payment.acquirer')
|
2013-09-05 15:18:03 +00:00
|
|
|
payment_ids = payment_obj.search(request.cr, SUPERUSER_ID, [('visible', '=', True)], context=request.context)
|
|
|
|
values['payments'] = payment_obj.browse(request.cr, SUPERUSER_ID, payment_ids, request.context)
|
2013-08-08 14:23:41 +00:00
|
|
|
for payment in values['payments']:
|
2013-08-13 12:43:06 +00:00
|
|
|
content = payment_obj.render(request.cr, SUPERUSER_ID, payment.id, order, order.name, order.pricelist_id.currency_id, order.amount_total)
|
2013-08-08 14:23:41 +00:00
|
|
|
payment._content = content
|
|
|
|
|
2013-09-10 13:41:33 +00:00
|
|
|
return request.website.render("website_sale.payment", values)
|
2013-08-08 14:23:41 +00:00
|
|
|
|
2013-09-26 14:54:48 +00:00
|
|
|
@website.route(['/shop/payment_validate/'], type='http', auth="public", multilang=True)
|
2013-08-23 09:40:17 +00:00
|
|
|
def payment_validate(self, **post):
|
|
|
|
request.httprequest.session['ecommerce_order_id'] = False
|
2013-08-23 14:37:57 +00:00
|
|
|
request.httprequest.session['ecommerce_pricelist'] = False
|
2013-09-26 14:54:48 +00:00
|
|
|
return request.redirect("/shop/")
|
2013-08-23 09:40:17 +00:00
|
|
|
|
2013-09-26 11:18:54 +00:00
|
|
|
@website.route(['/shop/change_sequence/'], type='json', auth="public")
|
|
|
|
def change_sequence(self, id, top):
|
|
|
|
product_obj = request.registry.get('product.template')
|
|
|
|
if top:
|
2013-10-02 07:12:39 +00:00
|
|
|
product_obj.set_sequence_top(request.cr, request.uid, [id], context=request.context)
|
2013-09-26 11:18:54 +00:00
|
|
|
else:
|
2013-10-02 07:12:39 +00:00
|
|
|
product_obj.set_sequence_bottom(request.cr, request.uid, [id], context=request.context)
|
2013-09-26 11:18:54 +00:00
|
|
|
|
2013-09-26 13:09:54 +00:00
|
|
|
@website.route(['/shop/change_styles/'], type='json', auth="public")
|
|
|
|
def change_styles(self, id, style_id):
|
2013-09-27 10:31:48 +00:00
|
|
|
product_obj = request.registry.get('product.template')
|
2013-10-02 07:12:39 +00:00
|
|
|
product = product_obj.browse(request.cr, request.uid, id, context=request.context)
|
2013-09-26 13:09:54 +00:00
|
|
|
|
|
|
|
remove = []
|
|
|
|
active = False
|
|
|
|
for style in product.website_style_ids:
|
|
|
|
if style.id == style_id:
|
|
|
|
remove.append(style.id)
|
|
|
|
active = True
|
|
|
|
break
|
|
|
|
|
2013-10-02 07:12:39 +00:00
|
|
|
style = request.registry.get('website.product.style').browse(request.cr, request.uid, style_id, context=request.context)
|
2013-09-26 13:09:54 +00:00
|
|
|
|
|
|
|
if remove:
|
|
|
|
product.write({'website_style_ids': [(3, rid) for rid in remove]})
|
|
|
|
if not active:
|
|
|
|
product.write({'website_style_ids': [(4, style.id)]})
|
|
|
|
|
|
|
|
return not active
|
|
|
|
|
2013-09-27 10:31:48 +00:00
|
|
|
@website.route(['/shop/change_size/'], type='json', auth="public")
|
|
|
|
def change_size(self, id, x, y):
|
|
|
|
product_obj = request.registry.get('product.template')
|
2013-10-02 07:12:39 +00:00
|
|
|
product = product_obj.browse(request.cr, request.uid, id, context=request.context)
|
2013-09-27 10:31:48 +00:00
|
|
|
return product.write({'website_size_x': x, 'website_size_y': y})
|
2013-09-26 11:18:54 +00:00
|
|
|
|
2013-06-28 16:28:04 +00:00
|
|
|
# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4:
|