diff --git a/addons/membership/membership_view.xml b/addons/membership/membership_view.xml
index 24693845e1c..c70c8cd6cc0 100644
--- a/addons/membership/membership_view.xml
+++ b/addons/membership/membership_view.xml
@@ -9,9 +9,10 @@
membership.product.search.form
product.template
+ 50
-
+
diff --git a/addons/product/product.py b/addons/product/product.py
index 6fa0627db2c..d90165ae022 100644
--- a/addons/product/product.py
+++ b/addons/product/product.py
@@ -816,10 +816,8 @@ class product_product(osv.osv):
uom.id, product.list_price, context['uom'])
else:
res[product.id] = product.list_price
- price_extra = 0.0
- for variant_id in product.attribute_value_ids:
- price_extra += variant_id.price_extra
- res[product.id] = (res[product.id] or 0.0) + price_extra
+ res[product.id] = res[product.id] + product.price_extra
+
return res
def _get_partner_code_name(self, cr, uid, ids, product, partner_id, context=None):
diff --git a/addons/product/product_view.xml b/addons/product/product_view.xml
index 6f29d3a188d..963bdd0eea0 100644
--- a/addons/product/product_view.xml
+++ b/addons/product/product_view.xml
@@ -283,15 +283,30 @@
Product Kanban
product.product
- primary
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
@@ -343,7 +358,7 @@
@@ -361,7 +376,7 @@
diff --git a/addons/report_intrastat/report_intrastat_view.xml b/addons/report_intrastat/report_intrastat_view.xml
index 574234b1eac..f1147d7f28c 100644
--- a/addons/report_intrastat/report_intrastat_view.xml
+++ b/addons/report_intrastat/report_intrastat_view.xml
@@ -25,14 +25,13 @@
-
- product.normal.form
- product.product
-
+
+ product.template.form
+ product.template
+
-
+
diff --git a/addons/website/models/ir_http.py b/addons/website/models/ir_http.py
index 7c7ad354cdc..4d42c9d0643 100644
--- a/addons/website/models/ir_http.py
+++ b/addons/website/models/ir_http.py
@@ -62,7 +62,7 @@ class ir_http(orm.AbstractModel):
self.geo_ip_resolver = GeoIP.open('/usr/share/GeoIP/GeoIP.dat', GeoIP.GEOIP_STANDARD)
except ImportError:
self.geo_ip_resolver = False
- if self.geo_ip_resolver:
+ if self.geo_ip_resolver and request.httprequest.remote_addr:
record = self.geo_ip_resolver.record_by_addr(request.httprequest.remote_addr) or {}
request.session['geoip'] = record
diff --git a/addons/website/static/src/js/website.editor.js b/addons/website/static/src/js/website.editor.js
index 8cd78377a90..b99d399a7a6 100644
--- a/addons/website/static/src/js/website.editor.js
+++ b/addons/website/static/src/js/website.editor.js
@@ -452,7 +452,6 @@
openerp.jsonRpc('/website/customize_template_get', 'call', { 'xml_id': view_name }).then(
function(result) {
_.each(result, function (item) {
- if (item.xml_id === "website.debugger" && !window.location.search.match(/[&?]debug(&|$)/)) return;
if (item.header) {
menu.append('');
} else {
diff --git a/addons/website/views/website_templates.xml b/addons/website/views/website_templates.xml
index 92483061e10..97edc1713df 100644
--- a/addons/website/views/website_templates.xml
+++ b/addons/website/views/website_templates.xml
@@ -251,12 +251,6 @@
-
-
-
-
-
-
diff --git a/addons/website_event/views/website_event.xml b/addons/website_event/views/website_event.xml
index 774d38381fb..37dab768ccc 100644
--- a/addons/website_event/views/website_event.xml
+++ b/addons/website_event/views/website_event.xml
@@ -8,7 +8,7 @@
-
+
diff --git a/addons/website_event_sale/models/sale_order.py b/addons/website_event_sale/models/sale_order.py
index 91f282a1c00..4c1a83681ea 100644
--- a/addons/website_event_sale/models/sale_order.py
+++ b/addons/website_event_sale/models/sale_order.py
@@ -7,21 +7,18 @@ from openerp.tools.translate import _
class sale_order(osv.Model):
_inherit = "sale.order"
- def _cart_find_product_line(self, cr, uid, ids, product_id=None, line_id=None, context=None):
+ def _cart_find_product_line(self, cr, uid, ids, product_id=None, line_id=None, context=None, **kwargs):
+ line_ids = super(sale_order, self)._cart_find_product_line(cr, uid, ids, product_id, line_id, context=context)
+ if line_id:
+ return line_ids
for so in self.browse(cr, uid, ids, context=context):
- order_line_id = None
- domain = [('order_id', '=', so.id), ('product_id', '=', product_id)]
- if line_id:
- domain += [('id', '=', line_id)]
- elif context.get("event_ticket_id"):
+ domain = [('id', 'in', line_ids)]
+ if context.get("event_ticket_id"):
domain += [('event_ticket_id', '=', context.get("event_ticket_id"))]
- order_line_ids = self.pool.get('sale.order.line').search(cr, SUPERUSER_ID, domain, context=context)
- if order_line_ids:
- order_line_id = order_line_ids[0]
- return order_line_id
+ return self.pool.get('sale.order.line').search(cr, SUPERUSER_ID, domain, context=context)
def _website_product_id_change(self, cr, uid, ids, order_id, product_id, line_id=None, context=None):
- values = super(sale_order,self)._website_product_id_change(cr, uid, ids, order_id, product_id, line_id=None, context=None)
+ values = super(sale_order,self)._website_product_id_change(cr, uid, ids, order_id, product_id, line_id=line_id, context=None)
event_ticket_id = None
if context.get("event_ticket_id"):
diff --git a/addons/website_event_sale/tests/test_ui.py b/addons/website_event_sale/tests/test_ui.py
index 94869251fad..28195e6495f 100644
--- a/addons/website_event_sale/tests/test_ui.py
+++ b/addons/website_event_sale/tests/test_ui.py
@@ -4,7 +4,6 @@ import openerp.tests
inject = [
("openerp.Tour", os.path.join(os.path.dirname(__file__), '../../web/static/src/js/tour.js')),
- ("openerp.Tour.ShopTest", os.path.join(os.path.dirname(__file__), "../static/src/js/website.tour.event_sale.js")),
]
@openerp.tests.common.at_install(False)
diff --git a/addons/website_event_sale/views/website_event_sale.xml b/addons/website_event_sale/views/website_event_sale.xml
index cf46797b34d..c34ff045731 100644
--- a/addons/website_event_sale/views/website_event_sale.xml
+++ b/addons/website_event_sale/views/website_event_sale.xml
@@ -2,13 +2,12 @@
-
-
-
-
+
+
+
+
-
diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py
index a6bcd15f9e5..f187e6799ac 100644
--- a/addons/website_sale/controllers/main.py
+++ b/addons/website_sale/controllers/main.py
@@ -110,6 +110,21 @@ class website_sale(http.Controller):
pricelist = partner.property_product_pricelist
return pricelist
+ def get_attribute_value_ids(self, product):
+ cr, uid, context, pool = request.cr, request.uid, request.context, request.registry
+ currency_obj = pool['res.currency']
+ attribute_value_ids = []
+ if request.website.pricelist_id.id != context['pricelist']:
+ website_currency_id = request.website.currency_id.id
+ currency_id = self.get_pricelist().currency_id.id
+ for p in product.product_variant_ids:
+ price = currency_obj.compute(cr, uid, website_currency_id, currency_id, p.lst_price)
+ attribute_value_ids.append([p.id, map(int, p.attribute_value_ids), p.price, price])
+ else:
+ attribute_value_ids = [[p.id, map(int, p.attribute_value_ids), p.price, p.lst_price] for p in product.product_variant_ids]
+
+ return attribute_value_ids
+
@http.route(['/shop',
'/shop/page/',
'/shop/category/',
@@ -125,7 +140,10 @@ class website_sale(http.Controller):
if category:
domain += [('product_variant_ids.public_categ_ids', 'child_of', int(category))]
- attrib_values = [map(int,v.split(",")) for v in request.httprequest.args.getlist('attrib') if v]
+ attrib_list = request.httprequest.args.getlist('attrib')
+ attrib_values = [map(int,v.split("-")) for v in attrib_list if v]
+ attrib_set = set([v[1] for v in attrib_values])
+
if attrib_values:
attrib = None
ids = []
@@ -142,8 +160,7 @@ class website_sale(http.Controller):
if attrib:
domain += [('attribute_line_ids.value_ids', 'in', ids)]
- attrib_set = set([v[1] for v in attrib_values])
- keep = QueryURL('/shop', category=category and int(category), search=search, attrib=attrib_set)
+ keep = QueryURL('/shop', category=category and int(category), search=search, attrib=attrib_list)
if not context.get('pricelist'):
context['pricelist'] = int(self.get_pricelist())
@@ -191,16 +208,18 @@ class website_sale(http.Controller):
def product(self, product, category='', search='', **kwargs):
cr, uid, context, pool = request.cr, request.uid, request.context, request.registry
category_obj = pool['product.public.category']
+ template_obj = pool['product.template']
context.update(active_id=product.id)
if category:
- category = category_obj.browse(request.cr, request.uid, int(category), context=request.context)
+ category = category_obj.browse(cr, uid, int(category), context=context)
- attrib_values = [map(int,v.split(",")) for v in request.httprequest.args.getlist('attrib') if v]
+ attrib_list = request.httprequest.args.getlist('attrib')
+ attrib_values = [map(int,v.split("-")) for v in attrib_list if v]
attrib_set = set([v[1] for v in attrib_values])
- keep = QueryURL('/shop', category=category and category.id, search=search, attrib=attrib_set)
+ keep = QueryURL('/shop', category=category and category.id, search=search, attrib=attrib_list)
category_ids = category_obj.search(cr, uid, [], context=context)
category_list = category_obj.name_get(cr, uid, category_ids, context=context)
@@ -208,9 +227,7 @@ class website_sale(http.Controller):
if not context.get('pricelist'):
context['pricelist'] = int(self.get_pricelist())
- product = request.registry.get('product.template').browse(request.cr, request.uid, int(product), context=context)
-
- variants = [[p.id, map(int, p.attribute_value_ids), p.price] for p in product.product_variant_ids]
+ product = template_obj.browse(cr, uid, int(product), context=context)
values = {
'search': search,
@@ -222,7 +239,7 @@ class website_sale(http.Controller):
'category_list': category_list,
'main_object': product,
'product': product,
- 'variants': variants,
+ 'get_attribute_value_ids': self.get_attribute_value_ids
}
return request.website.render("website_sale.product", values)
@@ -238,36 +255,45 @@ class website_sale(http.Controller):
context=dict(context, mail_create_nosubcribe=True))
return werkzeug.utils.redirect(request.httprequest.referrer + "#comments")
+ @http.route(['/shop/pricelist'], type='http', auth="public", website=True)
+ def pricelist(self, promo, **post):
+ cr, uid, context = request.cr, request.uid, request.context
+ request.website.sale_get_order(code=promo, context=context)
+ return request.redirect("/shop/cart")
+
@http.route(['/shop/cart'], type='http', auth="public", website=True)
def cart(self, **post):
+ cr, uid, context, pool = request.cr, request.uid, request.context, request.registry
order = request.website.sale_get_order()
+
values = {
'order': order,
'suggested_products': [],
}
if order:
- if not request.context.get('pricelist'):
- request.context['pricelist'] = order.pricelist_id.id
- values['suggested_products'] = order._cart_accessories(context=request.context)
+ if not context.get('pricelist'):
+ context['pricelist'] = order.pricelist_id.id
+ values['suggested_products'] = order._cart_accessories(context=context)
+
return request.website.render("website_sale.cart", values)
@http.route(['/shop/cart/update'], type='http', auth="public", methods=['POST'], website=True)
def cart_update(self, product_id, add_qty=1, set_qty=0, **kw):
cr, uid, context = request.cr, request.uid, request.context
- request.website.sale_get_order(force_create=1)._cart_update(product_id=int(product_id), add_qty=add_qty, set_qty=set_qty)
+ request.website.sale_get_order(force_create=1)._cart_update(product_id=int(product_id), add_qty=float(add_qty), set_qty=float(set_qty))
return request.redirect("/shop/cart")
@http.route(['/shop/cart/update_json'], type='json', auth="public", methods=['POST'], website=True)
- def cart_update_json(self, product_id, line_id, add_qty=None, set_qty=None):
+ def cart_update_json(self, product_id, line_id, add_qty=None, set_qty=None, display=True):
order = request.website.sale_get_order(force_create=1)
- quantity = order._cart_update(product_id=product_id, line_id=line_id, add_qty=add_qty, set_qty=set_qty)
- return {
- 'quantity': quantity,
- 'cart_quantity': order.cart_quantity,
- 'website_sale.total': request.website._render("website_sale.total", {
- 'website_sale_order': request.website.sale_get_order()
- })
- }
+ value = order._cart_update(product_id=product_id, line_id=line_id, add_qty=add_qty, set_qty=set_qty)
+ if not display:
+ return None
+ value['cart_quantity'] = order.cart_quantity
+ value['website_sale.total'] = request.website._render("website_sale.total", {
+ 'website_sale_order': request.website.sale_get_order()
+ })
+ return value
#------------------------------------------------------
# Checkout
@@ -323,12 +349,20 @@ class website_sale(http.Controller):
checkout.update(self.checkout_parse('shipping', data))
checkout["shipping_different"] = True
+ # Default search by user country
+ country_code = request.session['geoip'].get('country_code')
+ if country_code:
+ country_ids = request.registry.get('res.country').search(cr, uid, [('code', '=', country_code)], context=context)
+ if country_ids:
+ checkout['country_id'] = country_ids[0]
+
values = {
'countries': countries,
'states': states,
'checkout': checkout,
'shipping_different': checkout.get('shipping_different'),
'error': {},
+ 'has_check_vat': hasattr(registry['res.partner'], 'check_vat')
}
return values
@@ -445,7 +479,7 @@ class website_sale(http.Controller):
@http.route(['/shop/checkout'], type='http', auth="public", website=True)
def checkout(self, **post):
- cr, uid, context, registry = request.cr, request.uid, request.context, request.registry
+ cr, uid, context = request.cr, request.uid, request.context
order = request.website.sale_get_order(force_create=1, context=context)
diff --git a/addons/website_sale/data/demo.xml b/addons/website_sale/data/demo.xml
index a4380c3d7dd..952497bd547 100644
--- a/addons/website_sale/data/demo.xml
+++ b/addons/website_sale/data/demo.xml
@@ -555,8 +555,6 @@ Weight: 1.1 ounces
-
-
diff --git a/addons/website_sale/models/product.py b/addons/website_sale/models/product.py
index 116822f2984..ce206372047 100644
--- a/addons/website_sale/models/product.py
+++ b/addons/website_sale/models/product.py
@@ -201,7 +201,7 @@ class product_product(osv.Model):
class product_attribute(osv.Model):
_inherit = "product.attribute"
_columns = {
- 'type': fields.selection([('radio', 'Radio'), ('select', 'Select'), ('color', 'Color')], string="Type", type="char"),
+ 'type': fields.selection([('radio', 'Radio'), ('select', 'Select'), ('color', 'Color'), ('hidden', 'Hidden')], string="Type", type="char"),
}
_defaults = {
'type': lambda *a: 'radio',
@@ -210,5 +210,5 @@ class product_attribute(osv.Model):
class product_attribute_value(osv.Model):
_inherit = "product.attribute.value"
_columns = {
- 'color': fields.char("Color for Color Attributes"),
+ 'color': fields.char("HTML Color Index", help="Here you can set a specific HTML color index (e.g. #ff0000) to display the color on the website if the attibute type is 'Color'."),
}
diff --git a/addons/website_sale/models/sale_order.py b/addons/website_sale/models/sale_order.py
index d9855034018..165030f9f1a 100644
--- a/addons/website_sale/models/sale_order.py
+++ b/addons/website_sale/models/sale_order.py
@@ -43,16 +43,12 @@ class sale_order(osv.Model):
'order': order
}
- def _cart_find_product_line(self, cr, uid, ids, product_id=None, line_id=None, context=None):
+ def _cart_find_product_line(self, cr, uid, ids, product_id=None, line_id=None, context=None, **kwargs):
for so in self.browse(cr, uid, ids, context=context):
- order_line_id = None
domain = [('order_id', '=', so.id), ('product_id', '=', product_id)]
if line_id:
domain += [('id', '=', line_id)]
- order_line_ids = self.pool.get('sale.order.line').search(cr, SUPERUSER_ID, domain, context=context)
- if order_line_ids:
- order_line_id = order_line_ids[0]
- return order_line_id
+ return self.pool.get('sale.order.line').search(cr, SUPERUSER_ID, domain, context=context)
def _website_product_id_change(self, cr, uid, ids, order_id, product_id, line_id=None, context=None):
so = self.pool.get('sale.order').browse(cr, uid, order_id, context=context)
@@ -69,7 +65,7 @@ class sale_order(osv.Model):
values['name'] = line.name
else:
product = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
- values['name'] = product.name_get()[0][1]
+ values['name'] = product.description_sale or product.name
values['product_id'] = product_id
values['order_id'] = order_id
@@ -77,13 +73,16 @@ class sale_order(osv.Model):
values['tax_id'] = [(6, 0, values['tax_id'])]
return values
- def _cart_update(self, cr, uid, ids, product_id=None, line_id=None, add_qty=0, set_qty=0, context=None):
+ def _cart_update(self, cr, uid, ids, product_id=None, line_id=None, add_qty=0, set_qty=0, context=None, **kwargs):
""" Add or set product quantity, add_qty can be negative """
sol = self.pool.get('sale.order.line')
quantity = 0
for so in self.browse(cr, uid, ids, context=context):
- line_id = so._cart_find_product_line(product_id, line_id, context=context)
+ if line_id != False:
+ line_ids = so._cart_find_product_line(product_id, line_id, context=context, **kwargs)
+ if line_ids:
+ line_id = line_ids[0]
# Create line if no line with product_id can be located
if not line_id:
@@ -107,7 +106,7 @@ class sale_order(osv.Model):
values['product_uom_qty'] = quantity
sol.write(cr, SUPERUSER_ID, [line_id], values, context=context)
- return quantity
+ return {'line_id': line_id, 'quantity': quantity}
def _cart_accessories(self, cr, uid, ids, context=None):
for order in self.browse(cr, uid, ids, context=context):
@@ -121,7 +120,9 @@ class website(orm.Model):
_columns = {
'pricelist_id': fields.related('user_id','partner_id','property_product_pricelist',
- type='many2one', relation='product.pricelist', string='Default pricelist')
+ type='many2one', relation='product.pricelist', string='Default pricelist'),
+ 'currency_id': fields.related('pricelist_id','currency_id',
+ type='many2one', relation='res.currency', string='Default pricelist'),
}
def sale_product_domain(self, cr, uid, ids, context=None):
@@ -215,4 +216,9 @@ class website(orm.Model):
'sale_order_code_pricelist_id': False,
})
+ def compute_curency(self, cr, uid, ids, from_amount, from_currency_id=None, context=None):
+ from_currency_id = from_currency_id or self.browse(cr, SUPERUSER_ID, ids[0]).currency_id.id
+ to_currency_id = self.pool.get("res.users").browse(cr, uid, uid).partner_id.property_product_pricelist.currency_id.id
+ return self.pool['res.currency'].compute(cr, uid, from_currency_id, to_currency_id, from_amount, context=context)
+
# vim:et:
diff --git a/addons/website_sale/static/src/css/website_sale.css b/addons/website_sale/static/src/css/website_sale.css
index 73d374357ab..8055d0ad310 100644
--- a/addons/website_sale/static/src/css/website_sale.css
+++ b/addons/website_sale/static/src/css/website_sale.css
@@ -298,14 +298,32 @@
margin: 6px;
}
-.js_add_cart_variants option.css_not_available {
+.css_not_available_msg {
+ display: none;
+}
+
+.css_not_available.js_product > *:nth-child(4) > * {
+ display: none;
+}
+.css_not_available.js_product .product_price, .css_not_available.js_product .css_quantity {
+ display: none;
+}
+.css_not_available.js_product .css_not_available_msg {
+ display: block;
+}
+
+option.css_not_available {
color: #cccccc;
}
-.js_add_cart_variants label.css_not_available {
- opacity: 0.3;
+
+label.css_not_available {
+ opacity: 0.6;
}
-.js_add_cart_variants label.css_not_available input {
- opacity: 0;
+
+label.css_attribute_color.css_not_available {
+ opacity: 1;
+ background-image: url("/website_sale/static/src/img/redcross.png");
+ background-size: cover;
}
.product_detail_img {
diff --git a/addons/website_sale/static/src/css/website_sale.sass b/addons/website_sale/static/src/css/website_sale.sass
index 40308925552..f08b635124c 100644
--- a/addons/website_sale/static/src/css/website_sale.sass
+++ b/addons/website_sale/static/src/css/website_sale.sass
@@ -257,13 +257,24 @@
&.active input
margin: 6px
-.js_add_cart_variants
- option.css_not_available
- color: #ccc
- label.css_not_available
- opacity: 0.3
- input
- opacity: 0
+.css_not_available_msg
+ display: none
+.css_not_available.js_product
+ > *:nth-child(4) > *
+ display: none
+ .product_price, .css_quantity
+ display: none
+ .css_not_available_msg
+ display: block
+
+option.css_not_available
+ color: #ccc
+label.css_not_available
+ opacity: 0.6
+label.css_attribute_color.css_not_available
+ opacity: 1
+ background-image: url('/website_sale/static/src/img/redcross.png')
+ background-size: cover
.product_detail_img
margin-left: auto
diff --git a/addons/website_sale/static/src/img/redcross.png b/addons/website_sale/static/src/img/redcross.png
new file mode 100644
index 00000000000..92a87401e89
Binary files /dev/null and b/addons/website_sale/static/src/img/redcross.png differ
diff --git a/addons/website_sale/static/src/js/website.tour.sale.js b/addons/website_sale/static/src/js/website.tour.sale.js
index 57365a826a6..8867334f403 100644
--- a/addons/website_sale/static/src/js/website.tour.sale.js
+++ b/addons/website_sale/static/src/js/website.tour.sale.js
@@ -1,38 +1,5 @@
(function () {
'use strict';
- openerp.Tour.register({
- id: 'shop_customize',
- name: "Customize the page and search a product",
- path: '/shop',
- mode: 'test',
- steps: [
- {
- title: "open customize menu",
- element: '#customize-menu-button',
- },
- {
- title: "click on 'Product Attribute's Filters'",
- element: "#customize-menu a:contains(Product Attribute's Filters)",
- },
- {
- title: "select product attribute memory 16 Go",
- element: 'form.js_attributes label:contains(16 Go) input:not(:checked)',
- },
- {
- title: "check the selection",
- waitFor: 'form.js_attributes label:contains(16 Go) input:checked',
- },
- {
- title: "select ipod",
- waitNot: '.oe_website_sale .oe_product_cart:eq(2)',
- element: '.oe_product_cart a:contains("iPod")',
- },
- {
- title: "finish",
- waitFor: 'form[action="/shop/cart/update"] label:contains(32 Go) input',
- }
- ]
- });
openerp.Tour.register({
id: 'shop_buy_product',
@@ -57,7 +24,7 @@
{
title: "add suggested",
waitNot: '#cart_products:contains("[A8767] Apple In-Ear Headphones")',
- element: 'form[action="/shop/cart/update"] .btn-link:contains("Add to Cart")',
+ element: '.oe_cart a:contains("Add to Cart")',
},
{
title: "add one more iPod",
diff --git a/addons/website_sale/static/src/js/website_sale.js b/addons/website_sale/static/src/js/website_sale.js
index e0b04a8e07f..ad7823ca6bb 100644
--- a/addons/website_sale/static/src/js/website_sale.js
+++ b/addons/website_sale/static/src/js/website_sale.js
@@ -1,23 +1,27 @@
$(document).ready(function () {
- var $shippingDifferent = $(".oe_website_sale input[name='shipping_different']");
+$('.oe_website_sale').each(function () {
+ var oe_website_sale = this;
+
+ var $shippingDifferent = $("input[name='shipping_different']", oe_website_sale);
if ($shippingDifferent.is(':checked')) {
- $(".oe_website_sale .js_shipping").show();
+ $(".js_shipping", oe_website_sale).show();
}
$shippingDifferent.change(function () {
- $(".oe_website_sale .js_shipping").toggle();
+ $(".js_shipping", oe_website_sale).toggle();
});
// change for css
- $(document).on('mouseup', '.js_publish', function (ev) {
+ $(oe_website_sale).on('mouseup touchend', '.js_publish', function (ev) {
$(ev.currentTarget).parents(".thumbnail").toggleClass("disabled");
});
- $(".oe_website_sale .oe_cart input.js_quantity").change(function () {
+ $(oe_website_sale).on("change", ".oe_cart input.js_quantity", function () {
var $input = $(this);
var value = parseInt($input.val(), 10);
+ var line_id = parseInt($input.data('line-id'),10);
if (isNaN(value)) value = 0;
openerp.jsonRpc("/shop/cart/update_json", 'call', {
- 'line_id': parseInt($input.data('line-id'),10),
+ 'line_id': line_id,
'product_id': parseInt($input.data('product-id'),10),
'set_qty': value})
.then(function (data) {
@@ -28,33 +32,38 @@ $(document).ready(function () {
var $q = $(".my_cart_quantity");
$q.parent().parent().removeClass("hidden", !data.quantity);
$q.html(data.cart_quantity).hide().fadeIn(600);
+
$input.val(data.quantity);
+ $('.js_quantity[data-line-id='+line_id+']').val(data.quantity).html(data.quantity);
$("#cart_total").replaceWith(data['website_sale.total']);
});
});
// hack to add and rome from cart with json
- $('.oe_website_sale a.js_add_cart_json').on('click', function (ev) {
+ $(oe_website_sale).on('click', 'a.js_add_cart_json', function (ev) {
ev.preventDefault();
var $link = $(ev.currentTarget);
var $input = $link.parent().parent().find("input");
- $input.val(($link.has(".fa-minus").length ? -1 : 1) + parseFloat($input.val(),10));
+ var min = parseFloat($input.data("min") || 0);
+ var max = parseFloat($input.data("max") || Infinity);
+ var quantity = ($link.has(".fa-minus").length ? -1 : 1) + parseFloat($input.val(),10);
+ $input.val(quantity > min ? (quantity < max ? quantity : max) : min);
+ $('input[name="'+$input.attr("name")+'"]').val(quantity > min ? (quantity < max ? quantity : max) : min);
$input.change();
return false;
});
- $('.a-submit').on('click', function () {
+ $('.a-submit', oe_website_sale).off('click').on('click', function () {
$(this).closest('form').submit();
});
- $('form.js_attributes input, form.js_attributes select').on('change', function () {
+ $('.form.js_attributes input, form.js_attributes select', oe_website_sale).on('change', function () {
$(this).closest("form").submit();
});
// change price when they are variants
- var $price = $(".oe_price .oe_currency_value");
- $('form.js_add_cart_json label').on('mouseup', function (ev) {
- ev.preventDefault();
- var $label = $(ev.currentTarget);
+ $('form.js_add_cart_json label', oe_website_sale).on('mouseup touchend', function (ev) {
+ var $label = $(this);
+ var $price = $label.parents("form:first").find(".oe_price .oe_currency_value");
if (!$price.data("price")) {
$price.data("price", parseFloat($price.text()));
}
@@ -63,62 +72,85 @@ $(document).ready(function () {
$price.html(value + (dec < 0.01 ? ".00" : (dec < 1 ? "0" : "") ));
});
// hightlight selected color
- $('.css_attribute_color input').on('change', function (ev) {
+ $('.css_attribute_color input', oe_website_sale).on('change', function (ev) {
$('.css_attribute_color').removeClass("active");
$('.css_attribute_color:has(input:checked)').addClass("active");
});
- var $form_var = $('form.js_add_cart_variants');
- var variant_ids = $form_var.data("attribute_value_ids");
- $form_var.on('change', 'input, select', function (ev) {
- var values = [];
- $form_var.find("label").removeClass("text-muted css_not_available");
- $form_var.find(".a-submit").removeAttr("disabled");
+ function price_to_str(price) {
+ price = Math.round(price * 100) / 100;
+ var dec = Math.round((price % 1) * 100);
+ return price + (dec ? '' : '.0') + (dec%10 ? '' : '0');
+ }
- $form_var.find('input:checked, select').each(function () {
+ $(oe_website_sale).on('change', 'input.js_variant_change, select.js_variant_change', function (ev) {
+ var $ul = $(this).parents('ul.js_add_cart_variants:first');
+ var $parent = $ul.closest('.js_product');
+ var $product_id = $parent.find('input.product_id').first();
+ var $price = $parent.find(".oe_price:first .oe_currency_value");
+ var $default_price = $parent.find(".oe_default_price:first .oe_currency_value");
+ var variant_ids = $ul.data("attribute_value_ids");
+ var values = [];
+ $parent.find('input.js_variant_change:checked, select.js_variant_change').each(function () {
values.push(+$(this).val());
});
+
+ $parent.find("label").removeClass("text-muted css_not_available");
+
var product_id = false;
for (var k in variant_ids) {
if (_.isEqual(variant_ids[k][1], values)) {
- var dec = variant_ids[k][2] % 1;
+ $price.html(price_to_str(variant_ids[k][2]));
+ $default_price.html(price_to_str(variant_ids[k][3]));
+ $default_price.parent().toggle(variant_ids[k][3]-variant_ids[k][2]>0.2);
product_id = variant_ids[k][0];
- $('input[name="product_id"]').val(product_id);
- $price.html(variant_ids[k][2] + (dec < 0.01 ? ".00" : (dec < 1 ? "0" : "") ));
break;
}
}
- if (product_id) {
- $("#product_detail .product_detail_img").attr("src", "/website/image?field=image&model=product.product&id="+product_id);
- }
-
- $form_var.find("input:radio, select").each(function () {
- var id = +$(this).val();
+ $parent.find("input.js_variant_change:radio, select.js_variant_change").each(function () {
+ var $input = $(this);
+ var id = +$input.val();
var values = [id];
- $form_var.find(">ul>li:not(:has(input[value='" + id + "'])) input:checked, select").each(function () {
+
+ $parent.find("ul:not(:has(input.js_variant_change[value='" + id + "'])) input.js_variant_change:checked, select").each(function () {
values.push(+$(this).val());
});
+
for (var k in variant_ids) {
if (!_.difference(values, variant_ids[k][1]).length) {
return;
}
}
- $(this).parents("label:not(.css_attribute_color):first").addClass("text-muted");
- $(this).parents("label.css_attribute_color:first").addClass("css_not_available");
- $(this).find("option[value='" + id + "']").addClass("css_not_available");
+ $input.closest("label").addClass("css_not_available");
+ $input.find("option[value='" + id + "']").addClass("css_not_available");
});
if (product_id) {
- $(".oe_price_h4").removeClass("hidden");
- $(".oe_not_available").addClass("hidden");
+ $parent.removeClass("css_not_available");
+ $product_id.val(product_id);
+ $parent.find(".js_check_product").removeAttr("disabled");
} else {
- $(".oe_price_h4").addClass("hidden");
- $(".oe_not_available").removeClass("hidden");
- $form_var.find('input[name="product_id"]').val(0);
- $form_var.find(".a-submit").attr("disabled", "disabled");
+ $parent.addClass("css_not_available");
+ $product_id.val(0);
+ $parent.find(".js_check_product").attr("disabled", "disabled");
}
});
- $form_var.find("input:first").trigger('change');
+ $('ul.js_add_cart_variants', oe_website_sale).each(function () {
+ $('input.js_variant_change, select.js_variant_change', this).first().trigger('change');
+ });
+ $(oe_website_sale).on('change', "select[name='country_id']", function () {
+ var $select = $("select[name='state_id']");
+ $select.find("option:not(:first)").hide();
+ var nb = $select.find("option[data-country_id="+($(this).val() || 0)+"]").show().size();
+ $select.parent().toggle(nb>1);
+ }).change();
+ $(oe_website_sale).on('change', "select[name='shipping_country_id']", function () {
+ var $select = $("select[name='shipping_state_id']");
+ $select.find("option:not(:first)").hide();
+ var nb = $select.find("option[data-country_id="+($(this).val() || 0)+"]").show().size();
+ $select.parent().toggle(nb>1);
+ }).change();
+});
});
diff --git a/addons/website_sale/static/src/js/website_sale_payment.js b/addons/website_sale/static/src/js/website_sale_payment.js
index d4d4a6712c3..ca61e0655d9 100644
--- a/addons/website_sale/static/src/js/website_sale_payment.js
+++ b/addons/website_sale/static/src/js/website_sale_payment.js
@@ -10,7 +10,7 @@ $(document).ready(function () {
.find("input[name='acquirer']:checked").click();
// When clicking on payment button: create the tx using json then continue to the acquirer
- $('button[type="submit"]').on("click", function (ev) {
+ $payment.on("click", 'button[type="submit"]', function (ev) {
ev.preventDefault();
ev.stopPropagation();
var $form = $(ev.currentTarget).parents('form');
diff --git a/addons/website_sale/tests/test_sale_process.py b/addons/website_sale/tests/test_sale_process.py
index a57a2d64bca..3f79ac0ea81 100644
--- a/addons/website_sale/tests/test_sale_process.py
+++ b/addons/website_sale/tests/test_sale_process.py
@@ -4,7 +4,6 @@ import openerp.tests
inject = [
("openerp.Tour", os.path.join(os.path.dirname(__file__), '../../web/static/src/js/tour.js')),
- ("openerp.Tour.ShopTest", os.path.join(os.path.dirname(__file__), "../static/src/js/website.tour.sale.js")),
]
@openerp.tests.common.at_install(False)
@@ -14,7 +13,6 @@ class TestUi(openerp.tests.HttpCase):
self.phantom_js("/", "openerp.Tour.run('shop', 'test')", "openerp.Tour.tours.shop", login="admin")
def test_02_admin_checkout(self):
- self.phantom_js("/", "openerp.Tour.run('shop_customize', 'test')", "openerp.Tour.tours.shop_customize", login="admin", inject=inject)
self.phantom_js("/", "openerp.Tour.run('shop_buy_product', 'test')", "openerp.Tour.tours.shop_buy_product", login="admin", inject=inject)
def test_03_demo_checkout(self):
diff --git a/addons/website_sale/views/templates.xml b/addons/website_sale/views/templates.xml
index 21bab48a8b3..c655afea80e 100644
--- a/addons/website_sale/views/templates.xml
+++ b/addons/website_sale/views/templates.xml
@@ -4,12 +4,6 @@
-
-
-
-
-
-
@@ -17,6 +11,17 @@
+
+
+
+
+
+
+
+
+
+
+