[MERGE] trunk-websit-al-refactor by chm
- allow fiscal position change on sale orders - public user on website - simplify website_sale sale.order and shopping cart code - remove preprocess_request bzr revid: al@openerp.com-20140507153223-q73u5lhyrfw98o3a
This commit is contained in:
commit
56eeefdfda
|
@ -37,6 +37,9 @@ class product_template(osv.osv):
|
|||
|
||||
class product(osv.osv):
|
||||
_inherit = 'product.product'
|
||||
_columns = {
|
||||
'event_ticket_ids': fields.one2many('event.event.ticket', 'product_id', 'Event Tickets'),
|
||||
}
|
||||
|
||||
def onchange_event_ok(self, cr, uid, ids, type, event_ok, context=None):
|
||||
# cannot directly forward to product.template as the ids are theoretically different
|
||||
|
|
|
@ -626,6 +626,48 @@ class sale_order(osv.osv):
|
|||
def action_done(self, cr, uid, ids, context=None):
|
||||
return self.write(cr, uid, ids, {'state': 'done'}, context=context)
|
||||
|
||||
def onchange_fiscal_position(self, cr, uid, ids, fiscal_position, order_lines, context=None):
|
||||
'''Update taxes of order lines for each line where a product is defined
|
||||
|
||||
:param list ids: not used
|
||||
:param int fiscal_position: sale order fiscal position
|
||||
:param list order_lines: command list for one2many write method
|
||||
'''
|
||||
order_line = []
|
||||
fiscal_obj = self.pool.get('account.fiscal.position')
|
||||
product_obj = self.pool.get('product.product')
|
||||
line_obj = self.pool.get('sale.order.line')
|
||||
|
||||
fpos = False
|
||||
if fiscal_position:
|
||||
fpos = fiscal_obj.browse(cr, uid, fiscal_position, context=context)
|
||||
|
||||
for line in order_lines:
|
||||
# create (0, 0, { fields })
|
||||
# update (1, ID, { fields })
|
||||
if line[0] in [0, 1]:
|
||||
prod = None
|
||||
if line[2].get('product_id'):
|
||||
prod = product_obj.browse(cr, uid, line[2]['product_id'], context=context)
|
||||
elif line[1]:
|
||||
prod = line_obj.browse(cr, uid, line[1], context=context).product_id
|
||||
if prod and prod.taxes_id:
|
||||
line[2]['tax_id'] = [[6, 0, fiscal_obj.map_tax(cr, uid, fpos, prod.taxes_id)]]
|
||||
order_line.append(line)
|
||||
|
||||
# link (4, ID)
|
||||
# link all (6, 0, IDS)
|
||||
elif line[0] in [4, 6]:
|
||||
line_ids = line[0] == 4 and [line[1]] or line[2]
|
||||
for line_id in line_ids:
|
||||
prod = line_obj.browse(cr, uid, line_id, context=context).product_id
|
||||
if prod and prod.taxes_id:
|
||||
order_line.append([1, line_id, {'tax_id': [[6, 0, fiscal_obj.map_tax(cr, uid, fpos, prod.taxes_id)]]}])
|
||||
else:
|
||||
order_line.append([4, line_id])
|
||||
else:
|
||||
order_line.append(line)
|
||||
return {'value': {'order_line': order_line}}
|
||||
|
||||
|
||||
# TODO add a field price_unit_uos
|
||||
|
@ -869,8 +911,8 @@ class sale_order_line(osv.osv):
|
|||
partner_obj = self.pool.get('res.partner')
|
||||
product_obj = self.pool.get('product.product')
|
||||
context = {'lang': lang, 'partner_id': partner_id}
|
||||
if partner_id:
|
||||
lang = partner_obj.browse(cr, uid, partner_id).lang
|
||||
partner = partner_obj.browse(cr, uid, partner_id)
|
||||
lang = partner.lang
|
||||
context_partner = {'lang': lang, 'partner_id': partner_id}
|
||||
|
||||
if not product:
|
||||
|
@ -896,7 +938,12 @@ class sale_order_line(osv.osv):
|
|||
uos = False
|
||||
else:
|
||||
uos = False
|
||||
fpos = fiscal_position and self.pool.get('account.fiscal.position').browse(cr, uid, fiscal_position) or False
|
||||
|
||||
fpos = False
|
||||
if not fiscal_position:
|
||||
fpos = partner.property_account_position or False
|
||||
else:
|
||||
fpos = self.pool.get('account.fiscal.position').browse(cr, uid, fiscal_position)
|
||||
if update_tax: #The quantity only have changed
|
||||
result['tax_id'] = self.pool.get('account.fiscal.position').map_tax(cr, uid, fpos, product_obj.taxes_id)
|
||||
|
||||
|
|
|
@ -206,7 +206,8 @@
|
|||
</group>
|
||||
<group name="sale_pay">
|
||||
<field name="payment_term" options="{'no_create': True}"/>
|
||||
<field name="fiscal_position" options="{'no_create': True}"/>
|
||||
<field name="fiscal_position" options="{'no_create': True}"
|
||||
on_change="onchange_fiscal_position(fiscal_position, order_line, context)"/>
|
||||
<field name="company_id" widget="selection" groups="base.group_multi_company"/>
|
||||
</group>
|
||||
<group>
|
||||
|
|
|
@ -12,7 +12,7 @@ OpenERP Website CMS
|
|||
'depends': ['web', 'share', 'mail'],
|
||||
'installable': True,
|
||||
'data': [
|
||||
'data/website_data.xml',
|
||||
'data/data.xml',
|
||||
'security/ir.model.access.csv',
|
||||
'security/ir_ui_view.xml',
|
||||
'views/website_templates.xml',
|
||||
|
@ -23,7 +23,7 @@ OpenERP Website CMS
|
|||
'views/ir_actions.xml',
|
||||
],
|
||||
'demo': [
|
||||
'data/website_demo.xml',
|
||||
'data/demo.xml',
|
||||
],
|
||||
'qweb': ['static/src/xml/website.backend.xml'],
|
||||
'application': True,
|
||||
|
|
|
@ -32,6 +32,13 @@ class ir_http(orm.AbstractModel):
|
|||
page=PageConverter,
|
||||
)
|
||||
|
||||
def _auth_method_public(self):
|
||||
# TODO: select user_id from matching website
|
||||
if not request.session.uid:
|
||||
request.uid = self.pool['ir.model.data'].xmlid_to_res_id(request.cr, openerp.SUPERUSER_ID, 'base.public_user')
|
||||
else:
|
||||
request.uid = request.session.uid
|
||||
|
||||
def _dispatch(self):
|
||||
first_pass = not hasattr(request, 'website')
|
||||
request.website = None
|
||||
|
|
|
@ -109,10 +109,6 @@ class website(osv.osv):
|
|||
menu = menus and menus[0] or False
|
||||
return dict( map(lambda x: (x, menu), ids) )
|
||||
|
||||
def _get_public_user(self, cr, uid, ids, name='public_user', arg=(), context=None):
|
||||
ref = self.get_public_user(cr, uid, context=context)
|
||||
return dict( map(lambda x: (x, ref), ids) )
|
||||
|
||||
_name = "website" # Avoid website.website convention for conciseness (for new api). Got a special authorization from xmo and rco
|
||||
_description = "Website"
|
||||
_columns = {
|
||||
|
@ -129,13 +125,17 @@ class website(osv.osv):
|
|||
'social_googleplus': fields.char('Google+ Account'),
|
||||
'google_analytics_key': fields.char('Google Analytics Key'),
|
||||
'user_id': fields.many2one('res.users', string='Public User'),
|
||||
'public_user': fields.function(_get_public_user, relation='res.users', type='many2one', string='Public User'),
|
||||
'partner_id': fields.related('user_id','partner_id', type='many2one', relation='res.partner', string='Public Partner'),
|
||||
'menu_id': fields.function(_get_menu, relation='website.menu', type='many2one', string='Main Menu',
|
||||
store= {
|
||||
'website.menu': (_get_menu_website, ['sequence','parent_id','website_id'], 10)
|
||||
})
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'company_id': lambda self,cr,uid,c: self.pool['ir.model.data'].xmlid_to_res_id(cr, openerp.SUPERUSER_ID, 'base.public_user'),
|
||||
}
|
||||
|
||||
# cf. Wizard hack in website_views.xml
|
||||
def noop(self, *args, **kwargs):
|
||||
pass
|
||||
|
@ -186,11 +186,6 @@ class website(osv.osv):
|
|||
except:
|
||||
return False
|
||||
|
||||
def get_public_user(self, cr, uid, context=None):
|
||||
uid = openerp.SUPERUSER_ID
|
||||
res = self.pool['ir.model.data'].get_object_reference(cr, uid, 'base', 'public_user')
|
||||
return res and res[1] or False
|
||||
|
||||
@openerp.tools.ormcache(skiparg=3)
|
||||
def _get_languages(self, cr, uid, id, context=None):
|
||||
website = self.browse(cr, uid, id)
|
||||
|
@ -342,7 +337,7 @@ class website(osv.osv):
|
|||
"""
|
||||
router = request.httprequest.app.get_db_router(request.db)
|
||||
# Force enumeration to be performed as public user
|
||||
uid = self.get_public_user(cr, uid, context=context)
|
||||
uid = request.website.user_id.id
|
||||
url_list = []
|
||||
for rule in router.iter_rules():
|
||||
if not self.rule_is_enumerable(rule):
|
||||
|
|
|
@ -104,11 +104,11 @@ var T = website.Tour = {
|
|||
if (tour.path && !window.location.href.match(new RegExp("("+T.getLang()+")?"+tour.path+"#?$", "i"))) {
|
||||
var href = "/"+T.getLang()+tour.path;
|
||||
console.log("Tour Begin from run method (redirection to "+href+")");
|
||||
T.saveState(tour.id, mode || tour.mode, -1);
|
||||
T.saveState(tour.id, mode || tour.mode, -1, 0);
|
||||
window.location.href = href;
|
||||
} else {
|
||||
console.log("Tour Begin from run method");
|
||||
T.saveState(tour.id, mode || tour.mode, 0);
|
||||
T.saveState(tour.id, mode || tour.mode, 0, 0);
|
||||
T.running();
|
||||
}
|
||||
},
|
||||
|
@ -311,7 +311,7 @@ var T = website.Tour = {
|
|||
};
|
||||
window.location.hash = "";
|
||||
console.log("Tour Begin from url hash");
|
||||
T.saveState(state.id, state.mode, state.step_id);
|
||||
T.saveState(state.id, state.mode, state.step_id, 0);
|
||||
}
|
||||
if (!state.id) {
|
||||
return;
|
||||
|
@ -341,8 +341,8 @@ var T = website.Tour = {
|
|||
}
|
||||
return tour_ids;
|
||||
},
|
||||
saveState: function (tour_id, mode, step_id) {
|
||||
localStorage.setItem("tour", JSON.stringify({"id":tour_id, "mode":mode, "step_id":step_id || 0, "time": this.time}));
|
||||
saveState: function (tour_id, mode, step_id, number) {
|
||||
localStorage.setItem("tour", JSON.stringify({"id":tour_id, "mode":mode, "step_id":step_id || 0, "time": this.time, "number": number+1}));
|
||||
},
|
||||
reset: function () {
|
||||
var state = T.getState();
|
||||
|
@ -402,6 +402,7 @@ var T = website.Tour = {
|
|||
if (T.check(next)) {
|
||||
clearTimeout(T.currentTimer);
|
||||
// use an other timeout for cke dom loading
|
||||
T.saveState(state.id, state.mode, state.step.id, 0);
|
||||
setTimeout(function () {
|
||||
T.nextStep(next);
|
||||
}, T.defaultDelay);
|
||||
|
@ -421,7 +422,13 @@ var T = website.Tour = {
|
|||
}
|
||||
|
||||
step = step || state.step;
|
||||
T.saveState(state.id, state.mode, step.id);
|
||||
var next = state.tour.steps[step.id+1];
|
||||
|
||||
if (state.number > 3) {
|
||||
T.error(next, "Cycling. Can't reach the next step");
|
||||
}
|
||||
|
||||
T.saveState(state.id, state.mode, step.id, state.number);
|
||||
|
||||
if (step.id !== state.step_id) {
|
||||
console.log("Tour Step: '" + (step._title || step.title) + "' (" + (new Date().getTime() - this.time) + "ms)");
|
||||
|
@ -433,7 +440,6 @@ var T = website.Tour = {
|
|||
step.onload();
|
||||
}
|
||||
|
||||
var next = state.tour.steps[step.id+1];
|
||||
if (next) {
|
||||
setTimeout(function () {
|
||||
T.waitNextStep();
|
||||
|
|
|
@ -34,6 +34,7 @@ import time
|
|||
from dateutil.relativedelta import relativedelta
|
||||
from openerp import tools
|
||||
import werkzeug.urls
|
||||
from openerp.addons.website.models.website import slug
|
||||
|
||||
try:
|
||||
import GeoIP
|
||||
|
@ -211,7 +212,8 @@ class website_event(http.Controller):
|
|||
'date_end': (date_begin + timedelta(days=(1))).strftime('%Y-%m-%d'),
|
||||
}
|
||||
event_id = Event.create(request.cr, request.uid, vals, context=context)
|
||||
return request.redirect("/event/%s?enable_editor=1" % event_id)
|
||||
event = Event.browse(request.cr, request.uid, event_id, context=context)
|
||||
return request.redirect("/event/%s/register?enable_editor=1" % slug(event))
|
||||
|
||||
def get_visitors_country(self):
|
||||
GI = GeoIP.open('/usr/share/GeoIP/GeoIP.dat', 0)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
access_event_event_public,event.event.public,event.model_event_event,base.group_public,1,0,0,0
|
||||
access_event_event_portal,event.event.portal,event.model_event_event,base.group_portal,1,0,0,0
|
||||
access_event_type_public,event.type.public,event.model_event_type,base.group_public,1,0,0,0
|
||||
access_event_type_portal,event.type.portal,event.model_event_type,base.group_portal,1,0,0,0
|
||||
|
|
|
|
@ -27,57 +27,24 @@ from openerp.tools.translate import _
|
|||
|
||||
|
||||
class website_event(website_event):
|
||||
@http.route(['/event/add_cart'], type='http', auth="public", website=True, multilang=True)
|
||||
def add_cart(self, event_id, **post):
|
||||
user_obj = request.registry['res.users']
|
||||
order_line_obj = request.registry.get('sale.order.line')
|
||||
|
||||
@http.route(['/event/cart/update'], type='http', auth="public", methods=['POST'], website=True, multilang=True)
|
||||
def cart_update(self, event_id, **post):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
ticket_obj = request.registry.get('event.event.ticket')
|
||||
order_obj = request.registry.get('sale.order')
|
||||
website = request.registry['website']
|
||||
|
||||
order = website.ecommerce_get_current_order(request.cr, request.uid, context=request.context)
|
||||
if not order:
|
||||
order = website.ecommerce_get_new_order(request.cr, request.uid, context=request.context)
|
||||
|
||||
partner_id = user_obj.browse(request.cr, SUPERUSER_ID, request.uid,
|
||||
context=request.context).partner_id.id
|
||||
|
||||
fields = [k for k, v in order_line_obj._columns.items()]
|
||||
values = order_line_obj.default_get(request.cr, SUPERUSER_ID, fields,
|
||||
context=request.context)
|
||||
|
||||
_values = None
|
||||
sale = False
|
||||
for key, value in post.items():
|
||||
try:
|
||||
quantity = int(value)
|
||||
assert quantity > 0
|
||||
except:
|
||||
quantity = None
|
||||
ticket_id = key.split("-")[0] == 'ticket' and int(key.split("-")[1]) or None
|
||||
if not ticket_id or not quantity:
|
||||
quantity = int(value or "0")
|
||||
if not quantity:
|
||||
continue
|
||||
ticket = ticket_obj.browse(request.cr, request.uid, ticket_id,
|
||||
context=request.context)
|
||||
sale = True
|
||||
ticket_id = key.split("-")[0] == 'ticket' and int(key.split("-")[1]) or None
|
||||
ticket = ticket_obj.browse(cr, SUPERUSER_ID, ticket_id, context=context)
|
||||
request.website.sale_get_order(force_create=1)._cart_update(
|
||||
product_id=ticket.product_id.id, add_qty=quantity, context=dict(context, event_ticket_id=ticket.id))
|
||||
|
||||
values['product_id'] = ticket.product_id.id
|
||||
values['event_id'] = ticket.event_id.id
|
||||
values['event_ticket_id'] = ticket.id
|
||||
values['product_uom_qty'] = quantity
|
||||
values['price_unit'] = ticket.price
|
||||
values['order_id'] = order.id
|
||||
values['name'] = "%s: %s" % (ticket.event_id.name, ticket.name)
|
||||
|
||||
# change and record value
|
||||
pricelist_id = order.pricelist_id and order.pricelist_id.id or False
|
||||
_values = order_line_obj.product_id_change(
|
||||
request.cr, SUPERUSER_ID, [], pricelist_id, ticket.product_id.id,
|
||||
partner_id=partner_id, context=request.context)['value']
|
||||
_values.update(values)
|
||||
|
||||
order_line_id = order_line_obj.create(request.cr, SUPERUSER_ID, _values, context=request.context)
|
||||
order_obj.write(request.cr, SUPERUSER_ID, [order.id], {'order_line': [(4, order_line_id)]}, context=request.context)
|
||||
|
||||
if not _values:
|
||||
if not sale:
|
||||
return request.redirect("/event/%s" % event_id)
|
||||
return request.redirect("/shop/checkout")
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
import product
|
||||
import sale_order
|
||||
import website
|
||||
import sale_order
|
||||
|
|
|
@ -1,22 +1,49 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from openerp.osv import osv
|
||||
from openerp import SUPERUSER_ID
|
||||
from openerp.addons.web.http import request
|
||||
from openerp.osv import osv, fields
|
||||
from openerp.tools.translate import _
|
||||
|
||||
# defined for access rules
|
||||
class sale_order(osv.Model):
|
||||
_inherit = "sale.order"
|
||||
|
||||
class sale_order_line(osv.osv):
|
||||
_inherit = "sale.order.line"
|
||||
def _cart_find_product_line(self, cr, uid, ids, product_id=None, line_id=None, context=None):
|
||||
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 += [('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
|
||||
|
||||
def _recalculate_product_values(self, cr, uid, ids, product_id=0, fiscal_position=False, context=None):
|
||||
if not ids:
|
||||
return super(sale_order_line, self)._recalculate_product_values(cr, uid, ids, product_id, fiscal_position=fiscal_position, 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)
|
||||
|
||||
order_line = self.browse(cr, SUPERUSER_ID, ids[0], context=context)
|
||||
assert order_line.order_id.website_session_id == request.session['website_session_id']
|
||||
event_ticket_id = None
|
||||
if context.get("event_ticket_id"):
|
||||
event_ticket_id = context.get("event_ticket_id")
|
||||
elif line_id:
|
||||
line = self.pool.get('sale.order.line').browse(cr, SUPERUSER_ID, line_id, context=context)
|
||||
if line.event_ticket_id:
|
||||
event_ticket_id = line.event_ticket_id.id
|
||||
else:
|
||||
product = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
|
||||
if product.event_ticket_ids:
|
||||
event_ticket_id = product.event_ticket_ids[0]
|
||||
|
||||
product = product_id and self.pool.get('product.product').browse(cr, uid, product_id, context=context) or order_line.product_id
|
||||
res = super(sale_order_line, self)._recalculate_product_values(cr, uid, ids, product.id, fiscal_position=fiscal_position, context=context)
|
||||
if product.event_type_id and order_line.event_ticket_id and order_line.event_ticket_id.price != product.lst_price:
|
||||
res.update({'price_unit': order_line.event_ticket_id.price})
|
||||
if event_ticket_id:
|
||||
ticket = self.pool.get('event.event.ticket').browse(cr, uid, event_ticket_id, context=context)
|
||||
if product_id != ticket.product_id.id:
|
||||
raise osv.except_osv(_('Error!'),_("The ticket doesn't match with this product."))
|
||||
|
||||
return res
|
||||
values['product_id'] = ticket.product_id.id
|
||||
values['event_id'] = ticket.event_id.id
|
||||
values['event_ticket_id'] = ticket.id
|
||||
values['price_unit'] = ticket.price
|
||||
values['name'] = "%s: %s" % (ticket.event_id.name, ticket.name)
|
||||
|
||||
return values
|
||||
|
|
|
@ -5,6 +5,6 @@ from openerp.osv import orm
|
|||
class Website(orm.Model):
|
||||
_inherit = 'website'
|
||||
|
||||
def ecommerce_get_product_domain(self):
|
||||
def sale_product_domain(self, cr, uid, ids, context=None):
|
||||
# remove product event from the website content grid and list view (not removed in detail view)
|
||||
return ['&'] + super(Website, self).ecommerce_get_product_domain() + [('event_ok', '=', False)]
|
||||
return ['&'] + super(Website, self).sale_product_domain(cr, uid, ids, context=context) + [('event_ok', '=', False)]
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
</xpath>
|
||||
</template>
|
||||
|
||||
<template id="mycart" inherit_id="website_sale.mycart" name="My Cart Event's Price">
|
||||
<template id="cart" inherit_id="website_sale.cart" name="My Cart Event's Price">
|
||||
<xpath expr="//td[@name='price']/t" position="attributes">
|
||||
<attribute name="t-if">abs(line.product_id.lst_price - line.price_unit) > 0.2 and not line.product_id.event_ok</attribute>
|
||||
</xpath>
|
||||
|
@ -28,7 +28,7 @@
|
|||
|
||||
<template id="event_description_full" inherit_id="website_event.event_description_full" inherit_option_id="website_event.event_description_full" name="Event's Ticket form">
|
||||
<xpath expr="//div[@t-field='event.description']" position="before">
|
||||
<form t-attf-action="/event/add_cart?event_id=#{ event.id }" method="post" t-if="event.event_ticket_ids">
|
||||
<form t-attf-action="/event/cart/update?event_id=#{ event.id }" method="post" t-if="event.event_ticket_ids">
|
||||
<table itemprop="offers" class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
|
|
|
@ -32,14 +32,13 @@ class WebsiteMail(http.Controller):
|
|||
|
||||
partner_obj = request.registry['res.partner']
|
||||
user_obj = request.registry['res.users']
|
||||
website = request.registry['website']
|
||||
|
||||
_id = int(id)
|
||||
_message_is_follower = message_is_follower == 'on'
|
||||
_object = request.registry[object]
|
||||
|
||||
# search partner_id
|
||||
public_id = website.get_public_user(cr, uid, context)
|
||||
public_id = request.website.user_id.id
|
||||
if uid != public_id:
|
||||
partner_ids = [user_obj.browse(cr, uid, uid, context).partner_id.id]
|
||||
else:
|
||||
|
@ -68,10 +67,9 @@ class WebsiteMail(http.Controller):
|
|||
partner_obj = request.registry.get('res.partner')
|
||||
users_obj = request.registry.get('res.users')
|
||||
obj = request.registry.get(model)
|
||||
website = request.registry['website']
|
||||
|
||||
partner_id = None
|
||||
public_id = website.get_public_user(cr, uid, context)
|
||||
public_id = request.website.user_id.id
|
||||
if uid != public_id:
|
||||
partner_id = users_obj.browse(cr, SUPERUSER_ID, uid, context).partner_id
|
||||
elif request.session.get('partner_id'):
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
.. _changelog:
|
||||
|
||||
Changelog
|
||||
=========
|
||||
|
||||
`trunk (saas-3)`
|
||||
----------------
|
||||
|
||||
- created ``website_mail`` menu, holding website-related stuff about mail module
|
|
@ -1,10 +0,0 @@
|
|||
Website Mail Module documentation topics
|
||||
''''''''''''''''''''''''''''''''''''''''
|
||||
|
||||
Changelog
|
||||
'''''''''
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
changelog.rst
|
|
@ -32,7 +32,7 @@
|
|||
'views/website_partner_view.xml',
|
||||
'data/website_data.xml',
|
||||
],
|
||||
'demo': ['website_partner_demo.xml'],
|
||||
'demo': ['data/demo.xml'],
|
||||
'qweb': [
|
||||
],
|
||||
'installable': True,
|
||||
|
|
|
@ -11,15 +11,15 @@ OpenERP E-Commerce
|
|||
'author': 'OpenERP SA',
|
||||
'depends': ['website', 'sale', 'payment'],
|
||||
'data': [
|
||||
'data/website_sale_data.xml',
|
||||
'views/website_sale.xml',
|
||||
'views/website_sale_backend.xml',
|
||||
'data/data.xml',
|
||||
'views/views.xml',
|
||||
'views/templates.xml',
|
||||
'views/payment.xml',
|
||||
'security/ir.model.access.csv',
|
||||
'security/website_sale.xml',
|
||||
],
|
||||
'demo': [
|
||||
'data/website_sale_demo.xml',
|
||||
'data/demo.xml',
|
||||
],
|
||||
'qweb': ['static/src/xml/*.xml'],
|
||||
'installable': True,
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import random
|
||||
import simplejson
|
||||
import werkzeug
|
||||
|
||||
from openerp import SUPERUSER_ID
|
||||
|
@ -12,47 +10,6 @@ from openerp.addons.website.models.website import slug
|
|||
PPG = 20 # Products Per Page
|
||||
PPR = 4 # Products Per Row
|
||||
|
||||
|
||||
class CheckoutInfo(object):
|
||||
mandatory_billing_fields = ["name", "phone", "email", "street", "city", "country_id", "zip"]
|
||||
optional_billing_fields = ["company", "state_id"]
|
||||
string_billing_fields = ["name", "phone", "email", "street", "city", "zip"]
|
||||
|
||||
mandatory_shipping_fields = ["shipping_name", "shipping_phone", "shipping_street", "shipping_city", "shipping_country_id", "shipping_zip"]
|
||||
optional_shipping_field = ["shipping_state_id"]
|
||||
string_shipping_fields = ["shipping_name", "shipping_phone", "shipping_street", "shipping_city", "shipping_zip"]
|
||||
|
||||
def mandatory_fields(self):
|
||||
return self.mandatory_billing_fields + self.mandatory_shipping_fields
|
||||
|
||||
def optional_fields(self):
|
||||
return self.optional_billing_fields + self.optional_shipping_field
|
||||
|
||||
def all_fields(self):
|
||||
return self.mandatory_fields() + self.optional_fields()
|
||||
|
||||
def empty(self):
|
||||
return dict.fromkeys(self.all_fields(), '')
|
||||
|
||||
def from_partner(self, partner, address_type='billing'):
|
||||
assert address_type in ('billing', 'shipping')
|
||||
if address_type == 'billing':
|
||||
prefix = ''
|
||||
else:
|
||||
prefix = 'shipping_'
|
||||
result = dict((prefix + field_name, getattr(partner, field_name)) for field_name in self.string_billing_fields if getattr(partner, field_name))
|
||||
result[prefix + 'state_id'] = partner.state_id and partner.state_id.id or ''
|
||||
result[prefix + 'country_id'] = partner.country_id and partner.country_id.id or ''
|
||||
result[prefix + 'company'] = partner.commercial_partner_id and partner.commercial_partner_id.is_company and partner.commercial_partner_id.name or ''
|
||||
return result
|
||||
|
||||
def from_post(self, post):
|
||||
return dict((field_name, post[field_name]) for field_name in self.all_fields() if post[field_name])
|
||||
|
||||
|
||||
#
|
||||
# Compute grid of products according to their sizes
|
||||
#
|
||||
class table_compute(object):
|
||||
def __init__(self):
|
||||
self.table = {}
|
||||
|
@ -116,209 +73,137 @@ class table_compute(object):
|
|||
|
||||
return rows
|
||||
|
||||
# TODO keep with input type hidden
|
||||
|
||||
class Ecommerce(http.Controller):
|
||||
|
||||
_order = 'website_published desc, website_sequence desc'
|
||||
class QueryURL(object):
|
||||
def __init__(self, path='', **args):
|
||||
self.path = path
|
||||
self.args = args
|
||||
|
||||
def get_attribute_ids(self):
|
||||
attributes_obj = request.registry['product.attribute']
|
||||
attributes_ids = attributes_obj.search(request.cr, request.uid, [], context=request.context)
|
||||
return attributes_obj.browse(request.cr, request.uid, attributes_ids, context=request.context)
|
||||
def __call__(self, path=None, **kw):
|
||||
if not path:
|
||||
path = self.path
|
||||
for k,v in self.args.items():
|
||||
kw.setdefault(k,v)
|
||||
l = []
|
||||
for k,v in kw.items():
|
||||
if v:
|
||||
if isinstance(v, list) or isinstance(v, set):
|
||||
l.append(werkzeug.url_encode([(k,i) for i in v]))
|
||||
else:
|
||||
l.append(werkzeug.url_encode([(k,v)]))
|
||||
if l:
|
||||
path += '?' + '&'.join(l)
|
||||
return path
|
||||
|
||||
|
||||
class website_sale(http.Controller):
|
||||
|
||||
def get_pricelist(self):
|
||||
""" Shortcut to get the pricelist from the website model """
|
||||
return request.registry['website'].ecommerce_get_pricelist_id(request.cr, request.uid, None, context=request.context)
|
||||
|
||||
def get_order(self):
|
||||
""" Shortcut to get the current ecommerce quotation from the website model """
|
||||
return request.registry['website'].ecommerce_get_current_order(request.cr, request.uid, context=request.context)
|
||||
|
||||
def get_products(self, product_ids):
|
||||
product_obj = request.registry.get('product.template')
|
||||
request.context['pricelist'] = self.get_pricelist()
|
||||
# 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)]
|
||||
return product_obj.browse(request.cr, request.uid, product_ids, context=request.context)
|
||||
|
||||
def has_search_filter(self, attribute_id, value_id=None):
|
||||
if request.httprequest.args.get('filters'):
|
||||
filters = simplejson.loads(request.httprequest.args['filters'])
|
||||
cr, uid, context, pool = request.cr, request.uid, request.context, request.registry
|
||||
sale_order = context.get('sale_order')
|
||||
if sale_order:
|
||||
pricelist = sale_order.pricelist_id
|
||||
else:
|
||||
filters = []
|
||||
for key_val in filters:
|
||||
if key_val[0] == attribute_id and (not value_id or value_id in key_val[1:]):
|
||||
return key_val
|
||||
return False
|
||||
partner = pool['res.users'].browse(cr, SUPERUSER_ID, uid, context=context).partner_id
|
||||
pricelist = partner.property_product_pricelist
|
||||
return pricelist
|
||||
|
||||
@http.route(['/shop/filters'], type='http', auth="public", methods=['POST'], website=True, multilang=True)
|
||||
def filters(self, category=None, **post):
|
||||
index = []
|
||||
filters = []
|
||||
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:
|
||||
filters.append([cat_id , [_min, _max] ])
|
||||
index.append(cat_id)
|
||||
elif cat_id not in index:
|
||||
filters.append([ cat_id, int(cat[2]) ])
|
||||
index.append(cat_id)
|
||||
else:
|
||||
cat[2] = int(cat[2])
|
||||
if cat[2] not in filters[index.index(cat_id)][1:]:
|
||||
filters[index.index(cat_id)].append( cat[2] )
|
||||
post.pop(key)
|
||||
|
||||
url = "/shop"
|
||||
if category:
|
||||
category_obj = request.registry.get('product.public.category')
|
||||
url = "%s/category/%s" % (url, slug(category_obj.browse(request.cr, request.uid, int(category), context=request.context)))
|
||||
if filters:
|
||||
url = "%s?filters=%s" % (url, simplejson.dumps(filters))
|
||||
if post.get("search"):
|
||||
url = "%s%ssearch=%s" % (url, filters and "&" or "?", post.get("search"))
|
||||
|
||||
return request.redirect(url)
|
||||
|
||||
def attributes_to_ids(self, cr, uid, attributes):
|
||||
req = """
|
||||
SELECT product_tmpl_id as id, count(*) as nb_match
|
||||
FROM product_attribute_line
|
||||
WHERE 1!=1
|
||||
"""
|
||||
nb = 0
|
||||
for key_val in attributes:
|
||||
attribute_id = key_val[0]
|
||||
if isinstance(key_val[1], list):
|
||||
req += " OR ( attribute_id = %s AND value >= %s AND value <= %s)" % \
|
||||
(attribute_id, key_val[1][0], key_val[1][1])
|
||||
nb += 1
|
||||
else:
|
||||
for value_id in key_val[1:]:
|
||||
req += " OR ( attribute_id = %s AND value_id = %s)" % \
|
||||
(attribute_id, value_id)
|
||||
nb += 1
|
||||
|
||||
req += " GROUP BY product_tmpl_id"
|
||||
cr.execute(req)
|
||||
result = cr.fetchall()
|
||||
return [id for id, nb_match in result if nb_match >= nb]
|
||||
|
||||
@http.route(['/shop/pricelist'], type='http', auth="public", website=True, multilang=True)
|
||||
def shop_promo(self, promo=None, **post):
|
||||
request.registry['website']._ecommerce_change_pricelist(request.cr, request.uid, code=promo, context=request.context)
|
||||
return request.redirect("/shop/mycart")
|
||||
|
||||
@http.route([
|
||||
'/shop',
|
||||
@http.route(['/shop',
|
||||
'/shop/page/<int:page>',
|
||||
'/shop/category/<model("product.public.category"):category>',
|
||||
'/shop/category/<model("product.public.category"):category>/page/<int:page>'
|
||||
], type='http', auth="public", website=True, multilang=True)
|
||||
def shop(self, category=None, page=0, filters='', search='', **post):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
product_obj = request.registry.get('product.template')
|
||||
base_domain = request.registry.get('website').ecommerce_get_product_domain()
|
||||
domain = list(base_domain)
|
||||
if search:
|
||||
domain += ['|',
|
||||
('name', 'ilike', search),
|
||||
('description', 'ilike', search)]
|
||||
if category:
|
||||
domain.append(('product_variant_ids.public_categ_id', 'child_of', int(category)))
|
||||
if isinstance(category, (int,str,unicode)):
|
||||
category = request.registry.get('product.public.category').browse(cr, uid, int(category), context=context)
|
||||
if filters:
|
||||
filters = simplejson.loads(filters)
|
||||
if filters:
|
||||
ids = self.attributes_to_ids(cr, uid, filters)
|
||||
domain.append(('id', 'in', ids or [0]))
|
||||
def shop(self, page=0, category=None, search='', **post):
|
||||
cr, uid, context, pool = request.cr, request.uid, request.context, request.registry
|
||||
|
||||
url = "/shop"
|
||||
domain = request.website.sale_product_domain()
|
||||
if search:
|
||||
domain += ['|', ('name', 'ilike', search), ('description', 'ilike', search)]
|
||||
if category:
|
||||
domain += [('product_variant_ids.public_categ_id', 'child_of', int(category))]
|
||||
|
||||
attrib_values = map(int,request.httprequest.args.getlist('attrib'))
|
||||
if attrib_values:
|
||||
domain += [('attribute_lines.value_id', 'in', attrib_values)]
|
||||
attrib_set = set(attrib_values)
|
||||
keep = QueryURL('/shop', category=category and int(category), search=search, attrib=attrib_set)
|
||||
|
||||
if not context.get('pricelist'):
|
||||
context['pricelist'] = int(self.get_pricelist())
|
||||
product_obj = pool.get('product.template')
|
||||
product_count = product_obj.search_count(cr, uid, domain, context=context)
|
||||
if search:
|
||||
post["search"] = search
|
||||
if filters:
|
||||
post["filters"] = filters
|
||||
if category:
|
||||
url = "/shop/category/%s" % slug(category)
|
||||
pager = request.website.pager(url=url, total=product_count, page=page, step=PPG, scope=7, url_args=post)
|
||||
pager = request.website.pager(url="/shop", total=product_count, page=page, step=PPG, scope=7, url_args=post)
|
||||
product_ids = product_obj.search(cr, uid, domain, limit=PPG+10, offset=pager['offset'], order='website_published desc, website_sequence desc', context=context)
|
||||
products = product_obj.browse(cr, uid, product_ids, context=context)
|
||||
|
||||
request.context['pricelist'] = self.get_pricelist()
|
||||
style_obj = pool['product.style']
|
||||
style_ids = style_obj.search(cr, uid, [], context=context)
|
||||
styles = style_obj.browse(cr, uid, style_ids, context=context)
|
||||
|
||||
pids = product_obj.search(cr, uid, domain, limit=PPG+10, offset=pager['offset'], order=self._order, context=context)
|
||||
products = product_obj.browse(cr, uid, pids, context=context)
|
||||
|
||||
styles = []
|
||||
try:
|
||||
style_obj = request.registry.get('product.style')
|
||||
style_ids = style_obj.search(request.cr, request.uid, [], context=request.context)
|
||||
styles = style_obj.browse(request.cr, request.uid, style_ids, context=request.context)
|
||||
except:
|
||||
pass
|
||||
|
||||
category_obj = request.registry.get('product.public.category')
|
||||
category_ids = [product['public_categ_id'][0] for product in product_obj.read_group(cr, uid, base_domain, ['public_categ_id'], ['public_categ_id'], context=context) if product['public_categ_id']]
|
||||
category_obj = pool['product.public.category']
|
||||
category_ids = category_obj.search(cr, uid, [], context=context)
|
||||
categories = category_obj.browse(cr, uid, category_ids, context=context)
|
||||
all_categories = set(categories)
|
||||
for cat in categories:
|
||||
parent = cat.parent_id
|
||||
while parent:
|
||||
all_categories.add(parent)
|
||||
parent = parent.parent_id
|
||||
categories = list(all_categories)
|
||||
categories.sort(key=lambda x: x.sequence)
|
||||
categs = filter(lambda x: not x.parent_id, categories)
|
||||
|
||||
attributes_obj = request.registry['product.attribute']
|
||||
attributes_ids = attributes_obj.search(cr, uid, [], context=request.context)
|
||||
attributes = attributes_obj.browse(cr, uid, attributes_ids, context=request.context)
|
||||
|
||||
values = {
|
||||
'search': search,
|
||||
'category': category and int(category),
|
||||
'attrib_set': attrib_set,
|
||||
'pager': pager,
|
||||
'pricelist': self.get_pricelist(),
|
||||
'products': products,
|
||||
'bins': table_compute().process(products),
|
||||
'rows': PPR,
|
||||
'range': range,
|
||||
'search': {
|
||||
'search': search,
|
||||
'category': category and int(category),
|
||||
'filters': filters,
|
||||
},
|
||||
'pager': pager,
|
||||
'styles': styles,
|
||||
'category': category,
|
||||
'categories': filter(lambda x: not x.parent_id, categories),
|
||||
'all_categories': categories,
|
||||
'Ecommerce': self, # TODO fp: Should be removed
|
||||
'categories': categs,
|
||||
'attributes': attributes,
|
||||
'keep': keep,
|
||||
'style_in_product': lambda style, product: style.id in [s.id for s in product.website_style_ids],
|
||||
'attrib_encode': lambda attribs: werkzeug.url_encode([('attrib',i) for i in attribs]),
|
||||
}
|
||||
|
||||
return request.website.render("website_sale.products", values)
|
||||
|
||||
@http.route(['/shop/product/<model("product.template"):product>'], type='http', auth="public", website=True, multilang=True)
|
||||
def product(self, product, search='', category='', filters='', **kwargs):
|
||||
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']
|
||||
|
||||
if category:
|
||||
category_obj = request.registry.get('product.public.category')
|
||||
category = category_obj.browse(request.cr, request.uid, int(category), context=request.context)
|
||||
|
||||
request.context['pricelist'] = self.get_pricelist()
|
||||
attrib_values = map(int,request.httprequest.args.getlist('attrib'))
|
||||
attrib_set = set(attrib_values)
|
||||
|
||||
keep = QueryURL('/shop', category=category and category.id, search=search, attrib=attrib_set)
|
||||
|
||||
category_ids = category_obj.search(cr, uid, [], context=context)
|
||||
category_list = category_obj.name_get(cr, uid, category_ids, context=context)
|
||||
category_list = sorted(category_list, key=lambda category: category[1])
|
||||
|
||||
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)
|
||||
|
||||
values = {
|
||||
'Ecommerce': self,
|
||||
'search': search,
|
||||
'category': category,
|
||||
'pricelist': self.get_pricelist(),
|
||||
'attrib_set': attrib_set,
|
||||
'keep': keep,
|
||||
'category_list': category_list,
|
||||
'main_object': product,
|
||||
'product': product,
|
||||
'category': category,
|
||||
'search': {
|
||||
'search': search,
|
||||
'category': category and int(category),
|
||||
'filters': filters,
|
||||
}
|
||||
}
|
||||
return request.website.render("website_sale.product", values)
|
||||
|
||||
@http.route(['/shop/product/<int:product_template_id>/comment'], type='http', auth="public", methods=['POST'], website=True)
|
||||
@http.route(['/shop/product/comment/<int:product_template_id>'], type='http', auth="public", methods=['POST'], website=True)
|
||||
def product_comment(self, product_template_id, **post):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
if post.get('comment'):
|
||||
|
@ -330,233 +215,186 @@ class Ecommerce(http.Controller):
|
|||
context=dict(context, mail_create_nosubcribe=True))
|
||||
return werkzeug.utils.redirect(request.httprequest.referrer + "#comments")
|
||||
|
||||
@http.route(['/shop/add_product'], type='http', auth="user", methods=['POST'], website=True, multilang=True)
|
||||
def add_product(self, name=None, category=0, **post):
|
||||
if not name:
|
||||
name = _("New Product")
|
||||
Product = request.registry.get('product.product')
|
||||
product_id = Product.create(request.cr, request.uid, {
|
||||
'name': name, 'public_categ_id': category
|
||||
}, context=request.context)
|
||||
product = Product.browse(request.cr, request.uid, product_id, context=request.context)
|
||||
|
||||
return request.redirect("/shop/product/%s?enable_editor=1" % slug(product.product_tmpl_id))
|
||||
|
||||
@http.route(['/shop/mycart'], type='http', auth="public", website=True, multilang=True)
|
||||
def mycart(self, **post):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
prod_obj = request.registry.get('product.product')
|
||||
|
||||
# must have a draft sale order with lines at this point, otherwise reset
|
||||
order = self.get_order()
|
||||
if order and order.state != 'draft':
|
||||
request.registry['website'].ecommerce_reset(cr, uid, context=context)
|
||||
return request.redirect('/shop')
|
||||
|
||||
self.get_pricelist()
|
||||
|
||||
suggested_ids = []
|
||||
product_ids = []
|
||||
if order:
|
||||
for line in order.order_line:
|
||||
suggested_ids += [p.id for p in line.product_id and line.product_id.accessory_product_ids or []]
|
||||
product_ids.append(line.product_id.id)
|
||||
suggested_ids = list(set(suggested_ids) - set(product_ids))
|
||||
if suggested_ids:
|
||||
suggested_ids = prod_obj.search(cr, uid, [('id', 'in', suggested_ids)], context=context)
|
||||
|
||||
# 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))
|
||||
|
||||
context = dict(context or {}, pricelist=request.registry['website'].ecommerce_get_pricelist_id(cr, uid, None, context=context))
|
||||
|
||||
@http.route(['/shop/cart'], type='http', auth="public", website=True, multilang=True)
|
||||
def cart(self, **post):
|
||||
order = request.website.sale_get_order()
|
||||
values = {
|
||||
'int': int,
|
||||
'suggested_products': prod_obj.browse(cr, uid, suggested_products, context),
|
||||
'order': order,
|
||||
'suggested_products': [],
|
||||
}
|
||||
return request.website.render("website_sale.mycart", values)
|
||||
if order:
|
||||
if not request.context.get('pricelist'):
|
||||
request.context['pricelist'] = order.pricelist_id.id
|
||||
values['suggested_products'] = order._cart_accessories(context=request.context)
|
||||
return request.website.render("website_sale.cart", values)
|
||||
|
||||
@http.route(['/shop/add_cart'], type='http', auth="public", methods=['POST'], website=True, multilang=True)
|
||||
def add_cart(self, product_id, remove=None, **kw):
|
||||
request.registry['website']._ecommerce_add_product_to_cart(request.cr, request.uid,
|
||||
product_id=int(product_id),
|
||||
number=float(kw.get('number',1)),
|
||||
set_number=float(kw.get('set_number',-1)),
|
||||
context=request.context)
|
||||
return request.redirect("/shop/mycart")
|
||||
@http.route(['/shop/cart/update'], type='http', auth="public", methods=['POST'], website=True, multilang=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)
|
||||
return request.redirect("/shop/cart")
|
||||
|
||||
@http.route(['/shop/change_cart/<int:order_line_id>'], type='http', auth="public", website=True, multilang=True)
|
||||
def add_cart_order_line(self, order_line_id=None, remove=None, **kw):
|
||||
request.registry['website']._ecommerce_add_product_to_cart(request.cr, request.uid,
|
||||
order_line_id=order_line_id, number=(remove and -1 or 1),
|
||||
context=request.context)
|
||||
return request.redirect("/shop/mycart")
|
||||
@http.route(['/shop/cart/update_json'], type='json', auth="public", methods=['POST'], website=True, multilang=True)
|
||||
def cart_update_json(self, product_id, line_id, add_qty=None, set_qty=None):
|
||||
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()
|
||||
})
|
||||
}
|
||||
|
||||
@http.route(['/shop/add_cart_json'], type='json', auth="public", website=True, multilang=True)
|
||||
def add_cart_json(self, product_id=None, order_line_id=None, remove=None):
|
||||
quantity = request.registry['website']._ecommerce_add_product_to_cart(request.cr, request.uid,
|
||||
product_id=product_id, order_line_id=order_line_id, number=(remove and -1 or 1),
|
||||
context=request.context)
|
||||
order = self.get_order()
|
||||
return [quantity,
|
||||
order.get_number_of_products(),
|
||||
order.amount_total,
|
||||
request.website._render("website_sale.total", {'website_sale_order': order})]
|
||||
#------------------------------------------------------
|
||||
# Checkout
|
||||
#------------------------------------------------------
|
||||
|
||||
@http.route(['/shop/set_cart_json'], type='json', auth="public", website=True, multilang=True)
|
||||
def set_cart_json(self, path=None, product_id=None, order_line_id=None, set_number=0, json=None):
|
||||
quantity = request.registry['website']._ecommerce_add_product_to_cart(request.cr, request.uid,
|
||||
product_id=product_id, order_line_id=order_line_id, set_number=set_number,
|
||||
context=request.context)
|
||||
order = self.get_order()
|
||||
return [quantity,
|
||||
order.get_number_of_products(),
|
||||
order.amount_total,
|
||||
request.website._render("website_sale.total", {'website_sale_order': order})]
|
||||
|
||||
@http.route(['/shop/checkout'], type='http', auth="public", website=True, multilang=True)
|
||||
def checkout(self, **post):
|
||||
def checkout_redirection(self, order):
|
||||
cr, uid, context, registry = request.cr, request.uid, request.context, request.registry
|
||||
|
||||
# must have a draft sale order with lines at this point, otherwise reset
|
||||
order = self.get_order()
|
||||
if not order or order.state != 'draft' or not order.order_line:
|
||||
request.registry['website'].ecommerce_reset(cr, uid, context=context)
|
||||
if not order or order.state != 'draft':
|
||||
request.website_sale_reset(cr, uid, context=context)
|
||||
return request.redirect('/shop')
|
||||
|
||||
# if transaction pending / done: redirect to confirmation
|
||||
tx = context.get('website_sale_transaction')
|
||||
if tx and tx.state != 'draft':
|
||||
return request.redirect('/shop/payment/confirmation/%s' % order.id)
|
||||
|
||||
self.get_pricelist()
|
||||
|
||||
def checkout_values(self, data=None):
|
||||
cr, uid, context, registry = request.cr, request.uid, request.context, request.registry
|
||||
orm_partner = registry.get('res.partner')
|
||||
orm_user = registry.get('res.users')
|
||||
orm_country = registry.get('res.country')
|
||||
state_orm = registry.get('res.country.state')
|
||||
|
||||
country_ids = orm_country.search(cr, SUPERUSER_ID, [], context=context)
|
||||
countries = orm_country.browse(cr, SUPERUSER_ID, country_ids, context)
|
||||
state_orm = registry.get('res.country.state')
|
||||
states_ids = state_orm.search(cr, SUPERUSER_ID, [], context=context)
|
||||
states = state_orm.browse(cr, SUPERUSER_ID, states_ids, context)
|
||||
|
||||
info = CheckoutInfo()
|
||||
checkout = {}
|
||||
if not data:
|
||||
if request.uid != request.website.user_id.id:
|
||||
partner = orm_user.browse(cr, SUPERUSER_ID, request.uid, context).partner_id
|
||||
checkout.update( self.checkout_parse("billing", partner) )
|
||||
|
||||
shipping_ids = orm_partner.search(cr, SUPERUSER_ID, [("parent_id", "=", partner.id), ('type', "=", 'delivery')], limit=1, context=context)
|
||||
if shipping_ids:
|
||||
shipping = orm_user.browse(cr, SUPERUSER_ID, request.uid, context)
|
||||
checkout.update( self.checkout_parse("shipping", shipping) )
|
||||
checkout['shipping_different'] = True
|
||||
else:
|
||||
order = request.website.sale_get_order(force_create=1, context=context)
|
||||
if order.partner_id:
|
||||
domain = [("active", "=", False), ("partner_id", "=", order.partner_id.id)]
|
||||
user_ids = request.registry['res.users'].search(cr, SUPERUSER_ID, domain, context=context)
|
||||
if not user_ids or request.website.user_id.id not in user_ids:
|
||||
checkout.update( self.checkout_parse("billing", order.partner_id) )
|
||||
else:
|
||||
checkout = self.checkout_parse('billing', data)
|
||||
if data.get("shipping_different"):
|
||||
checkout.update(self.checkout_parse('shipping', data))
|
||||
checkout["shipping_different"] = True
|
||||
|
||||
values = {
|
||||
'countries': countries,
|
||||
'states': states,
|
||||
'checkout': info.empty(),
|
||||
'shipping': post.get("shipping_different"),
|
||||
'checkout': checkout,
|
||||
'shipping_different': checkout.get('shipping_different'),
|
||||
'error': {},
|
||||
}
|
||||
checkout = values['checkout']
|
||||
return values
|
||||
|
||||
partner = None
|
||||
public_id = request.registry['website'].get_public_user(cr, uid, context)
|
||||
if request.uid != public_id:
|
||||
partner = orm_user.browse(cr, uid, uid, context).partner_id
|
||||
elif order.partner_id:
|
||||
public_partner = orm_user.browse(cr, SUPERUSER_ID, public_id, context=context).partner_id.id
|
||||
if public_partner != order.partner_id.id:
|
||||
partner = orm_partner.browse(cr, SUPERUSER_ID, order.partner_id.id, context)
|
||||
mandatory_billing_fields = ["name", "phone", "email", "street", "city", "country_id", "zip"]
|
||||
optional_billing_fields = ["street2", "state_id"]
|
||||
mandatory_shipping_fields = ["name", "phone", "street", "city", "country_id", "zip"]
|
||||
optional_shipping_fields = ["state_id"]
|
||||
|
||||
if partner:
|
||||
partner_info = info.from_partner(partner)
|
||||
checkout.update(partner_info)
|
||||
shipping_ids = orm_partner.search(cr, SUPERUSER_ID, [("parent_id", "=", partner.id), ('type', "=", 'delivery')], limit=1, context=context)
|
||||
if shipping_ids:
|
||||
values['shipping'] = "true"
|
||||
shipping_partner = orm_partner.browse(cr, SUPERUSER_ID, shipping_ids[0], context)
|
||||
checkout.update(info.from_partner(shipping_partner, address_type='shipping'))
|
||||
def checkout_parse(self, address_type, data, remove_prefix=False):
|
||||
""" data is a dict OR a partner browse record
|
||||
"""
|
||||
# set mandatory and optional fields
|
||||
assert address_type in ('billing', 'shipping')
|
||||
if address_type == 'billing':
|
||||
all_fields = self.mandatory_billing_fields + self.optional_billing_fields
|
||||
prefix = ''
|
||||
else:
|
||||
all_fields = self.mandatory_shipping_fields + self.optional_shipping_fields
|
||||
prefix = 'shipping_'
|
||||
|
||||
return request.website.render("website_sale.checkout", values)
|
||||
# set data
|
||||
if isinstance(data, dict):
|
||||
query = dict((prefix + field_name, data[prefix + field_name])
|
||||
for field_name in all_fields if data.get(prefix + field_name))
|
||||
else:
|
||||
query = dict((prefix + field_name, getattr(data, field_name))
|
||||
for field_name in all_fields if field_name != "street2" and getattr(data, field_name))
|
||||
if data.parent_id:
|
||||
query[prefix + 'street2'] = data.parent_id.name
|
||||
|
||||
@http.route(['/shop/confirm_order'], type='http', auth="public", website=True, multilang=True)
|
||||
def confirm_order(self, **post):
|
||||
if query.get(prefix + 'state_id'):
|
||||
query[prefix + 'state_id'] = int(query[prefix + 'state_id'])
|
||||
if query.get(prefix + 'country_id'):
|
||||
query[prefix + 'country_id'] = int(query[prefix + 'country_id'])
|
||||
|
||||
if not remove_prefix:
|
||||
return query
|
||||
|
||||
return dict((field_name, data[prefix + field_name]) for field_name in all_fields if data.get(prefix + field_name))
|
||||
|
||||
def checkout_form_validate(self, data):
|
||||
cr, uid, context, registry = request.cr, request.uid, request.context, request.registry
|
||||
order_line_obj = request.registry.get('sale.order')
|
||||
|
||||
# must have a draft sale order with lines at this point, otherwise redirect to shop
|
||||
order = self.get_order()
|
||||
if not order or order.state != 'draft' or not order.order_line:
|
||||
request.registry['website'].ecommerce_reset(cr, uid, context=context)
|
||||
return request.redirect('/shop')
|
||||
# if transaction pending / done: redirect to confirmation
|
||||
tx = context.get('website_sale_transaction')
|
||||
if tx and tx.state != 'draft':
|
||||
return request.redirect('/shop/payment/confirmation/%s' % order.id)
|
||||
# Validation
|
||||
error = dict()
|
||||
for field_name in self.mandatory_billing_fields:
|
||||
if not data.get(field_name):
|
||||
error[field_name] = 'missing'
|
||||
|
||||
if data.get("shipping_different"):
|
||||
for field_name in self.mandatory_shipping_fields:
|
||||
field_name = 'shipping_' + field_name
|
||||
if not data.get(field_name):
|
||||
error[field_name] = 'missing'
|
||||
|
||||
return error
|
||||
|
||||
def checkout_form_save(self, checkout):
|
||||
cr, uid, context, registry = request.cr, request.uid, request.context, request.registry
|
||||
|
||||
order = request.website.sale_get_order(force_create=1, context=context)
|
||||
|
||||
orm_partner = registry.get('res.partner')
|
||||
orm_user = registry.get('res.users')
|
||||
orm_country = registry.get('res.country')
|
||||
country_ids = orm_country.search(cr, SUPERUSER_ID, [], context=context)
|
||||
countries = orm_country.browse(cr, SUPERUSER_ID, country_ids, context)
|
||||
orm_state = registry.get('res.country.state')
|
||||
states_ids = orm_state.search(cr, SUPERUSER_ID, [], context=context)
|
||||
states = orm_state.browse(cr, SUPERUSER_ID, states_ids, context)
|
||||
order_obj = request.registry.get('sale.order')
|
||||
|
||||
info = CheckoutInfo()
|
||||
values = {
|
||||
'countries': countries,
|
||||
'states': states,
|
||||
'checkout': info.empty(),
|
||||
'shipping': post.get("shipping_different"),
|
||||
'error': {},
|
||||
}
|
||||
checkout = values['checkout']
|
||||
checkout.update(post)
|
||||
error = values['error']
|
||||
|
||||
for field_name in info.mandatory_billing_fields:
|
||||
if not checkout[field_name]:
|
||||
error[field_name] = 'missing'
|
||||
if post.get("shipping_different"):
|
||||
for field_name in info.mandatory_shipping_fields:
|
||||
if not checkout[field_name]:
|
||||
error[field_name] = 'missing'
|
||||
if error:
|
||||
return request.website.render("website_sale.checkout", values)
|
||||
|
||||
billing_info = dict((k, v) for k,v in checkout.items() if "shipping_" not in k and k != "company")
|
||||
billing_info = self.checkout_parse('billing', checkout, True)
|
||||
|
||||
# set partner_id
|
||||
partner_id = None
|
||||
public_id = request.registry['website'].get_public_user(cr, uid, context)
|
||||
if request.uid != public_id:
|
||||
if request.uid != request.website.user_id.id:
|
||||
partner_id = orm_user.browse(cr, SUPERUSER_ID, uid, context=context).partner_id.id
|
||||
elif order.partner_id:
|
||||
public_partner = orm_user.browse(cr, SUPERUSER_ID, public_id, context=context).partner_id.id
|
||||
if public_partner != order.partner_id.id:
|
||||
user_ids = request.registry['res.users'].search(cr, SUPERUSER_ID,
|
||||
[("partner_id", "=", order.partner_id.id)], context=dict(context or {}, active_test=False))
|
||||
if not user_ids or request.website.user_id.id not in user_ids:
|
||||
partner_id = order.partner_id.id
|
||||
|
||||
if partner_id:
|
||||
# save partner informations
|
||||
if partner_id and request.website.partner_id.id != partner_id:
|
||||
orm_partner.write(cr, SUPERUSER_ID, [partner_id], billing_info, context=context)
|
||||
else:
|
||||
partner_id = orm_partner.create(cr, SUPERUSER_ID, billing_info, context=context)
|
||||
|
||||
# create a new shipping partner
|
||||
shipping_id = None
|
||||
if post.get('shipping_different'):
|
||||
shipping_info = {
|
||||
'phone': post['shipping_phone'],
|
||||
'zip': post['shipping_zip'],
|
||||
'street': checkout['company'],
|
||||
'street2': post['shipping_street'],
|
||||
'city': post['shipping_city'],
|
||||
'name': post['shipping_name'],
|
||||
'email': post['email'],
|
||||
'type': 'delivery',
|
||||
'parent_id': partner_id,
|
||||
'country_id': post['shipping_country_id'],
|
||||
'state_id': post['shipping_state_id'],
|
||||
}
|
||||
domain = [(key, '_id' in key and '=' or 'ilike', '_id' in key and value and int(value) or value)
|
||||
for key, value in shipping_info.items() if key in info.mandatory_billing_fields + ["type", "parent_id"]]
|
||||
|
||||
shipping_ids = orm_partner.search(cr, SUPERUSER_ID, domain, context=context)
|
||||
if shipping_ids:
|
||||
shipping_id = shipping_ids[0]
|
||||
orm_partner.write(cr, SUPERUSER_ID, [shipping_id], shipping_info, context)
|
||||
else:
|
||||
if checkout.get('shipping_different'):
|
||||
shipping_info = self.checkout_parse('shipping', checkout, True)
|
||||
shipping_info['type'] = 'delivery'
|
||||
shipping_info['parent_id'] = partner_id
|
||||
shipping_id = orm_partner.create(cr, SUPERUSER_ID, shipping_info, context)
|
||||
|
||||
order_info = {
|
||||
|
@ -568,10 +406,47 @@ class Ecommerce(http.Controller):
|
|||
order_info.update(registry.get('sale.order').onchange_partner_id(cr, SUPERUSER_ID, [], partner_id, context=context)['value'])
|
||||
order_info.pop('user_id')
|
||||
|
||||
order_line_obj.write(cr, SUPERUSER_ID, [order.id], order_info, context=context)
|
||||
order_obj.write(cr, SUPERUSER_ID, [order.id], order_info, context=context)
|
||||
|
||||
@http.route(['/shop/checkout'], type='http', auth="public", website=True, multilang=True)
|
||||
def checkout(self, **post):
|
||||
cr, uid, context, registry = request.cr, request.uid, request.context, request.registry
|
||||
|
||||
order = request.website.sale_get_order(force_create=1, context=context)
|
||||
|
||||
redirection = self.checkout_redirection(order)
|
||||
if redirection:
|
||||
return redirection
|
||||
|
||||
values = self.checkout_values()
|
||||
|
||||
return request.website.render("website_sale.checkout", values)
|
||||
|
||||
@http.route(['/shop/confirm_order'], type='http', auth="public", website=True, multilang=True)
|
||||
def confirm_order(self, **post):
|
||||
cr, uid, context, registry = request.cr, request.uid, request.context, request.registry
|
||||
|
||||
order = request.website.sale_get_order(context=context)
|
||||
|
||||
redirection = self.checkout_redirection(order)
|
||||
if redirection:
|
||||
return redirection
|
||||
|
||||
values = self.checkout_values(post)
|
||||
|
||||
values["error"] = self.checkout_form_validate(values["checkout"])
|
||||
if values["error"]:
|
||||
return request.website.render("website_sale.checkout", values)
|
||||
|
||||
self.checkout_form_save(values["checkout"])
|
||||
request.session['sale_last_order_id'] = order.id
|
||||
|
||||
return request.redirect("/shop/payment")
|
||||
|
||||
#------------------------------------------------------
|
||||
# Payment
|
||||
#------------------------------------------------------
|
||||
|
||||
@http.route(['/shop/payment'], type='http', auth="public", website=True, multilang=True)
|
||||
def payment(self, **post):
|
||||
""" Payment step. This page proposes several payment means based on available
|
||||
|
@ -585,17 +460,12 @@ class Ecommerce(http.Controller):
|
|||
"""
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
payment_obj = request.registry.get('payment.acquirer')
|
||||
sale_order_obj = request.registry['sale.order']
|
||||
|
||||
# if no sale order at this stage: back to checkout beginning
|
||||
order = self.get_order()
|
||||
if not order or order.state != 'draft' or not order.order_line:
|
||||
request.registry['website'].ecommerce_reset(cr, uid, context=context)
|
||||
return request.redirect("/shop")
|
||||
# alread a transaction: forward to confirmation
|
||||
tx = context.get('website_sale_transaction')
|
||||
if tx and tx.state != 'draft':
|
||||
return request.redirect('/shop/confirmation/%s' % order.id)
|
||||
order = request.website.sale_get_order(context=context)
|
||||
|
||||
redirection = self.checkout_redirection(order)
|
||||
if redirection:
|
||||
return redirection
|
||||
|
||||
shipping_partner_id = False
|
||||
if order:
|
||||
|
@ -604,17 +474,16 @@ class Ecommerce(http.Controller):
|
|||
else:
|
||||
shipping_partner_id = order.partner_invoice_id.id
|
||||
|
||||
values = {}
|
||||
values['website_sale_order'] = values['order'] = sale_order_obj.browse(cr, SUPERUSER_ID, order.id, context=context)
|
||||
values['errors'] = sale_order_obj._get_errors(cr, uid, order, context=context)
|
||||
values.update(sale_order_obj._get_website_data(cr, uid, order, context=context))
|
||||
values = {
|
||||
'order': request.registry['sale.order'].browse(cr, SUPERUSER_ID, order.id, context=context)
|
||||
}
|
||||
values.update(request.registry.get('sale.order')._get_website_data(cr, uid, order, context))
|
||||
|
||||
if not values['errors']:
|
||||
# fetch all registered payment means
|
||||
if tx:
|
||||
acquirer_ids = [tx.acquirer_id.id]
|
||||
else:
|
||||
acquirer_ids = payment_obj.search(cr, SUPERUSER_ID, [('website_published', '=', True), '|', ('company_id', '=', order.company_id.id), ('company_id', '=', False)], context=context)
|
||||
# if tx:
|
||||
# acquirer_ids = [tx.acquirer_id.id]
|
||||
# else:
|
||||
acquirer_ids = payment_obj.search(cr, SUPERUSER_ID, [('website_published', '=', True)], context=context)
|
||||
values['acquirers'] = payment_obj.browse(cr, uid, acquirer_ids, context=context)
|
||||
render_ctx = dict(context, submit_class='btn btn-primary', submit_txt='Pay Now')
|
||||
for acquirer in values['acquirers']:
|
||||
|
@ -632,8 +501,7 @@ class Ecommerce(http.Controller):
|
|||
|
||||
return request.website.render("website_sale.payment", values)
|
||||
|
||||
@http.route(['/shop/payment/transaction/<int:acquirer_id>'],
|
||||
type='http', methods=['POST'], auth="public", website=True)
|
||||
@http.route(['/shop/payment/transaction/<int:acquirer_id>'], type='http', methods=['POST'], auth="public", website=True)
|
||||
def payment_transaction(self, acquirer_id, **post):
|
||||
""" Hook method that creates a payment.transaction and redirect to the
|
||||
acquirer, using post values to re-create the post action.
|
||||
|
@ -648,13 +516,15 @@ class Ecommerce(http.Controller):
|
|||
cr, uid, context = request.cr, request.uid, request.context
|
||||
payment_obj = request.registry.get('payment.acquirer')
|
||||
transaction_obj = request.registry.get('payment.transaction')
|
||||
order = self.get_order()
|
||||
order = request.website.sale_get_order(context=context)
|
||||
|
||||
if not order or not order.order_line or acquirer_id is None:
|
||||
return request.redirect("/shop/checkout")
|
||||
|
||||
assert order.partner_id.id != request.website.partner_id.id
|
||||
|
||||
# find an already existing transaction
|
||||
tx = context.get('website_sale_transaction')
|
||||
tx = request.website.sale_get_transaction()
|
||||
if not tx:
|
||||
tx_id = transaction_obj.create(cr, SUPERUSER_ID, {
|
||||
'acquirer_id': acquirer_id,
|
||||
|
@ -662,11 +532,12 @@ class Ecommerce(http.Controller):
|
|||
'amount': order.amount_total,
|
||||
'currency_id': order.pricelist_id.currency_id.id,
|
||||
'partner_id': order.partner_id.id,
|
||||
'partner_country_id': order.partner_id.country_id.id,
|
||||
'reference': order.name,
|
||||
'sale_order_id': order.id,
|
||||
}, context=context)
|
||||
request.session['website_sale_transaction_id'] = tx_id
|
||||
elif tx and tx.state == 'draft': # button cliked but no more info -> rewrite on tx or create a new one ?
|
||||
request.session['sale_transaction_id'] = tx_id
|
||||
elif tx.state == 'draft': # button cliked but no more info -> rewrite on tx or create a new one ?
|
||||
tx.write({
|
||||
'acquirer_id': acquirer_id,
|
||||
})
|
||||
|
@ -680,7 +551,7 @@ class Ecommerce(http.Controller):
|
|||
cr, uid, context = request.cr, request.uid, request.context
|
||||
|
||||
order = request.registry['sale.order'].browse(cr, SUPERUSER_ID, sale_order_id, context=context)
|
||||
assert order.website_session_id == request.session['website_session_id']
|
||||
assert order.id == request.session.get('sale_last_order_id')
|
||||
|
||||
if not order:
|
||||
return {
|
||||
|
@ -732,24 +603,22 @@ class Ecommerce(http.Controller):
|
|||
- UDPATE ME
|
||||
"""
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
sale_order_obj = request.registry['sale.order']
|
||||
email_act = None
|
||||
sale_order_obj = request.registry['sale.order']
|
||||
|
||||
if transaction_id is None:
|
||||
tx = context.get('website_sale_transaction')
|
||||
tx = request.website.sale_get_transaction()
|
||||
else:
|
||||
tx = request.registry['payment.transaction'].browse(cr, uid, transaction_id, context=context)
|
||||
|
||||
if sale_order_id is None:
|
||||
order = self.get_order()
|
||||
order = request.website.sale_get_order(context=context)
|
||||
else:
|
||||
order = request.registry['sale.order'].browse(cr, SUPERUSER_ID, sale_order_id, context=context)
|
||||
assert order.website_session_id == request.session['website_session_id']
|
||||
assert order.id == request.session.get('sale_last_order_id')
|
||||
|
||||
if not order:
|
||||
if not tx or not order:
|
||||
return request.redirect('/shop')
|
||||
elif order.amount_total and not tx:
|
||||
return request.redirect('/shop/mycart')
|
||||
|
||||
if not order.amount_total or tx.state == 'done':
|
||||
# confirm the quotation
|
||||
|
@ -763,23 +632,13 @@ class Ecommerce(http.Controller):
|
|||
# cancel the quotation
|
||||
sale_order_obj.action_cancel(cr, SUPERUSER_ID, [order.id], context=request.context)
|
||||
|
||||
# send the email
|
||||
if email_act and email_act.get('context'):
|
||||
composer_values = {}
|
||||
email_ctx = email_act['context']
|
||||
public_id = request.registry['website'].get_public_user(cr, uid, context)
|
||||
if uid == public_id:
|
||||
composer_values['email_from'] = request.registry['res.users'].browse(cr, SUPERUSER_ID, public_id, context=context).company_id.email
|
||||
composer_id = request.registry['mail.compose.message'].create(cr, SUPERUSER_ID, composer_values, context=email_ctx)
|
||||
request.registry['mail.compose.message'].send_mail(cr, SUPERUSER_ID, [composer_id], context=email_ctx)
|
||||
|
||||
# clean context and session, then redirect to the confirmation page
|
||||
request.registry['website'].ecommerce_reset(cr, uid, context=context)
|
||||
request.website.sale_reset(context=context)
|
||||
|
||||
return request.redirect('/shop/confirmation/%s' % order.id)
|
||||
return request.redirect('/shop/confirmation')
|
||||
|
||||
@http.route(['/shop/confirmation/<int:sale_order_id>'], type='http', auth="public", website=True, multilang=True)
|
||||
def payment_confirmation(self, sale_order_id, **post):
|
||||
@http.route(['/shop/confirmation'], type='http', auth="public", website=True, multilang=True)
|
||||
def payment_confirmation(self, **post):
|
||||
""" End of checkout process controller. Confirmation is basically seing
|
||||
the status of a sale.order. State at this point :
|
||||
|
||||
|
@ -789,24 +648,32 @@ class Ecommerce(http.Controller):
|
|||
"""
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
|
||||
sale_order_id = request.session.get('sale_last_order_id')
|
||||
if sale_order_id:
|
||||
order = request.registry['sale.order'].browse(cr, SUPERUSER_ID, sale_order_id, context=context)
|
||||
assert order.website_session_id == request.session['website_session_id']
|
||||
|
||||
request.registry['website']._ecommerce_change_pricelist(cr, uid, None, context=context or {})
|
||||
else:
|
||||
return request.redirect('/shop')
|
||||
|
||||
return request.website.render("website_sale.confirmation", {'order': order})
|
||||
|
||||
@http.route(['/shop/change_sequence'], type='json', auth="public")
|
||||
def change_sequence(self, id, sequence):
|
||||
product_obj = request.registry.get('product.template')
|
||||
if sequence == "top":
|
||||
product_obj.set_sequence_top(request.cr, request.uid, [id], context=request.context)
|
||||
elif sequence == "bottom":
|
||||
product_obj.set_sequence_bottom(request.cr, request.uid, [id], context=request.context)
|
||||
elif sequence == "up":
|
||||
product_obj.set_sequence_up(request.cr, request.uid, [id], context=request.context)
|
||||
elif sequence == "down":
|
||||
product_obj.set_sequence_down(request.cr, request.uid, [id], context=request.context)
|
||||
#------------------------------------------------------
|
||||
# Edit
|
||||
#------------------------------------------------------
|
||||
|
||||
@http.route(['/shop/add_product'], type='http', auth="user", methods=['POST'], website=True, multilang=True)
|
||||
def add_product(self, name=None, category=0, **post):
|
||||
cr, uid, context, pool = request.cr, request.uid, request.context, request.registry
|
||||
if not name:
|
||||
name = _("New Product")
|
||||
product_obj = request.registry.get('product.product')
|
||||
product_id = product_obj.create(cr, uid, { 'name': name, 'public_categ_id': category }, context=context)
|
||||
product = product_obj.browse(cr, uid, product_id, context=context)
|
||||
|
||||
return request.redirect("/shop/product/%s?enable_editor=1" % slug(product.product_tmpl_id))
|
||||
|
||||
@http.route(['/shop/reorder'], type='json', auth="public")
|
||||
def reorder(self, product_id, operation):
|
||||
request.registry['product.template'].website_reorder(request.cr, request.uid, [id], operation, context=request.context)
|
||||
|
||||
@http.route(['/shop/change_styles'], type='json', auth="public")
|
||||
def change_styles(self, id, style_id):
|
||||
|
@ -836,4 +703,5 @@ class Ecommerce(http.Controller):
|
|||
product = product_obj.browse(request.cr, request.uid, id, context=request.context)
|
||||
return product.write({'website_size_x': x, 'website_size_y': y})
|
||||
|
||||
|
||||
# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<data noupdate="1">
|
||||
|
||||
<record id="product.group_product_attributes" model="res.groups">
|
||||
<field name="name">Product attribute (not supported)</field>
|
||||
<field name="name">Product Attributes</field>
|
||||
<field name="category_id" ref="base.module_category_hidden"/>
|
||||
</record>
|
||||
|
|
@ -1,7 +1,3 @@
|
|||
import website_styles
|
||||
import payment_transaction
|
||||
import product
|
||||
import product_characteristics
|
||||
import res_config
|
||||
import sale_order
|
||||
import website
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from openerp.osv import orm, fields
|
||||
|
||||
|
||||
class PaymentTransaction(orm.Model):
|
||||
_inherit = 'payment.transaction'
|
||||
|
||||
_columns = {
|
||||
# link with the sale order
|
||||
'sale_order_id': fields.many2one('sale.order', 'Sale Order'),
|
||||
}
|
|
@ -21,6 +21,39 @@
|
|||
|
||||
from openerp.osv import osv, fields
|
||||
|
||||
class product_attribue(osv.Model):
|
||||
# TODO merge product.attribute, mrp.properties product_manufacturer_attributes
|
||||
_name = "product.attribute"
|
||||
_columns = {
|
||||
'name': fields.char('Name', translate=True, required=True),
|
||||
'value_ids': fields.one2many('product.attribute.value', 'attribute_id', 'Values'),
|
||||
}
|
||||
|
||||
class product_attribute_value(osv.Model):
|
||||
_name = "product.attribute.value"
|
||||
_columns = {
|
||||
'attribute_id': fields.many2one('product.attribute', 'attribute', required=True),
|
||||
'name': fields.char('Value', translate=True, required=True),
|
||||
}
|
||||
|
||||
class product_attribute_line(osv.Model):
|
||||
_name = "product.attribute.line"
|
||||
_order = 'attribute_id, value_id'
|
||||
_columns = {
|
||||
'product_tmpl_id': fields.many2one('product.template', 'Product', required=True),
|
||||
'attribute_id': fields.many2one('product.attribute', 'attribute', required=True),
|
||||
'value_id': fields.many2one('product.attribute.value', 'Textual Value'),
|
||||
}
|
||||
|
||||
def onchange_attribute_id(self, cr, uid, ids, attribute_id, context=None):
|
||||
return {'value': {'value_id': False}}
|
||||
|
||||
class product_style(osv.Model):
|
||||
_name = "product.style"
|
||||
_columns = {
|
||||
'name' : fields.char('Style Name', required=True),
|
||||
'html_class': fields.char('HTML Classes'),
|
||||
}
|
||||
|
||||
class product_pricelist(osv.Model):
|
||||
_inherit = "product.pricelist"
|
||||
|
@ -28,7 +61,6 @@ class product_pricelist(osv.Model):
|
|||
'code': fields.char('Promotional Code'),
|
||||
}
|
||||
|
||||
|
||||
class product_template(osv.Model):
|
||||
_inherit = ["product.template", "website.seo.metadata"]
|
||||
_order = 'website_published desc, website_sequence desc, name'
|
||||
|
@ -36,55 +68,51 @@ class product_template(osv.Model):
|
|||
|
||||
def _website_url(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = dict.fromkeys(ids, '')
|
||||
base_url = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url')
|
||||
for product in self.browse(cr, uid, ids, context=context):
|
||||
res[product.id] = "%s/shop/product/%s" % (base_url, product.id)
|
||||
res[product.id] = "/shop/product/%s" % (product.id,)
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'website_published': fields.boolean('Available in the website'),
|
||||
'website_description': fields.html('Description for the website'),
|
||||
# TDE TODO FIXME: when website_mail/mail_thread.py inheritance work -> this field won't be necessary
|
||||
'attribute_lines': fields.one2many('product.attribute.line', 'product_tmpl_id', 'Product attributes'),
|
||||
# TODO FIXME tde: when website_mail/mail_thread.py inheritance work -> this field won't be necessary
|
||||
'website_message_ids': fields.one2many(
|
||||
'mail.message', 'res_id',
|
||||
domain=lambda self: [
|
||||
'&', ('model', '=', self._name), ('type', '=', 'comment')
|
||||
],
|
||||
string='Website Messages',
|
||||
help="Website communication history",
|
||||
string='Website Comments',
|
||||
),
|
||||
'website_published': fields.boolean('Available in the website'),
|
||||
'website_description': fields.html('Description for the website'),
|
||||
'alternative_product_ids': fields.many2many('product.template','product_alternative_rel','src_id','dest_id', string='Alternative Products', help='Appear on the product page'),
|
||||
'accessory_product_ids': fields.many2many('product.template','product_accessory_rel','src_id','dest_id', string='Accessory Products', help='Appear on the shopping cart'),
|
||||
'website_size_x': fields.integer('Size X'),
|
||||
'website_size_y': fields.integer('Size Y'),
|
||||
'website_style_ids': fields.many2many('product.style', 'product_website_style_rel', 'product_id', 'style_id', 'Styles'),
|
||||
'website_style_ids': fields.many2many('product.style', string='Styles'),
|
||||
'website_sequence': fields.integer('Sequence', help="Determine the display order in the Website E-commerce"),
|
||||
'website_url': fields.function(_website_url, string="Website url", type="char"),
|
||||
}
|
||||
|
||||
def __defaults_website_sequence(self, cr, uid, *kwargs):
|
||||
cr.execute('SELECT MAX(website_sequence) FROM product_template')
|
||||
max_sequence = cr.fetchone()[0] or 0
|
||||
return max_sequence + 1
|
||||
def _defaults_website_sequence(self, cr, uid, *l, **kwargs):
|
||||
cr.execute('SELECT MAX(website_sequence)+1 FROM product_template')
|
||||
next_sequence = cr.fetchone()[0] or 0
|
||||
return next_sequence
|
||||
|
||||
_defaults = {
|
||||
'website_size_x': 1,
|
||||
'website_size_y': 1,
|
||||
'website_sequence': __defaults_website_sequence,
|
||||
'website_sequence': _defaults_website_sequence,
|
||||
'website_published': False,
|
||||
}
|
||||
|
||||
def set_sequence_top(self, cr, uid, ids, context=None):
|
||||
def website_reorder(self, cr, uid, ids, operation=None, context=None):
|
||||
if operation == "top":
|
||||
cr.execute('SELECT MAX(website_sequence) FROM product_template')
|
||||
max_sequence = cr.fetchone()[0] or 0
|
||||
return self.write(cr, uid, ids, {'website_sequence': max_sequence + 1}, context=context)
|
||||
|
||||
def set_sequence_bottom(self, cr, uid, ids, context=None):
|
||||
seq = (cr.fetchone()[0] or 0) + 1
|
||||
if operation == "bottom":
|
||||
cr.execute('SELECT MIN(website_sequence) FROM product_template')
|
||||
min_sequence = cr.fetchone()[0] or 0
|
||||
return self.write(cr, uid, ids, {'website_sequence': min_sequence -1}, context=context)
|
||||
|
||||
def set_sequence_up(self, cr, uid, ids, context=None):
|
||||
seq = (cr.fetchone()[0] or 0) -1
|
||||
if operation == "up":
|
||||
product = self.browse(cr, uid, ids[0], context=context)
|
||||
cr.execute(""" SELECT id, website_sequence FROM product_template
|
||||
WHERE website_sequence > %s AND website_published = %s ORDER BY website_sequence ASC LIMIT 1""" % (product.website_sequence, product.website_published))
|
||||
|
@ -93,9 +121,8 @@ class product_template(osv.Model):
|
|||
self.write(cr, uid, [prev[0]], {'website_sequence': product.website_sequence}, context=context)
|
||||
return self.write(cr, uid, [ids[0]], {'website_sequence': prev[1]}, context=context)
|
||||
else:
|
||||
return self.set_sequence_top(cr, uid, ids, context=context)
|
||||
|
||||
def set_sequence_down(self, cr, uid, ids, context=None):
|
||||
return self.website_reorder(cr, uid, ids, operation='top', context=context)
|
||||
if operation == "down":
|
||||
product = self.browse(cr, uid, ids[0], context=context)
|
||||
cr.execute(""" SELECT id, website_sequence FROM product_template
|
||||
WHERE website_sequence < %s AND website_published = %s ORDER BY website_sequence DESC LIMIT 1""" % (product.website_sequence, product.website_published))
|
||||
|
@ -104,42 +131,19 @@ class product_template(osv.Model):
|
|||
self.write(cr, uid, [next[0]], {'website_sequence': product.website_sequence}, context=context)
|
||||
return self.write(cr, uid, [ids[0]], {'website_sequence': next[1]}, context=context)
|
||||
else:
|
||||
return self.set_sequence_bottom(cr, uid, ids, context=context)
|
||||
|
||||
def recommended_products(self, cr, uid, ids, context=None):
|
||||
id = ids[0]
|
||||
product_ids = []
|
||||
query = """
|
||||
SELECT sol.product_id
|
||||
FROM sale_order_line as my
|
||||
LEFT JOIN sale_order_line as sol
|
||||
ON sol.order_id = my.order_id
|
||||
WHERE my.product_id in (%s)
|
||||
AND sol.product_id not in (%s)
|
||||
GROUP BY sol.product_id
|
||||
ORDER BY COUNT(sol.order_id) DESC
|
||||
LIMIT 10
|
||||
"""
|
||||
cr.execute(query, (id, id))
|
||||
for p in cr.fetchall():
|
||||
product_ids.append(p[0])
|
||||
|
||||
# search to apply access rules
|
||||
product_ids = self.search(cr, uid, [("id", "in", product_ids)], limit=3)
|
||||
return self.browse(cr, uid, product_ids)
|
||||
return self.website_reorder(cr, uid, ids, operation='bottom', context=context)
|
||||
return self.write(cr, uid, ids, {'website_sequence': seq}, context=context)
|
||||
|
||||
def img(self, cr, uid, ids, field='image_small', context=None):
|
||||
return "/website/image?model=%s&field=%s&id=%s" % (self._name, field, ids[0])
|
||||
|
||||
|
||||
class product_product(osv.Model):
|
||||
_inherit = "product.product"
|
||||
|
||||
def _website_url(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = {}
|
||||
base_url = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url')
|
||||
for product in self.browse(cr, uid, ids, context=context):
|
||||
res[product.id] = "%s/shop/product/%s" % (base_url, product.product_tmpl_id.id)
|
||||
res[product.id] = "/shop/product/%s" % (product.product_tmpl_id.id,)
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
|
@ -149,3 +153,5 @@ class product_product(osv.Model):
|
|||
def img(self, cr, uid, ids, field='image_small', context=None):
|
||||
temp_id = self.browse(cr, uid, ids[0], context=context).product_tmpl_id.id
|
||||
return "/website/image?model=product.template&field=%s&id=%s" % (field, temp_id)
|
||||
|
||||
# vim:et:
|
||||
|
|
|
@ -1,87 +0,0 @@
|
|||
|
||||
from openerp.osv import osv, fields
|
||||
|
||||
|
||||
class attributes(osv.Model):
|
||||
_name = "product.attribute"
|
||||
|
||||
def _get_float_max(self, cr, uid, ids, field_name, arg, context=None):
|
||||
result = dict.fromkeys(ids, 0)
|
||||
if ids:
|
||||
cr.execute("""
|
||||
SELECT attribute_id, MAX(value)
|
||||
FROM product_attribute_line
|
||||
WHERE attribute_id in (%s)
|
||||
GROUP BY attribute_id
|
||||
""" % ",".join(map(str, ids)))
|
||||
result.update(dict(cr.fetchall()))
|
||||
return result
|
||||
|
||||
def _get_float_min(self, cr, uid, ids, field_name, arg, context=None):
|
||||
result = dict.fromkeys(ids, 0)
|
||||
if ids:
|
||||
cr.execute("""
|
||||
SELECT attribute_id, MIN(value)
|
||||
FROM product_attribute_line
|
||||
WHERE attribute_id in (%s)
|
||||
GROUP BY attribute_id
|
||||
""" % ",".join(map(str, ids)))
|
||||
result.update(dict(cr.fetchall()))
|
||||
return result
|
||||
|
||||
def _get_min_max(self, cr, uid, ids, context=None):
|
||||
result = {}
|
||||
for value in self.pool.get('product.attribute.line').browse(cr, uid, ids, context=context):
|
||||
if value.type == 'float':
|
||||
result[value.attribute_id.id] = True
|
||||
return result.keys()
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('Name', translate=True, required=True),
|
||||
'type': fields.selection([('distinct', 'Textual Value'), ('float', 'Numeric Value')], "Type", required=True),
|
||||
'value_ids': fields.one2many('product.attribute.value', 'attribute_id', 'Values'),
|
||||
'attr_product_ids': fields.one2many('product.attribute.line', 'attribute_id', 'Products'),
|
||||
|
||||
'float_max': fields.function(_get_float_max, type='float', string="Max", store={
|
||||
'product.attribute.line': (_get_min_max, ['value','attribute_id'], 20),
|
||||
}),
|
||||
'float_min': fields.function(_get_float_min, type='float', string="Min", store={
|
||||
'product.attribute.line': (_get_min_max, ['value','attribute_id'], 20),
|
||||
}),
|
||||
'visible': fields.boolean('Display Filter on Website'),
|
||||
}
|
||||
_defaults = {
|
||||
'type': 'distinct',
|
||||
'visible': True,
|
||||
}
|
||||
|
||||
class attributes_value(osv.Model):
|
||||
_name = "product.attribute.value"
|
||||
_columns = {
|
||||
'name': fields.char('Value', translate=True, required=True),
|
||||
'attribute_id': fields.many2one('product.attribute', 'attribute', required=True),
|
||||
'atr_product_ids': fields.one2many('product.attribute.line', 'value_id', 'Products'),
|
||||
}
|
||||
|
||||
class attributes_product(osv.Model):
|
||||
_name = "product.attribute.line"
|
||||
_order = 'attribute_id, value_id, value'
|
||||
_columns = {
|
||||
'value': fields.float('Numeric Value'),
|
||||
'value_id': fields.many2one('product.attribute.value', 'Textual Value'),
|
||||
'attribute_id': fields.many2one('product.attribute', 'attribute', required=True),
|
||||
'product_tmpl_id': fields.many2one('product.template', 'Product', required=True),
|
||||
|
||||
'type': fields.related('attribute_id', 'type', type='selection',
|
||||
selection=[('distinct', 'Distinct'), ('float', 'Float')], string='Type'),
|
||||
}
|
||||
|
||||
def onchange_attribute_id(self, cr, uid, ids, attribute_id, context=None):
|
||||
attribute = self.pool.get('product.attribute').browse(cr, uid, attribute_id, context=context)
|
||||
return {'value': {'type': attribute.type, 'value_id': False, 'value': ''}}
|
||||
|
||||
class product_template(osv.Model):
|
||||
_inherit = "product.template"
|
||||
_columns = {
|
||||
'attribute_lines': fields.one2many('product.attribute.line', 'product_tmpl_id', 'Product attributes'),
|
||||
}
|
|
@ -1,19 +1,34 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import random
|
||||
|
||||
from openerp import SUPERUSER_ID
|
||||
from openerp.osv import osv, fields
|
||||
from openerp.osv import osv, orm, fields
|
||||
from openerp.addons.web.http import request
|
||||
|
||||
|
||||
class SaleOrder(osv.Model):
|
||||
_inherit = "sale.order"
|
||||
class payment_transaction(orm.Model):
|
||||
_inherit = 'payment.transaction'
|
||||
|
||||
_columns = {
|
||||
# link with the sale order
|
||||
'sale_order_id': fields.many2one('sale.order', 'Sale Order'),
|
||||
}
|
||||
|
||||
class sale_order(osv.Model):
|
||||
_inherit = "sale.order"
|
||||
|
||||
def _cart_qty(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = dict();
|
||||
for order in self.browse(cr, uid, ids, context=context):
|
||||
res[order.id] = int(sum(l.product_uom_qty for l in (order.website_order_line or [])))
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'website_session_id': fields.char('Session UUID4'),
|
||||
'website_order_line': fields.one2many(
|
||||
'sale.order.line', 'order_id',
|
||||
string='Order Lines displayed on Website', readonly=True,
|
||||
help='Order Lines to be displayed on the website. They should not be used for computation purpose.',
|
||||
),
|
||||
'cart_quantity': fields.function(_cart_qty, type='integer', string='Main Menu'),
|
||||
}
|
||||
|
||||
def _get_errors(self, cr, uid, order, context=None):
|
||||
|
@ -25,30 +40,175 @@ class SaleOrder(osv.Model):
|
|||
'order': order
|
||||
}
|
||||
|
||||
def get_number_of_products(self, cr, uid, ids, context=None):
|
||||
order = self.browse(cr, uid, ids[0], context=context)
|
||||
return int(sum(l.product_uom_qty for l in (order.website_order_line or [])))
|
||||
def _cart_find_product_line(self, cr, uid, ids, product_id=None, line_id=None, context=None):
|
||||
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
|
||||
|
||||
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)
|
||||
|
||||
class SaleOrderLine(osv.Model):
|
||||
_inherit = "sale.order.line"
|
||||
|
||||
def _recalculate_product_values(self, cr, uid, ids, product_id=0, fiscal_position=False, context=None):
|
||||
# TDE FIXME: seems to be defined several times -> fix me ?
|
||||
if context is None:
|
||||
context = {}
|
||||
user_obj = self.pool.get('res.users')
|
||||
|
||||
if ids and not product_id:
|
||||
order_line = self.browse(cr, SUPERUSER_ID, ids[0], context=context)
|
||||
assert order_line.order_id.website_session_id == request.session['website_session_id']
|
||||
product_id = product_id or order_line.product_id.id
|
||||
|
||||
return self.product_id_change(
|
||||
cr, SUPERUSER_ID, ids,
|
||||
pricelist=context.pop('pricelist'),
|
||||
values = self.pool.get('sale.order.line').product_id_change(cr, SUPERUSER_ID, [],
|
||||
pricelist=so.pricelist_id.id,
|
||||
product=product_id,
|
||||
partner_id=user_obj.browse(cr, SUPERUSER_ID, uid).partner_id.id,
|
||||
fiscal_position=fiscal_position,
|
||||
partner_id=so.partner_id.id,
|
||||
context=context
|
||||
)['value']
|
||||
|
||||
if line_id:
|
||||
line = self.pool.get('sale.order.line').browse(cr, SUPERUSER_ID, line_id, context=context)
|
||||
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['product_id'] = product_id
|
||||
values['order_id'] = order_id
|
||||
if values.get('tax_id') != None:
|
||||
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):
|
||||
""" 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)
|
||||
|
||||
# Create line if no line with product_id can be located
|
||||
if not line_id:
|
||||
values = self._website_product_id_change(cr, uid, ids, so.id, product_id, context=context)
|
||||
line_id = sol.create(cr, SUPERUSER_ID, values, context=context)
|
||||
if add_qty:
|
||||
add_qty -= 1
|
||||
|
||||
# compute new quantity
|
||||
if set_qty:
|
||||
quantity = set_qty
|
||||
elif add_qty != None:
|
||||
quantity = sol.browse(cr, SUPERUSER_ID, line_id, context=context).product_uom_qty + (add_qty or 0)
|
||||
|
||||
# Remove zero of negative lines
|
||||
if quantity <= 0:
|
||||
sol.unlink(cr, SUPERUSER_ID, [line_id], context=context)
|
||||
else:
|
||||
# update line
|
||||
values = self._website_product_id_change(cr, uid, ids, so.id, product_id, line_id, context=context)
|
||||
values['product_uom_qty'] = quantity
|
||||
sol.write(cr, SUPERUSER_ID, [line_id], values, context=context)
|
||||
|
||||
return quantity
|
||||
|
||||
def _cart_accessories(self, cr, uid, ids, context=None):
|
||||
for order in self.browse(cr, uid, ids, context=context):
|
||||
s = set(j.id for l in (order.website_order_line or []) for j in (l.product_id.accessory_product_ids or []))
|
||||
s -= set(l.product_id.id for l in order.order_line)
|
||||
product_ids = random.sample(s, min(len(s),3))
|
||||
return self.pool['product.template'].browse(cr, uid, product_ids, context=context)
|
||||
|
||||
class website(orm.Model):
|
||||
_inherit = 'website'
|
||||
|
||||
_columns = {
|
||||
'pricelist_id': fields.related('user_id','partner_id','property_product_pricelist',
|
||||
type='many2one', relation='product.pricelist', string='Default pricelist')
|
||||
}
|
||||
|
||||
def sale_product_domain(self, cr, uid, ids, context=None):
|
||||
return [("sale_ok", "=", True)]
|
||||
|
||||
def sale_get_order(self, cr, uid, ids, force_create=False, code=None, context=None):
|
||||
sale_order_obj = self.pool['sale.order']
|
||||
sale_order_id = request.session.get('sale_order_id')
|
||||
sale_order = None
|
||||
# create so if needed
|
||||
if not sale_order_id and (force_create or code):
|
||||
# TODO cache partner_id session
|
||||
partner = self.pool['res.users'].browse(cr, SUPERUSER_ID, uid, context=context).partner_id
|
||||
|
||||
for w in self.browse(cr, uid, ids):
|
||||
values = {
|
||||
'user_id': w.user_id.id,
|
||||
'partner_id': partner.id,
|
||||
'pricelist_id': partner.property_product_pricelist.id,
|
||||
}
|
||||
sale_order_id = sale_order_obj.create(cr, SUPERUSER_ID, values, context=context)
|
||||
values = sale_order_obj.onchange_partner_id(cr, SUPERUSER_ID, [], partner.id, context=context)['value']
|
||||
sale_order_obj.write(cr, SUPERUSER_ID, [sale_order_id], values, context=context)
|
||||
request.session['sale_order_id'] = sale_order_id
|
||||
if sale_order_id:
|
||||
# TODO cache partner_id session
|
||||
partner = self.pool['res.users'].browse(cr, SUPERUSER_ID, uid, context=context).partner_id
|
||||
|
||||
sale_order = sale_order_obj.browse(cr, SUPERUSER_ID, sale_order_id, context=context)
|
||||
if not sale_order.exists():
|
||||
request.session['sale_order_id'] = None
|
||||
return None
|
||||
|
||||
def update_pricelist(pricelist_id):
|
||||
values = {'pricelist_id': pricelist_id}
|
||||
values.update(sale_order.onchange_pricelist_id(pricelist_id, None)['value'])
|
||||
sale_order.write(values)
|
||||
for line in sale_order.order_line:
|
||||
sale_order._cart_update(product_id=line.product_id.id, add_qty=0)
|
||||
|
||||
# check for change of pricelist with a coupon
|
||||
if code and code != sale_order.pricelist_id.code:
|
||||
pricelist_ids = self.pool['product.pricelist'].search(cr, SUPERUSER_ID, [('code', '=', code)], context=context)
|
||||
if pricelist_ids:
|
||||
pricelist_id = pricelist_ids[0]
|
||||
request.session['sale_order_code_pricelist_id'] = pricelist_id
|
||||
update_pricelist(pricelist_id)
|
||||
request.session['sale_order_code_pricelist_id'] = False
|
||||
|
||||
# check for change of partner_id ie after signup
|
||||
if sale_order.partner_id.id != partner.id and request.website.partner_id.id != partner.id:
|
||||
flag_pricelist = False
|
||||
pricelist_id = request.session.get('sale_order_code_pricelist_id') or partner.property_product_pricelist.id
|
||||
if pricelist_id != sale_order.pricelist_id.id:
|
||||
flag_pricelist = True
|
||||
fiscal_position = sale_order.fiscal_position and sale_order.fiscal_position.id or False
|
||||
|
||||
values = sale_order_obj.onchange_partner_id(cr, SUPERUSER_ID, [sale_order_id], partner.id, context=context)['value']
|
||||
order_lines = map(int,sale_order.order_line)
|
||||
values.update(sale_order_obj.onchange_fiscal_position(cr, SUPERUSER_ID, [],
|
||||
values['fiscal_position'], [[6, 0, order_lines]], context=context)['value'])
|
||||
|
||||
values['partner_id'] = partner.id
|
||||
sale_order_obj.write(cr, SUPERUSER_ID, [sale_order_id], values, context=context)
|
||||
|
||||
if flag_pricelist or values.get('fiscal_position') != fiscal_position:
|
||||
update_pricelist(pricelist_id)
|
||||
|
||||
# update browse record
|
||||
if (code and code != sale_order.pricelist_id.code) or sale_order.partner_id.id != partner.id:
|
||||
sale_order = sale_order_obj.browse(cr, SUPERUSER_ID, sale_order.id, context=context)
|
||||
|
||||
return sale_order
|
||||
|
||||
def sale_get_transaction(self, cr, uid, ids, context=None):
|
||||
transaction_obj = self.pool.get('payment.transaction')
|
||||
tx_id = request.session.get('sale_transaction_id')
|
||||
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)
|
||||
else:
|
||||
request.session['sale_transaction_id'] = False
|
||||
return False
|
||||
|
||||
def sale_reset(self, cr, uid, ids, context=None):
|
||||
request.session.update({
|
||||
'sale_order_id': False,
|
||||
'sale_transaction_id': False,
|
||||
'sale_order_code_pricelist_id': False,
|
||||
})
|
||||
|
||||
# vim:et:
|
||||
|
|
|
@ -1,226 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import uuid
|
||||
from openerp.osv import orm, fields
|
||||
from openerp.addons.web.http import request
|
||||
from openerp import SUPERUSER_ID
|
||||
|
||||
|
||||
class Website(orm.Model):
|
||||
_inherit = 'website'
|
||||
|
||||
def _get_pricelist_id(self, cr, uid, ids, field_name, arg, context=None):
|
||||
pricelist_id = self.ecommerce_get_pricelist_id(cr, uid, None, context=context)
|
||||
return dict.fromkeys(ids, pricelist_id)
|
||||
|
||||
_columns = {
|
||||
'pricelist_id': fields.function(
|
||||
_get_pricelist_id, type='many2one', obj='product.pricelist')
|
||||
}
|
||||
|
||||
# ************************************************************
|
||||
# Ecommerce pricelist management
|
||||
# ***********************************************************
|
||||
|
||||
def ecommerce_get_pricelist_id(self, cr, uid, ids, context=None):
|
||||
if not request.session.get('ecommerce_pricelist'):
|
||||
self._ecommerce_change_pricelist(cr, uid, None, context=context)
|
||||
return request.session.get('ecommerce_pricelist')
|
||||
|
||||
def _ecommerce_change_pricelist(self, cr, uid, code=None, context=None):
|
||||
request.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.session['ecommerce_pricelist'] = pricelist_id
|
||||
|
||||
order = self.ecommerce_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._ecommerce_add_product_to_cart(cr, uid, order_line_id=line.id, number=0)
|
||||
|
||||
# ************************************************************
|
||||
# Ecommerce quotation management
|
||||
# ************************************************************
|
||||
|
||||
def _ecommerce_add_product_to_cart(self, cr, uid, product_id=0, order_line_id=0, number=1, set_number=-1, context=None):
|
||||
order = self.ecommerce_get_current_order(cr, uid, context=context)
|
||||
if not order:
|
||||
order = self.ecommerce_get_new_order(cr, uid, context=context)
|
||||
|
||||
order_line_obj = self.pool.get('sale.order.line')
|
||||
order_obj = self.pool.get('sale.order')
|
||||
|
||||
context = dict(context or {}, pricelist=self.ecommerce_get_pricelist_id(cr, uid, None, context=context))
|
||||
|
||||
# set order_line_id and product_id
|
||||
if order_line_id:
|
||||
order_line = None
|
||||
for line in order.order_line:
|
||||
if line.id == order_line_id:
|
||||
order_line = line
|
||||
break
|
||||
if order_line:
|
||||
product_id = order_line.product_id.id
|
||||
else:
|
||||
order_line_id = None
|
||||
else:
|
||||
order_line_ids = order_line_obj.search(cr, SUPERUSER_ID,
|
||||
[('order_id', '=', order.id), ('product_id', '=', product_id)], context=context)
|
||||
if order_line_ids:
|
||||
order_line_id = order_line_ids[0]
|
||||
|
||||
if not order_line_id and not product_id:
|
||||
return 0
|
||||
|
||||
# values initialisation
|
||||
quantity = 0
|
||||
values = {}
|
||||
order_line_ids = []
|
||||
if order_line_id:
|
||||
order_line_val = order_line_obj.read(cr, SUPERUSER_ID, [order_line_id], [], context=context)[0]
|
||||
if not product_id:
|
||||
product_id = order_line_val['product_id'][0]
|
||||
if set_number >= 0:
|
||||
quantity = set_number
|
||||
else:
|
||||
quantity = order_line_val['product_uom_qty'] + number
|
||||
if quantity < 0:
|
||||
quantity = 0
|
||||
order_line_ids = [order_line_id]
|
||||
else:
|
||||
fields = [k for k, v in order_line_obj._columns.items()]
|
||||
values = order_line_obj.default_get(cr, SUPERUSER_ID, fields, context=context)
|
||||
if set_number >= 0:
|
||||
quantity = set_number
|
||||
elif number >= 0:
|
||||
quantity = number
|
||||
else:
|
||||
quantity = 1
|
||||
|
||||
# change and record value
|
||||
if quantity:
|
||||
vals = order_line_obj._recalculate_product_values(cr, uid, order_line_ids, product_id, fiscal_position=order.fiscal_position.id, context=context)
|
||||
values.update(vals)
|
||||
values['product_uom_qty'] = quantity
|
||||
values['product_id'] = product_id
|
||||
values['order_id'] = order.id
|
||||
|
||||
product = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
|
||||
values['name'] = "%s: %s" % (product.name, product.variants) if product.variants else product.name
|
||||
if values.get('tax_id'):
|
||||
values['tax_id'] = [(6, 0, values['tax_id'])]
|
||||
|
||||
order_obj.write(cr, SUPERUSER_ID, [order.id], {'order_line': [(1, order_line_id, values) if order_line_id else (0, 0, values)]}, context=context)
|
||||
|
||||
elif order_line_ids:
|
||||
order_line_obj.unlink(cr, SUPERUSER_ID, order_line_ids, context=context)
|
||||
|
||||
order = self.ecommerce_get_current_order(cr, uid, context=context)
|
||||
if not order or not order.order_line:
|
||||
self._ecommerce_change_pricelist(cr, uid, None, context=context)
|
||||
|
||||
return quantity
|
||||
|
||||
def _ecommerce_get_quotation_values(self, cr, uid, context=None):
|
||||
""" Generate the values for a new ecommerce quotation. """
|
||||
SaleOrder = self.pool.get('sale.order')
|
||||
fields = [k for k, v in SaleOrder._columns.items()]
|
||||
values = SaleOrder.default_get(cr, SUPERUSER_ID, fields, context=context)
|
||||
if request.session.get('ecommerce_pricelist'):
|
||||
values['pricelist_id'] = request.session['ecommerce_pricelist']
|
||||
values['partner_id'] = self.pool.get('res.users').browse(cr, SUPERUSER_ID, uid, context=context).partner_id.id
|
||||
values.update(SaleOrder.onchange_partner_id(cr, SUPERUSER_ID, [], values['partner_id'], context=context)['value'])
|
||||
values['website_session_id'] = request.session['website_session_id']
|
||||
return values
|
||||
|
||||
def _ecommerce_create_quotation(self, cr, uid, context=None):
|
||||
""" Create a new quotation used in the ecommerce (event, sale) """
|
||||
SaleOrder = self.pool.get('sale.order')
|
||||
quotation_values = self._ecommerce_get_quotation_values(cr, uid, context=context)
|
||||
quotation_values['user_id'] = False
|
||||
return SaleOrder.create(cr, SUPERUSER_ID, quotation_values, context=context)
|
||||
|
||||
def ecommerce_get_new_order(self, cr, uid, context=None):
|
||||
""" Create a new quotation for the ecommerce and update the session
|
||||
accordingly: website_session_id if not set, ecommerce_order_id """
|
||||
SaleOrder = self.pool.get('sale.order')
|
||||
|
||||
# add website_session_id key for access rules
|
||||
if not request.session.get('website_session_id'):
|
||||
request.session['website_session_id'] = str(uuid.uuid4())
|
||||
|
||||
order_id = self._ecommerce_create_quotation(cr, uid, context=context)
|
||||
request.session['ecommerce_order_id'] = order_id
|
||||
context = dict(context or {}, pricelist=self.ecommerce_get_pricelist_id(cr, uid, None, context=context))
|
||||
return SaleOrder.browse(cr, SUPERUSER_ID, order_id, context=context)
|
||||
|
||||
def ecommerce_get_current_order(self, cr, uid, context=None):
|
||||
SaleOrder = self.pool.get('sale.order')
|
||||
context = dict(context or {}, pricelist=self.ecommerce_get_pricelist_id(cr, uid, None, context=context))
|
||||
order_id = request.session.get('ecommerce_order_id')
|
||||
if not order_id:
|
||||
request.session['ecommerce_order_id'] = False
|
||||
return False
|
||||
if not order_id in SaleOrder.exists(cr, uid, [order_id], context=context):
|
||||
request.session['ecommerce_order_id'] = False
|
||||
return False
|
||||
try:
|
||||
order = SaleOrder.browse(cr, SUPERUSER_ID, order_id, context=context)
|
||||
assert order.website_session_id == request.session['website_session_id']
|
||||
return order
|
||||
except:
|
||||
request.session['ecommerce_order_id'] = False
|
||||
return False
|
||||
|
||||
# ************************************************************
|
||||
# Ecommerce transaction management
|
||||
# ************************************************************
|
||||
|
||||
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 ecommerce_get_current_transaction(self, cr, uid, context=None):
|
||||
if request.session.get('website_sale_transaction_id'):
|
||||
tx = self._get_transaction(cr, uid, tx_id=request.session['website_sale_transaction_id'], context=context)
|
||||
if not tx:
|
||||
request.session['website_sale_transaction_id'] = False
|
||||
return tx
|
||||
return False
|
||||
|
||||
def ecommerce_reset(self, cr, uid, context=None):
|
||||
request.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.ecommerce_get_current_order(cr, uid, context=context),
|
||||
'website_sale_transaction': self.ecommerce_get_current_transaction(cr, uid, context=context)
|
||||
})
|
||||
return super(Website, self).preprocess_request(cr, uid, ids, request, context=None)
|
||||
|
||||
def ecommerce_get_product_domain(self):
|
||||
return [("sale_ok", "=", True),("product_variant_ids","!=",False)]
|
|
@ -1,30 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from openerp.osv import osv, fields
|
||||
|
||||
|
||||
class product_style(osv.Model):
|
||||
_name = "product.style"
|
||||
_columns = {
|
||||
'name' : fields.char('Style Name', required=True, translate=True),
|
||||
'html_class': fields.char('HTML Classes'),
|
||||
}
|
|
@ -20,31 +20,32 @@
|
|||
{
|
||||
title: "click on add to cart",
|
||||
waitFor: 'input[name="product_id"]:eq(1)[checked]',
|
||||
element: 'form[action="/shop/add_cart"] .btn',
|
||||
element: 'form[action="/shop/cart/update"] .btn',
|
||||
},
|
||||
{
|
||||
title: "add suggested",
|
||||
element: 'form[action="/shop/add_cart"] .btn-link:contains("Add to Cart")',
|
||||
waitNot: '#cart_products:contains("[A8767] Apple In-Ear Headphones")',
|
||||
element: 'form[action="/shop/cart/update"] .btn-link:contains("Add to Cart")',
|
||||
},
|
||||
{
|
||||
title: "add one more iPod",
|
||||
waitFor: '.my_cart_quantity:contains(2)',
|
||||
element: '#mycart_products tr:contains("iPod: 32 Gb") a.js_add_cart_json:eq(1)',
|
||||
element: '#cart_products tr:contains("iPod - 32 Gb") a.js_add_cart_json:eq(1)',
|
||||
},
|
||||
{
|
||||
title: "remove Headphones",
|
||||
waitFor: '#mycart_products tr:contains("iPod: 32 Gb") input.js_quantity[value=2]',
|
||||
element: '#mycart_products tr:contains("Apple In-Ear Headphones") a.js_add_cart_json:first',
|
||||
waitFor: '#cart_products tr:contains("iPod - 32 Gb") input.js_quantity[value=2]',
|
||||
element: '#cart_products tr:contains("Apple In-Ear Headphones") a.js_add_cart_json:first',
|
||||
},
|
||||
{
|
||||
title: "set one iPod",
|
||||
waitNot: '#mycart_products tr:contains("Apple In-Ear Headphones")',
|
||||
element: '#mycart_products input.js_quantity',
|
||||
waitNot: '#cart_products tr:contains("Apple In-Ear Headphones")',
|
||||
element: '#cart_products input.js_quantity',
|
||||
sampleText: '1',
|
||||
},
|
||||
{
|
||||
title: "go to checkout",
|
||||
waitFor: '#mycart_products input.js_quantity[value=1]',
|
||||
waitFor: '#cart_products input.js_quantity[value=1]',
|
||||
element: 'a[href="/shop/checkout"]',
|
||||
},
|
||||
{
|
||||
|
|
|
@ -12,28 +12,24 @@ $(document).ready(function () {
|
|||
$(ev.currentTarget).parents(".thumbnail").toggleClass("disabled");
|
||||
});
|
||||
|
||||
function set_my_cart_quantity(qty) {
|
||||
var $q = $(".my_cart_quantity");
|
||||
$q.parent().parent().removeClass("hidden", !qty);
|
||||
$q.html(qty)
|
||||
.hide()
|
||||
.fadeIn(600);
|
||||
}
|
||||
|
||||
$(".oe_website_sale .oe_mycart input.js_quantity").change(function (ev) {
|
||||
$(".oe_website_sale .oe_cart input.js_quantity").change(function () {
|
||||
var $input = $(this);
|
||||
var $link = $(ev.currentTarget);
|
||||
var value = parseInt($input.val(), 10);
|
||||
if (isNaN(value)) value = 0;
|
||||
openerp.jsonRpc("/shop/set_cart_json", 'call', {'order_line_id': $input.data('id'), 'set_number': value})
|
||||
openerp.jsonRpc("/shop/cart/update_json", 'call', {
|
||||
'line_id': parseInt($input.data('line-id'),10),
|
||||
'product_id': parseInt($input.data('product-id'),10),
|
||||
'set_qty': value})
|
||||
.then(function (data) {
|
||||
if (!data[0]) {
|
||||
if (!data.quantity) {
|
||||
location.reload();
|
||||
return;
|
||||
}
|
||||
set_my_cart_quantity(data[1]);
|
||||
$link.parents(".input-group:first").find(".js_quantity").val(data[0]);
|
||||
$('#mycart_total').replaceWith(data[3]);
|
||||
var $q = $(".my_cart_quantity");
|
||||
$q.parent().parent().removeClass("hidden", !data.quantity);
|
||||
$q.html(data.cart_quantity).hide().fadeIn(600);
|
||||
$input.val(data.quantity);
|
||||
$("#cart_total").replaceWith(data['website_sale.total']);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -41,25 +37,9 @@ $(document).ready(function () {
|
|||
$('.oe_website_sale a.js_add_cart_json').on('click', function (ev) {
|
||||
ev.preventDefault();
|
||||
var $link = $(ev.currentTarget);
|
||||
var href = $link.attr("href");
|
||||
|
||||
var add_cart = href.match(/add_cart\/([0-9]+)/);
|
||||
var product_id = add_cart && +add_cart[1] || false;
|
||||
|
||||
var change_cart = href.match(/change_cart\/([0-9]+)/);
|
||||
var order_line_id = change_cart && +change_cart[1] || false;
|
||||
openerp.jsonRpc("/shop/add_cart_json", 'call', {
|
||||
'product_id': product_id,
|
||||
'order_line_id': order_line_id,
|
||||
'remove': $link.is('[href*="remove"]')})
|
||||
.then(function (data) {
|
||||
if (!data[0]) {
|
||||
location.reload();
|
||||
}
|
||||
set_my_cart_quantity(data[1]);
|
||||
$link.parents(".input-group:first").find(".js_quantity").val(data[0]);
|
||||
$('#mycart_total').replaceWith(data[3]);
|
||||
});
|
||||
var $input = $link.parent().parent().find("input");
|
||||
$input.val(($link.has(".fa-minus").length ? -1 : 1) + parseFloat($input.val(),10));
|
||||
$input.change();
|
||||
return false;
|
||||
});
|
||||
|
||||
|
@ -83,7 +63,6 @@ $(document).ready(function () {
|
|||
var js_slider_time = null;
|
||||
var $form = $("form.attributes");
|
||||
$form.on("change", "label input", function () {
|
||||
clearTimeout(js_slider_time);
|
||||
$form.submit();
|
||||
});
|
||||
$(".js_slider", $form).each(function() {
|
||||
|
|
|
@ -1 +1 @@
|
|||
import test_ui
|
||||
import test_sale_process
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<openerp>
|
||||
<data>
|
||||
|
||||
<!-- Layout add nav and footer -->
|
||||
<!-- Layout and common templates -->
|
||||
|
||||
<template id="debugger" inherit_id="website.debugger" name="Event Debugger">
|
||||
<xpath expr="//script[last()]" position="after">
|
||||
|
@ -19,65 +19,58 @@
|
|||
|
||||
<template id="header" inherit_id="website.layout" name="Header Shop My Cart Link">
|
||||
<xpath expr="//header//ul[@id='top_menu']/li" position="before">
|
||||
<li t-att-class="(not website_sale_order or not website_sale_order.get_number_of_products()) and 'hidden' or ''">
|
||||
<a href="/shop/mycart">
|
||||
<t t-set="website_sale_order" t-value="website.sale_get_order()"/>
|
||||
<li t-att-class="'' if website_sale_order and website_sale_order.cart_quantity else 'hidden'">
|
||||
<a href="/shop/cart">
|
||||
<i class="fa fa-shopping-cart"></i>
|
||||
My cart <sup t-attf-class="my_cart_quantity label label-primary"
|
||||
t-esc="website_sale_order and website_sale_order.get_number_of_products() or ''"/>
|
||||
My cart <sup t-attf-class="my_cart_quantity label label-primary" t-esc="website_sale_order and website_sale_order.cart_quantity or ''"/>
|
||||
</a>
|
||||
</li>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
<!-- List of categories -->
|
||||
|
||||
<template id="categories_recursive" name="Category list">
|
||||
<li t-att-class="int(categ) == int(category or 0) and 'active' or ''">
|
||||
<t t-if="categ in all_categories">
|
||||
<a t-attf-href="/shop/category/#{ slug(categ) }" t-field="categ.name"></a>
|
||||
<ul t-if="categ.child_id" class="nav nav-pills nav-stacked nav-hierarchy">
|
||||
<t t-foreach="categ.child_id" t-as="categ">
|
||||
<t t-call="website_sale.categories_recursive"/>
|
||||
</t>
|
||||
</ul>
|
||||
</t>
|
||||
</li>
|
||||
</template>
|
||||
|
||||
<!-- Product list -->
|
||||
|
||||
<template id="search" name="Search hidden fields">
|
||||
<form t-attf-action="/shop/{{'category/%s' % slug(category) if category else ''}}" method="get" t-att-class="search_class">
|
||||
<input t-if="search.get('filters')" type="hidden" name="filters" t-att-value="search.get('filters')"/>
|
||||
<input t-if="attrib" type="hidden" name="filters" t-att-value="attrib"/>
|
||||
<input t-if="category" type="hidden" name="category" t-att-value="int(category or 0)"/>
|
||||
<div class="input-group">
|
||||
<input type="text" name="search" class="search-query form-control" placeholder="Search..." t-att-value="search.get('search') or ''"/>
|
||||
<input type="text" name="search" class="search-query form-control" placeholder="Search..." t-att-value="search"/>
|
||||
<span class="input-group-btn">
|
||||
<a class="btn btn-default a-submit"><i class="fa fa-search"/></a>
|
||||
</span>
|
||||
</div>
|
||||
</form>
|
||||
</template>
|
||||
|
||||
<template id="products_cart" name="Product Cell">
|
||||
<template id="404">
|
||||
<t t-call="website.layout">
|
||||
<div id="wrap">
|
||||
<div class="oe_structure oe_empty">
|
||||
<div class="container">
|
||||
<h1 class="mt32">Product not found!</h1>
|
||||
<p>Sorry, this product is not available anymore.</p>
|
||||
<p><a t-attf-href="/shop">Return to the product list.</a></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
</template>
|
||||
|
||||
<!-- Product item used by /shop and /shop/cart -->
|
||||
|
||||
<template id="products_item" name="Product item">
|
||||
<div itemscope="itemscope" itemtype="http://schema.org/Product">
|
||||
<div class="ribbon-wrapper">
|
||||
<div class="ribbon btn btn-danger">Sale</div>
|
||||
</div>
|
||||
<div class="oe_product_image">
|
||||
<a itemprop="url" t-attf-href="/shop/product/{{ slug(product) }}?{{ keep_query('search', 'filters', category=(category and int(category)), page=(pager['page']['num'] if pager['page']['num']>1 else None)) }}">
|
||||
<a itemprop="url" t-attf-href="/shop/product/{{ slug(product) }}/?{{ keep_query('search', 'filters', category=(category and int(category)), page=(pager['page']['num'] if pager['page']['num']>1 else None)) }}">
|
||||
<img itemprop="image" class="img img-responsive" t-attf-src="/website/image/product.template/#{product.id}/image#{'' if product_image_big else '?max_width=300&max_height=300'}"/>
|
||||
</a>
|
||||
</div>
|
||||
<section>
|
||||
<h5><strong><a itemprop="name" t-attf-href="/shop/product/{{ slug(product) }}?{{ keep_query('search', 'filters', category=(category and int(category)), page=(pager['page']['num'] if pager['page']['num']>1 else None)) }}" t-field="product.name"/></strong></h5>
|
||||
<h5><strong><a itemprop="name" t-attf-href="/shop/product/{{ slug(product) }}/?{{ keep_query('search', 'filters', category=(category and int(category)), page=(pager['page']['num'] if pager['page']['num']>1 else None)) }}" t-field="product.name"/></strong></h5>
|
||||
<div itemprop="offers" itemscope="itemscope" itemtype="http://schema.org/Offer" class="product_price" t-if="product.product_variant_ids">
|
||||
<b>
|
||||
<t t-if="product.product_variant_ids[0].lst_price != product.product_variant_ids[0].price">
|
||||
<del class="text-danger"
|
||||
t-field="product.product_variant_ids[0].lst_price" t-field-options='{
|
||||
"widget": "monetary",
|
||||
"display_currency": "website.pricelist_id.currency_id"
|
||||
}'/>&nbsp;
|
||||
<t t-if="abs(product.product_variant_ids[0].lst_price - product.product_variant_ids[0].price) > 0.2">
|
||||
<del class="text-danger" t-field="product.product_variant_ids[0].lst_price" t-field-options='{ "widget": "monetary", "display_currency": "pricelist.currency_id" }'/>&nbsp;
|
||||
</t>
|
||||
<span t-field="product.product_variant_ids[0].price" t-field-options='{
|
||||
"widget": "monetary",
|
||||
|
@ -92,6 +85,25 @@
|
|||
</div>
|
||||
</template>
|
||||
|
||||
<template id="products_description" inherit_option_id="website_sale.products_item" name="Product Description">
|
||||
<xpath expr="//div[@class='product_price']" position="before">
|
||||
<div class="text-info oe_subdescription" contenteditable="false">
|
||||
<div itemprop="description" t-field="product.description_sale"></div>
|
||||
</div>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
<template id="products_add_to_cart" inherit_option_id="website_sale.products_item" name="Add to Cart">
|
||||
<xpath expr="//div[@class='product_price']" position="inside">
|
||||
<form action="/shop/cart/update" method="post" style="display: inline-block;">
|
||||
<input name="product_id" t-att-value="product.product_variant_ids[0].id" type="hidden"/>
|
||||
<a class="btn btn-default btn-xs fa fa-shopping-cart a-submit"/>
|
||||
</form>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
<!-- /shop product listing -->
|
||||
|
||||
<template id="products" name="Products">
|
||||
<t t-call="website.layout">
|
||||
<t t-set="head">
|
||||
|
@ -109,8 +121,9 @@
|
|||
<div class="container oe_website_sale">
|
||||
<div class="products_pager">
|
||||
<div class="row">
|
||||
<t t-set="search_class">pagination form-inline col-md-3</t>
|
||||
<form t-att-action="keep('/shop',search=0)" method="get" class="pagination form-inline col-md-3">
|
||||
<t t-call="website_sale.search"/>
|
||||
</form>
|
||||
<t t-call="website.pager"/>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -190,9 +203,8 @@
|
|||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<t t-set="product_image_big" t-value="td_product['x']+td_product['y'] > 2"/>
|
||||
<t t-call="website_sale.products_cart"/>
|
||||
<t t-call="website_sale.products_item"/>
|
||||
</div>
|
||||
|
||||
</td>
|
||||
|
@ -204,8 +216,8 @@
|
|||
</table>
|
||||
<t t-if="not bins">
|
||||
<div class="text-center text-muted">
|
||||
<h3>No product found.</h3>
|
||||
<t groups="base.group_website_publisher" t-ignore="true">
|
||||
<h3 class="css_editable_display">No product defined.</h3>
|
||||
<t groups="base.group_website_publisher">
|
||||
<p groups="base.group_sale_manager">Use the <i>'Content'</i> top menu to create a new product.</p>
|
||||
</t>
|
||||
</div>
|
||||
|
@ -221,54 +233,77 @@
|
|||
</t>
|
||||
</template>
|
||||
|
||||
<!-- Product Description-->
|
||||
|
||||
<template id="product_description" inherit_option_id="website_sale.products_cart" name="Product Description">
|
||||
<xpath expr="//div[@class='product_price']" position="before">
|
||||
<div class="text-info oe_subdescription" contenteditable="false">
|
||||
<div itemprop="description" t-field="product.description_sale"></div>
|
||||
</div>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
<!-- Add to cart button-->
|
||||
|
||||
<template id="add_to_basket" inherit_option_id="website_sale.products_cart" name="Add to Cart">
|
||||
<xpath expr="//div[@class='product_price']" position="inside">
|
||||
<form action="/shop/add_cart" method="post" style="display: inline-block;">
|
||||
<input name="product_id" t-att-value="product.product_variant_ids[0].id" type="hidden"/>
|
||||
<a class="btn btn-default btn-xs fa fa-shopping-cart a-submit"/>
|
||||
</form>
|
||||
<template id="categories_recursive" name="Category list">
|
||||
<li t-att-class="'active' if c.id == category else ''">
|
||||
<a t-att-href="keep('/shop/category/' + slug(c), category=0)" t-field="c.name"></a>
|
||||
<ul t-if="c.child_id" class="nav nav-pills nav-stacked nav-hierarchy">
|
||||
<t t-foreach="c.child_id" t-as="c">
|
||||
<t t-call="website_sale.categories_recursive"/>
|
||||
</t>
|
||||
</ul>
|
||||
</li>
|
||||
</template>
|
||||
|
||||
<template id="products_categories" inherit_option_id="website_sale.products" name="Product Categories">
|
||||
<xpath expr="//div[@id='products_grid_before']" position="inside">
|
||||
<ul class="nav nav-pills nav-stacked mt16">
|
||||
<li t-att-class=" '' if category else 'active' "><a t-att-href="keep('/shop',category=0)">All Products</a></li>
|
||||
<t t-foreach="categories" t-as="c">
|
||||
<t t-call="website_sale.categories_recursive"/>
|
||||
</t>
|
||||
</ul>
|
||||
</xpath>
|
||||
<xpath expr="//div[@id='products_grid_before']" position="attributes">
|
||||
<attribute name="class">col-md-3 hidden-xs</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//div[@id='products_grid']" position="attributes">
|
||||
<attribute name="class">col-md-9</attribute>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
<!-- List view of products -->
|
||||
<template id="products_attributes" inherit_option_id="website_sale.products" name="Product Attribute's Filters" groups="product.group_product_attributes">
|
||||
<xpath expr="//div[@id='products_grid_before']" position="inside">
|
||||
<form t-att-action="keep('shop',attrib=0)" class="attributes" method="get">
|
||||
<ul class="nav nav-pills nav-stacked mt16">
|
||||
<t t-foreach="attributes" t-as="a">
|
||||
<li t-if="a.value_ids">
|
||||
<div t-field="a.name"/>
|
||||
<ul class="nav nav-pills nav-stacked">
|
||||
<t t-foreach="a.value_ids" t-as="v">
|
||||
<li t-att-class="'active' if v.id in attrib_set else ''">
|
||||
<label style="margin: 0 20px;">
|
||||
<input type="checkbox" name="attrib" t-att-value="v.id" t-att-checked="'checked' if v.id in attrib_set else ''"/>
|
||||
<span style="font-weight: normal" t-field="v.name"/>
|
||||
</label>
|
||||
</li>
|
||||
</t>
|
||||
</ul>
|
||||
</li>
|
||||
</t>
|
||||
</ul>
|
||||
</form>
|
||||
</xpath>
|
||||
<xpath expr="//div[@id='products_grid_before']" position="attributes">
|
||||
<attribute name="class">col-md-3 hidden-xs</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//div[@id='products_grid']" position="attributes">
|
||||
<attribute name="class">col-md-9</attribute>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
<template id="list_view" inherit_option_id="website_sale.products" name="List View">
|
||||
<template id="products_list_view" inherit_option_id="website_sale.products" name="List View">
|
||||
<xpath expr="//div[@id='products_grid']//table" position="replace">
|
||||
<t t-foreach="products" t-as="product">
|
||||
<div class="oe_product oe_list oe_product_cart" t-att-data-publish="product.website_published and 'on' or 'off'">
|
||||
<t t-call="website_sale.products_cart"/>
|
||||
<t t-call="website_sale.products_item"/>
|
||||
</div>
|
||||
</t>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
|
||||
<!-- product -->
|
||||
<template id="404">
|
||||
<t t-call="website.layout">
|
||||
<div id="wrap">
|
||||
<div class="oe_structure oe_empty">
|
||||
<div class="container">
|
||||
<h1 class="mt32">Product not found!</h1>
|
||||
<p>Sorry, this product is not available anymore.</p>
|
||||
<p><a t-attf-href="/shop">Return to the product list.</a></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
</template>
|
||||
<!-- /shop/product product page -->
|
||||
|
||||
<template id="product" name="Product">
|
||||
<t t-call="website.layout">
|
||||
|
@ -284,20 +319,20 @@
|
|||
<div class="row">
|
||||
<div class="col-sm-4">
|
||||
<ol class="breadcrumb">
|
||||
<li><a t-attf-href="/shop?{{ keep_query('search', 'filters', 'page') if not category else keep_query('search', 'filters') }}">Products</a></li>
|
||||
<li t-if="category"><a t-attf-href="/shop/category/{{ slug(category) }}?{{ keep_query('search', 'filters', 'page') }}" t-field="category.name"/></li>
|
||||
<li><a t-att-href="keep(category=0)" onclick="history.go(-1); return false;">Products</a></li>
|
||||
<li t-if="category"><a t-att-href="keep()" t-field="category.name"/></li>
|
||||
<li class="active"><span t-field="product.name"/></li>
|
||||
</ol>
|
||||
</div>
|
||||
<div class="col-sm-3">
|
||||
<t t-set="search_class">pull-right</t>
|
||||
<form t-att-action="keep(search=0)" method="get" class="pull-right">
|
||||
<t t-call="website_sale.search"/>
|
||||
</form>
|
||||
</div>
|
||||
<div class="col-sm-4" groups="base.group_sale_manager">
|
||||
<t t-call="website.publish_management">
|
||||
<t t-set="object" t-value="product"/>
|
||||
<t t-set="publish_edit" t-value="True"/>
|
||||
<t t-set="action" t-value="'product.product_template_action'"/>
|
||||
</t>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -310,17 +345,14 @@
|
|||
</div><div class="col-sm-5 col-md-5 col-lg-4 col-lg-offset-1">
|
||||
<h1 itemprop="name" t-field="product.name">Product Name</h1>
|
||||
<span itemprop="url" style="display:none;" t-esc="'/shop/product/%s' % slug(product)"/>
|
||||
<form action="/shop/add_cart" class="js_add_cart_json" method="POST">
|
||||
<form action="/shop/cart/update" class="js_add_cart_json" method="POST">
|
||||
<input type="hidden" t-if="len(product.product_variant_ids) == 1" name="product_id" t-att-value="product.product_variant_ids[0].id"/>
|
||||
<t t-if="len(product.product_variant_ids) > 1">
|
||||
<label label-default="label-default" class="radio" t-foreach="product.product_variant_ids" t-as="variant_id">
|
||||
<input type="radio" name="product_id" t-att-value="variant_id.id" t-att-checked="variant_id == product.product_variant_ids[0] or None"/>
|
||||
<t t-esc="variant_id.variants or ''">Standard</t>
|
||||
<span class="badge" t-if="variant_id.price_extra">
|
||||
<t t-esc="variant_id.price_extra > 0 and '+' or ''"/><span t-field="variant_id.price_extra" t-field-options='{
|
||||
"widget": "monetary",
|
||||
"display_currency": "website.pricelist_id.currency_id"
|
||||
}'/>
|
||||
<t t-esc="variant_id.price_extra > 0 and '+' or ''"/><span t-field="variant_id.price_extra" t-field-options='{ "widget": "monetary", "display_currency": "pricelist.currency_id" }'/>
|
||||
</span>
|
||||
</label>
|
||||
</t>
|
||||
|
@ -330,17 +362,11 @@
|
|||
<t t-if="product.product_variant_ids[0].lst_price != product.product_variant_ids[0].price">
|
||||
<span class="text-danger" style="text-decoration: line-through;"
|
||||
t-field="product.product_variant_ids[0].lst_price"
|
||||
t-field-options='{
|
||||
"widget": "monetary",
|
||||
"display_currency": "website.pricelist_id.currency_id"
|
||||
}'/><br/>
|
||||
t-field-options='{ "widget": "monetary", "display_currency": "pricelist.currency_id" }'/><br/>
|
||||
</t>
|
||||
<b class="oe_price"
|
||||
t-field="product.product_variant_ids[0].price"
|
||||
t-field-options='{
|
||||
"widget": "monetary",
|
||||
"display_currency": "website.pricelist_id.currency_id"
|
||||
}'/>
|
||||
t-field-options='{ "widget": "monetary", "display_currency": "pricelist.currency_id" }'/>
|
||||
<span itemprop="price" style="display:none;" t-esc="product.product_variant_ids[0].price"/>
|
||||
<span itemprop="priceCurrency" style="display:none;" t-esc="website.pricelist_id.currency_id.name"/>
|
||||
</h4>
|
||||
|
@ -363,21 +389,18 @@
|
|||
</t>
|
||||
</template>
|
||||
|
||||
<!-- Product option: related / recommended products -->
|
||||
<template id="recommended_products" inherit_id="website_sale.product" inherit_option_id="website_sale.product" name="Recommended Products">
|
||||
<template id="recommended_products" inherit_id="website_sale.product" inherit_option_id="website_sale.product" name="Alternative Products">
|
||||
<xpath expr="//div[@id='product_full_description']" position="after">
|
||||
<div class="container mt32" t-if="product.recommended_products()">
|
||||
<h3>Customers who have bought this product also bought:</h3>
|
||||
<div class="container mt32" t-if="product.alternative_product_ids">
|
||||
<h3>Suggested alternatives:</h3>
|
||||
<div class='row mt16' style="margin-left: 15px !important;">
|
||||
<t t-foreach="product.recommended_products()" t-as="product">
|
||||
<t t-foreach="product.alternative_product_ids" t-as="product">
|
||||
<div class='col-md-2 thumbnail' style='width: 170px; margin-right: 16px;'>
|
||||
<div class='mt16 text-center'>
|
||||
<span t-field="product.image_small" t-field-options='{"widget": "image", "class": "img-rounded shadow" }'/>
|
||||
<h5>
|
||||
<a t-attf-href="/shop/product/#{ slug(product) }"
|
||||
style="display: block">
|
||||
<span t-field='product.name'
|
||||
style="display: block"/>
|
||||
<a t-attf-href="/shop/product/#{ slug(product) }" style="display: block">
|
||||
<span t-field='product.name' style="display: block"/>
|
||||
</a>
|
||||
</h5>
|
||||
</div>
|
||||
|
@ -388,19 +411,18 @@
|
|||
</xpath>
|
||||
</template>
|
||||
|
||||
<!-- Product option: attributes -->
|
||||
<template id="product_attributes" inherit_id="website_sale.product" inherit_option_id="website_sale.product" name="Product attributes" groups="product.group_product_attributes">
|
||||
<xpath expr="//p[@t-field='product.description_sale']" position="after">
|
||||
<hr t-if="product.attribute_lines"/>
|
||||
<p class="text-muted">
|
||||
<t t-set="attr" t-value="None"/>
|
||||
<t t-foreach="product.attribute_lines" t-as="attribute"><br t-if="attr and attribute.attribute_id.id != attr"/><t t-if="attribute.attribute_id.id != attr"><span t-field="attribute.attribute_id"/>: </t><t t-if="attribute.attribute_id.id == attr">, </t><t t-if="attribute.attribute_id.type == 'distinct'"><span t-field="attribute.value_id"/></t><t t-if="attribute.attribute_id.type == 'float'"><span t-field="attribute.value"/></t><t t-set="attr" t-value="attribute.attribute_id.id"/></t>
|
||||
<t t-foreach="product.attribute_lines" t-as="l">
|
||||
<span t-field="l.attribute_id.name"/>: <span t-field="l.value_id.name"/> <br/>
|
||||
</t>
|
||||
</p>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
<!-- Product options: OpenChatter -->
|
||||
<template id="product_option_openchatter" inherit_option_id="website_sale.product" name="Discussion">
|
||||
<template id="product_comment" inherit_option_id="website_sale.product" name="Discussion">
|
||||
<xpath expr="//div[@t-field='product.website_description']" position="after">
|
||||
<hr class="mb32"/>
|
||||
<section class="container">
|
||||
|
@ -433,7 +455,7 @@
|
|||
class='oe_attachment_embedded'></img>
|
||||
</t>
|
||||
<t t-if="attachment.file_type_icon != 'webimage'">
|
||||
<img t-att-src="'/mail/static/src/img/mimetypes' + attachment.file_type + '.png'"
|
||||
<img t-att-src="'/mail/static/src/img/mimetypes/' + attachment.file_type + '.png'"
|
||||
class='oe_attachment_webimage'></img>
|
||||
</t>
|
||||
<div class='oe_attachment_name'><t t-raw='attachment.name' /></div>
|
||||
|
@ -445,29 +467,22 @@
|
|||
</li>
|
||||
</ul>
|
||||
<div class="css_editable_mode_hidden">
|
||||
<t groups="base.group_public">
|
||||
<a class="btn btn-primary mt8" t-attf-href="/web/login?redirect=/shop/product/#{product.id}%23comment">Log in </a> <span>to post comments</span>
|
||||
</t>
|
||||
<t groups="base.group_user,base.group_portal">
|
||||
<form id="comment" t-attf-action="/shop/product/#{product.id}/comment"
|
||||
method="POST">
|
||||
<form id="comment" t-attf-action="/shop/product/comment/#{product.id}" method="POST">
|
||||
<img class="img pull-left img-rounded" t-att-src="'/website/image?model=res.partner&field=image_small&id='+str(user_id.partner_id.id)" style="width: 50px; margin-right: 10px;"/>
|
||||
<div class="pull-left mb32" style="width: 75%%">
|
||||
|
||||
<textarea rows="3" name="comment" class="form-control" placeholder="Write a comment..."></textarea>
|
||||
<a class="btn btn-primary mt8 a-submit">Post</a>
|
||||
</div>
|
||||
</form>
|
||||
</t>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
<!-- Page Shop my cart -->
|
||||
<!-- /shop/cart -->
|
||||
|
||||
<template id="mycart" name="Your Cart">
|
||||
<template id="cart" name="Shopping Cart">
|
||||
<t t-call="website.layout">
|
||||
<t t-set="head">
|
||||
<script type="text/javascript" src="/website_sale/static/src/js/website_sale.js"></script>
|
||||
|
@ -485,11 +500,12 @@
|
|||
</ul>
|
||||
<h1 class="mb32">Shopping Cart</h1>
|
||||
<div class="row">
|
||||
<div class="col-md-8 col-sm-9 oe_mycart">
|
||||
<div class="col-md-8 col-sm-9 oe_cart">
|
||||
<t t-set="website_sale_order" t-value="website.sale_get_order()"/>
|
||||
<div t-if="not website_sale_order or not website_sale_order.website_order_line" class="well well-lg">
|
||||
Your cart is empty!
|
||||
</div>
|
||||
<table class='table table-striped table-condensed' id="mycart_products" t-if="website_sale_order and website_sale_order.website_order_line">
|
||||
<table class='table table-striped table-condensed' id="cart_products" t-if="website_sale_order and website_sale_order.website_order_line">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2" width="100">Product</th>
|
||||
|
@ -528,14 +544,16 @@
|
|||
<td>
|
||||
<div class="input-group">
|
||||
<span class="input-group-addon">
|
||||
<a t-attf-href="../change_cart/#{ line.id }/?remove=True" class="mb8 js_add_cart_json">
|
||||
<a t-attf-href="#" class="mb8 js_add_cart_json">
|
||||
<i class="fa fa-minus"></i>
|
||||
</a>
|
||||
</span>
|
||||
<input type="text" class="js_quantity form-control"
|
||||
t-att-data-id="line.id" t-att-value="int(line.product_uom_qty)"/>
|
||||
t-att-data-line-id="line.id"
|
||||
t-att-data-product-id="line.product_id.id"
|
||||
t-att-value="int(line.product_uom_qty)"/>
|
||||
<span class="input-group-addon">
|
||||
<a t-attf-href="../change_cart/#{ line.id }" class="mb8 float_left js_add_cart_json">
|
||||
<a t-attf-href="#" class="mb8 float_left js_add_cart_json">
|
||||
<i class="fa fa-plus"></i>
|
||||
</a>
|
||||
</span>
|
||||
|
@ -570,79 +588,8 @@
|
|||
</t>
|
||||
</template>
|
||||
|
||||
|
||||
<template id="continue_shopping" inherit_id="website_sale.mycart" inherit_option_id="website_sale.mycart" name="Continue Shopping Button">
|
||||
<xpath expr="//a[@href='/shop/checkout']" position="before">
|
||||
<a href="/shop" class="btn btn-default mb32"><span class="fa fa-long-arrow-left"/> Continue Shopping</a>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
|
||||
<!-- Page Shop -->
|
||||
|
||||
<template id="products_categories" inherit_option_id="website_sale.products" name="Product Categories">
|
||||
<xpath expr="//div[@id='products_grid_before']" position="inside">
|
||||
<ul class="nav nav-pills nav-stacked mt16">
|
||||
<li t-att-class=" '' if category else 'active' "><a href="/shop">All Products</a></li>
|
||||
<t t-foreach="categories" t-as="categ">
|
||||
<t t-call="website_sale.categories_recursive"/>
|
||||
</t>
|
||||
</ul>
|
||||
</xpath>
|
||||
<xpath expr="//div[@id='products_grid_before']" position="attributes">
|
||||
<attribute name="class">col-md-3 hidden-xs</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//div[@id='products_grid']" position="attributes">
|
||||
<attribute name="class">col-md-9</attribute>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
<template id="products_attributes" inherit_id="website_sale.products" inherit_option_id="website_sale.products" name="Product attribute's Filters" groups="product.group_product_attributes">
|
||||
<xpath expr="//div[@id='products_grid_before']" position="inside">
|
||||
<form t-attf-action="/shop/filters?{{ keep_query('search', category=(category and int(category))) }}" class="attributes" method="post">
|
||||
<ul class="nav nav-pills nav-stacked mt16">
|
||||
<t t-set="attribute_ids" t-value="Ecommerce.get_attribute_ids()"/>
|
||||
<t t-foreach="attribute_ids" t-as="attribute_id">
|
||||
<t t-if="attribute_id.visible">
|
||||
<li t-if="attribute_id.value_ids and attribute_id.type == 'distinct'">
|
||||
<div t-field="attribute_id.name"/>
|
||||
<ul class="nav nav-pills nav-stacked">
|
||||
<t t-foreach="attribute_id.value_ids" t-as="value_id">
|
||||
<li t-att-class="Ecommerce.has_search_filter(attribute_id.id, value_id.id) and 'active' or ''">
|
||||
<label style="margin: 0 20px;">
|
||||
<input type="checkbox" t-att-name="'att-%s-%s' % (attribute_id.id, value_id.id)"
|
||||
t-att-checked="Ecommerce.has_search_filter(attribute_id.id, value_id.id) and 'checked' or ''"/>
|
||||
<span style="font-weight: normal" t-field="value_id.name"/>
|
||||
</label>
|
||||
</li>
|
||||
</t>
|
||||
</ul>
|
||||
</li>
|
||||
<li t-if="attribute_id.type == 'float' and attribute_id.float_min != attribute_id.float_max">
|
||||
<div t-field="attribute_id.name"/>
|
||||
<t t-set="attribute" t-value="Ecommerce.has_search_filter(attribute_id.id)"/>
|
||||
<div style="margin: 0 20px;" class="js_slider"
|
||||
t-att-data-id="attribute_id.id"
|
||||
t-att-data-value-min="attribute and attribute[1][0] or attribute_id.float_min or '0'"
|
||||
t-att-data-value-max="attribute and attribute[1][1] or attribute_id.float_max"
|
||||
t-att-data-min="attribute_id.float_min or '0'"
|
||||
t-att-data-max="attribute_id.float_max"></div>
|
||||
</li>
|
||||
</t>
|
||||
</t>
|
||||
</ul>
|
||||
</form>
|
||||
</xpath>
|
||||
<xpath expr="//div[@id='products_grid_before']" position="attributes">
|
||||
<attribute name="class">col-md-3 hidden-xs</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//div[@id='products_grid']" position="attributes">
|
||||
<attribute name="class">col-md-9</attribute>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
<template id="suggested_products_list" inherit_id="website_sale.mycart" inherit_option_id="website_sale.mycart" name="Suggested Products in my cart">
|
||||
<xpath expr="//table[@id='mycart_products']" position="after">
|
||||
<template id="suggested_products_list" inherit_id="website_sale.cart" inherit_option_id="website_sale.cart" name="Suggested Products in my cart">
|
||||
<xpath expr="//table[@id='cart_products']" position="after">
|
||||
<table t-if="suggested_products" class='table table-striped table-condensed'>
|
||||
<colgroup>
|
||||
<col width="80"/>
|
||||
|
@ -659,34 +606,34 @@
|
|||
<tr t-foreach="suggested_products" t-as="product">
|
||||
|
||||
<td>
|
||||
<a t-attf-href="/shop/product/#{ slug(product.product_tmpl_id) }">
|
||||
<a t-attf-href="/shop/product/#{ slug(product) }">
|
||||
<span t-field="product.image_small"
|
||||
t-field-options='{"widget": "image", "class": "img-rounded"}'/>
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<div>
|
||||
<a t-attf-href="/shop/product/#{ slug(product.product_tmpl_id) }">
|
||||
<a t-attf-href="/shop/product/#{ slug(product) }">
|
||||
<strong t-field="product.name"/>
|
||||
</a>
|
||||
</div>
|
||||
<div class="text-muted" t-field="product.description_sale"/>
|
||||
</td>
|
||||
<td>
|
||||
<t t-if="abs(product.lst_price - product.price) > 0.2">
|
||||
<t t-if="abs(product.product_variant_ids[0].lst_price - product.product_variant_ids[0].price) > 0.2">
|
||||
<del class="text-danger"
|
||||
t-field="product.lst_price" t-field-options='{
|
||||
t-field="product.product_variant_ids[0].lst_price" t-field-options='{
|
||||
"widget": "monetary",
|
||||
"display_currency": "website.pricelist_id.currency_id"
|
||||
}'/>&nbsp;
|
||||
</t>
|
||||
<span t-field="product.price" t-field-options='{
|
||||
<span t-field="product.product_variant_ids[0].price" t-field-options='{
|
||||
"widget": "monetary",
|
||||
"display_currency": "website.pricelist_id.currency_id"
|
||||
}'/>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<form action="/shop/add_cart" method="post">
|
||||
<form action="/shop/cart/update" method="post">
|
||||
<input name="product_id" t-att-value="product.product_variant_ids[0].id" type="hidden"/>
|
||||
<a class="btn btn-link a-submit"><strong>Add to Cart</strong></a>
|
||||
</form>
|
||||
|
@ -697,7 +644,13 @@
|
|||
</xpath>
|
||||
</template>
|
||||
|
||||
<template id="reduction_code" inherit_option_id="website_sale.mycart" name="Reduction Code">
|
||||
<template id="continue_shopping" inherit_id="website_sale.cart" inherit_option_id="website_sale.cart" name="Continue Shopping Button">
|
||||
<xpath expr="//a[@href='/shop/checkout']" position="before">
|
||||
<a href="/shop" class="btn btn-default mb32"><span class="fa fa-long-arrow-left"/> Continue Shopping</a>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
<template id="reduction_code" inherit_option_id="website_sale.cart" name="Reduction Code">
|
||||
<xpath expr="//div[@id='right_column']" position="inside">
|
||||
<h4>Coupon Code</h4>
|
||||
<p>
|
||||
|
@ -714,8 +667,7 @@
|
|||
</xpath>
|
||||
</template>
|
||||
|
||||
|
||||
<!-- Page confirm my cart -->
|
||||
<!-- /shop/checkout -->
|
||||
|
||||
<template id="checkout">
|
||||
<t t-call="website.layout">
|
||||
|
@ -728,7 +680,7 @@
|
|||
<div id="wrap">
|
||||
<div class="container oe_website_sale">
|
||||
<ul class="wizard pull-right">
|
||||
<li><a href="/shop/mycart" class="text-success">Review Order<span class="chevron"></span></a></li>
|
||||
<li><a href="/shop/cart" class="text-success">Review Order<span class="chevron"></span></a></li>
|
||||
<li class="text-primary">Shipping & Billing<span class="chevron"></span></li>
|
||||
<li class="text-muted">Payment<span class="chevron"></span></li>
|
||||
<li class="text-muted">Confirmation<span class="chevron"></span></li>
|
||||
|
@ -737,10 +689,10 @@
|
|||
<form action="/shop/confirm_order" method="post">
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-8 oe_mycart">
|
||||
<div class="col-md-8 oe_cart">
|
||||
<h3 class="page-header mt16">Billing Information
|
||||
<small groups="base.group_public"> or
|
||||
<a class='btn btn-primary' t-if="not partner" t-attf-href="/web/login?redirect=#{ request.httprequest.url }">Sign in</a>
|
||||
<a class='btn btn-primary' t-if="not partner" t-attf-href="/web?redirect=#{ request.httprequest.url }">Sign in</a>
|
||||
</small>
|
||||
</h3>
|
||||
<div class="row">
|
||||
|
@ -748,9 +700,9 @@
|
|||
<label class="control-label" for="contact_name">Your Name</label>
|
||||
<input type="text" name="name" class="form-control" t-att-value="checkout.get('name')"/>
|
||||
</div>
|
||||
<div t-attf-class="form-group #{error.get('company') and 'has-error' or ''} col-lg-6">
|
||||
<label class="control-label" for="company" style="font-weight: normal">Your Company</label>
|
||||
<input type="text" name="company" class="form-control" t-att-value="checkout.get('company')"/>
|
||||
<div t-attf-class="form-group #{error.get('street2') and 'has-error' or ''} col-lg-6">
|
||||
<label class="control-label" for="street2" style="font-weight: normal">Company Name</label>
|
||||
<input type="text" name="street2" class="form-control" t-att-value="checkout.get('street2')"/>
|
||||
</div>
|
||||
<div t-attf-class="form-group #{error.get('email') and 'has-error' or ''} col-lg-6">
|
||||
<label class="control-label" for="contact_name">Email</label>
|
||||
|
@ -798,12 +750,12 @@
|
|||
|
||||
<div class="form-group col-lg-6" groups="sale.group_delivery_invoice_address">
|
||||
<label>
|
||||
<input type="checkbox" name="shipping_different" t-att-checked="shipping"/>
|
||||
<input type="checkbox" name="shipping_different" t-att-checked="checkout.get('shipping_different')"/>
|
||||
<span>Ship to a different address</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="js_shipping row mb16" t-att-style="not shipping and 'display:none' or ''" groups="sale.group_delivery_invoice_address">
|
||||
<div class="js_shipping row mb16" t-att-style="not checkout.get('shipping_different') and 'display:none' or ''" groups="sale.group_delivery_invoice_address">
|
||||
<h3 class="oe_shipping col-lg-12 mt16">Shipping Information</h3>
|
||||
|
||||
<div t-attf-class="form-group #{error.get('shipping_name') and 'has-error' or ''} col-lg-6">
|
||||
|
@ -849,7 +801,8 @@
|
|||
<a class="btn btn-default btn-primary pull-right mb32 a-submit">Confirm <span class="fa fa-long-arrow-right"/></a>
|
||||
</div>
|
||||
<div class="col-lg-offset-1 col-lg-3 col-md-3 text-muted">
|
||||
<h3 class="page-header mt16">Your Order <small><a href="/shop/mycart"><span class="fa fa-arrow-right"/> change</a></small></h3>
|
||||
<h3 class="page-header mt16">Your Order <small><a href="/shop/cart"><span class="fa fa-arrow-right"/> change</a></small></h3>
|
||||
<t t-set="website_sale_order" t-value="website.sale_get_order()"/>
|
||||
<div class="row">
|
||||
<div class="col-sm-6 text-right">Subtotal:</div>
|
||||
<div class="col-sm-6"><span t-field="website_sale_order.amount_untaxed" t-field-options='{
|
||||
|
@ -875,6 +828,8 @@
|
|||
</t>
|
||||
</template>
|
||||
|
||||
<!-- /shop/payment -->
|
||||
|
||||
<template id="payment">
|
||||
<t t-call="website.layout">
|
||||
<t t-set="head">
|
||||
|
@ -888,21 +843,16 @@
|
|||
<div class="container oe_website_sale">
|
||||
|
||||
<ul class="wizard pull-right">
|
||||
<li><a href="/shop/mycart" class="text-success">Review Order<span class="chevron"></span></a></li>
|
||||
<li><a href="/shop/cart" class="text-success">Review Order<span class="chevron"></span></a></li>
|
||||
<li><a href="/shop/checkout" class="text-success">Shipping & Billing<span class="chevron"></span></a></li>
|
||||
<li class="text-primary">Payment<span class="chevron"></span></li>
|
||||
<li class="text-muted">Confirmation<span class="chevron"></span></li>
|
||||
</ul>
|
||||
<h1 class="mb32">Validate Order</h1>
|
||||
<t t-foreach="errors" t-as="error">
|
||||
<div class="alert alert-danger" t-if="error">
|
||||
<h4><t t-esc="error[0]"/></h4>
|
||||
<t t-esc="error[1]"/>
|
||||
</div>
|
||||
</t>
|
||||
<div class="row">
|
||||
<div class="col-lg-8 col-sm-9 oe_mycart">
|
||||
<table class='table table-striped table-condensed' id="mycart_products" t-if="website_sale_order and website_sale_order.website_order_line">
|
||||
<div class="col-lg-8 col-sm-9 oe_cart">
|
||||
<t t-set="website_sale_order" t-value="website.sale_get_order()"/>
|
||||
<table class='table table-striped table-condensed' id="cart_products" t-if="website_sale_order and website_sale_order.website_order_line">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2" width="80">Product</th>
|
||||
|
@ -987,7 +937,7 @@
|
|||
</t>
|
||||
</div>
|
||||
</div>
|
||||
<div class="js_payment mb64 row" t-if="not website_sale_order.amount_total and not errors" id="payment_method">
|
||||
<div class="js_payment mb64 row" t-if="not website_sale_order.amount_total" id="payment_method">
|
||||
<div class="col-lg-8 col-sm-8">
|
||||
<form target="_self" action="/shop/payment/validate" method="post" class="pull-right">
|
||||
<a style="width:100px;" class="btn btn-primary a-submit">
|
||||
|
@ -1023,7 +973,7 @@
|
|||
</ul>
|
||||
<h1 class="mb32">Order <em t-field="order.name"/> Confirmed</h1>
|
||||
<div class="row">
|
||||
<div class="col-md-8 oe_mycart">
|
||||
<div class="col-md-8 oe_cart">
|
||||
<h2>Thank you for your order.</h2>
|
||||
<div class="oe_website_sale_tx_status" t-att-data-order-id="order.id">
|
||||
</div>
|
||||
|
@ -1059,7 +1009,7 @@
|
|||
<!-- Page Shop my cart and payment total -->
|
||||
|
||||
<template id="total">
|
||||
<table class='pull-right mb16' id="mycart_total" t-if="website_sale_order">
|
||||
<table class='pull-right mb16' id="cart_total" t-if="website_sale_order">
|
||||
<thead>
|
||||
<tr width="100" style="border-top: 1px solid #000" id="order_total">
|
||||
<th><h3>Total: </h3></th>
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
<group name="sale" position="inside">
|
||||
<group name="website" string="Website">
|
||||
<field name="alternative_product_ids" widget="many2many_tags"/>
|
||||
<field name="accessory_product_ids" widget="many2many_tags"/>
|
||||
<field name="website_style_ids" widget="many2many_tags"/>
|
||||
<field name="website_sequence"/>
|
||||
|
@ -61,15 +62,13 @@
|
|||
</xpath>
|
||||
<xpath expr="//field[@name='description']" position="before">
|
||||
<group colspan="4" string="Website Options">
|
||||
<field name="alternative_product_ids" widget="many2many_tags"/>
|
||||
<field name="accessory_product_ids" widget="many2many_tags"/>
|
||||
<field name="website_style_ids" widget="many2many_tags"/>
|
||||
<field colspan="4" name="attribute_lines" nolabel="1" groups="product.group_product_attributes">
|
||||
<tree string="Product attributes" editable="bottom">
|
||||
<field name="attribute_id" on_change="onchange_attribute_id(attribute_id)"/>
|
||||
<field name="type" invisible="1"/>
|
||||
<field name="value" attrs="{'required': [('type','=','float')]}"/>
|
||||
<field name="value_id"
|
||||
attrs="{'required': [('type','=','distinct')]}"
|
||||
context="{'default_attribute_id': attribute_id}"
|
||||
domain="[('attribute_id', '=', attribute_id)]"/>
|
||||
</tree>
|
||||
|
@ -87,8 +86,6 @@
|
|||
<form string="Product attributes" version="7.0">
|
||||
<group>
|
||||
<field name="name"/>
|
||||
<field name="type"/>
|
||||
<field name="visible"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
|
@ -16,5 +16,5 @@ Delivery Costs
|
|||
],
|
||||
'demo': [],
|
||||
'qweb': [],
|
||||
'installable': True,
|
||||
'installable': False,
|
||||
}
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from openerp.addons.website_sale.controllers.main import Ecommerce
|
||||
import openerp
|
||||
from openerp.addons.web import http
|
||||
from openerp.addons.web.http import request
|
||||
from openerp import SUPERUSER_ID
|
||||
|
||||
|
||||
class Ecommerce(Ecommerce):
|
||||
class website_sale(openerp.addons.website_sale.controllers.main.website_sale):
|
||||
|
||||
@http.route(['/shop/payment'], type='http', auth="public", website=True, multilang=True)
|
||||
def payment(self, **post):
|
||||
|
@ -19,5 +18,5 @@ class Ecommerce(Ecommerce):
|
|||
if carrier_id:
|
||||
return request.redirect("/shop/payment")
|
||||
|
||||
res = super(Ecommerce, self).payment(**post)
|
||||
res = super(website_sale, self).payment(**post)
|
||||
return res
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<openerp>
|
||||
<data>
|
||||
|
||||
<template id="mycart_delivery" name="Delivery Costs" inherit_id="website_sale.total">
|
||||
<template id="cart_delivery" name="Delivery Costs" inherit_id="website_sale.total">
|
||||
<xpath expr="//tr[@id='order_total_taxes']" position="after">
|
||||
<tr class="text-muted" id="order_delivery">
|
||||
<td><abbr title="Delivery will be updated after choosing a new delivery method">Delivery:</abbr></td>
|
||||
|
|
Loading…
Reference in New Issue