[IMP] website_sale: checkout end
bzr revid: chm@openerp.com-20130724094218-9mppzak93e1pyfyp
This commit is contained in:
parent
06d90a6000
commit
9cc1eefa46
|
@ -21,38 +21,65 @@ class Ecommerce(http.Controller):
|
|||
partner_id = None
|
||||
return (cr, uid, partner_id)
|
||||
|
||||
def get_values(self):
|
||||
def get_categories(self):
|
||||
cr, uid, partner_id = self.get_cr_uid()
|
||||
category_obj = request.registry.get('pos.category')
|
||||
category_ids = category_obj.search(cr, uid, [('parent_id', '=', False)])
|
||||
return category_obj.browse(cr, uid, category_ids)
|
||||
|
||||
def get_order(self, order_id=None):
|
||||
cr, uid, partner_id = self.get_cr_uid()
|
||||
order_obj = request.registry.get('sale.order')
|
||||
category_obj = request.registry.get('pos.category')
|
||||
context = {}
|
||||
|
||||
order_id = request.httprequest.session.get('ecommerce_order')
|
||||
# check if order allready exists
|
||||
try:
|
||||
order_obj.browse(cr, uid, order_id).pricelist_id
|
||||
except:
|
||||
order_id = None
|
||||
|
||||
if not order_id:
|
||||
fields = [k for k, v in order_obj._columns.items()]
|
||||
order_value = order_obj.default_get(cr, uid, fields, context=context)
|
||||
order_value = order_obj.default_get(cr, uid, fields)
|
||||
order_value['partner_id'] = partner_id or request.registry.get('res.users').browse(cr, uid, uid).partner_id.id
|
||||
order_value.update(order_obj.onchange_partner_id(cr, uid, [], uid, context=context)['value'])
|
||||
order_id = order_obj.create(cr, uid, order_value, context=context)
|
||||
request.httprequest.session['ecommerce_order'] = order_id
|
||||
order_value.update(order_obj.onchange_partner_id(cr, uid, [], uid, context={})['value'])
|
||||
order_id = order_obj.create(cr, uid, order_value)
|
||||
return order_obj.browse(cr, uid, order_id)
|
||||
|
||||
category_ids = category_obj.search(cr, uid, [('parent_id', '=', False)])
|
||||
def get_values(self):
|
||||
cr, uid, partner_id = self.get_cr_uid()
|
||||
|
||||
order = self.get_order(request.httprequest.session.get('ecommerce_order'))
|
||||
request.httprequest.session['ecommerce_order'] = order.id
|
||||
|
||||
values = template_values()
|
||||
values.update({
|
||||
'temp': 0,
|
||||
'res_company': request.registry['res.company'].browse(request.cr, uid, 1, context=context),
|
||||
'order': order_obj.browse(cr, uid, order_id),
|
||||
'categories': category_obj.browse(cr, uid, category_ids),
|
||||
'res_company': request.registry['res.company'].browse(request.cr, 1, 1),
|
||||
'order': order,
|
||||
'categories': self.get_categories(),
|
||||
})
|
||||
return values
|
||||
|
||||
def recommended_product(self, my_pids):
|
||||
if not my_pids:
|
||||
return []
|
||||
cr, uid, partner_id = self.get_cr_uid()
|
||||
my_pids = str(my_pids)[1:-1]
|
||||
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 8
|
||||
""" % (my_pids, my_pids)
|
||||
cr.execute(query)
|
||||
for p in cr.fetchall():
|
||||
product_ids.append(p[0])
|
||||
return request.registry.get('product.product').browse(cr, uid, product_ids)
|
||||
|
||||
@http.route(['/shop', '/shop/category/<cat_id>'], type='http', auth="admin")
|
||||
def category(self, cat_id=0, offset=0, **post):
|
||||
values = self.get_values()
|
||||
|
@ -98,28 +125,6 @@ class Ecommerce(http.Controller):
|
|||
html = request.registry.get("ir.ui.view").render(cr, uid, "website_sale.product", values)
|
||||
return html
|
||||
|
||||
def recommended_product(self, my_pids):
|
||||
if not my_pids:
|
||||
return []
|
||||
cr, uid, partner_id = self.get_cr_uid()
|
||||
my_pids = str(my_pids)[1:-1]
|
||||
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 8
|
||||
""" % (my_pids, my_pids)
|
||||
cr.execute(query)
|
||||
for p in cr.fetchall():
|
||||
product_ids.append(p[0])
|
||||
return request.registry.get('product.product').browse(cr, uid, product_ids)
|
||||
|
||||
@http.route(['/shop/mycart'], type='http', auth="admin")
|
||||
def mycart(self, **post):
|
||||
cr, uid, partner_id = self.get_cr_uid()
|
||||
|
@ -189,9 +194,15 @@ class Ecommerce(http.Controller):
|
|||
return self.add_cart(product_id=product_id, remove=True)
|
||||
|
||||
@http.route(['/shop/checkout'], type='http', auth="admin")
|
||||
def checkout(self, *arg, **post):
|
||||
def checkout(self, **post):
|
||||
cr, uid, partner_id = self.get_cr_uid()
|
||||
values = self.get_values()
|
||||
|
||||
if values['order'].state != 'draft':
|
||||
return self.confirmed(**post)
|
||||
if not values['order'].order_line:
|
||||
return self.mycart(**post)
|
||||
|
||||
partner_obj = request.registry.get('res.partner')
|
||||
user_obj = request.registry.get('res.users')
|
||||
country_obj = request.registry.get('res.country')
|
||||
|
@ -206,19 +217,32 @@ class Ecommerce(http.Controller):
|
|||
|
||||
if partner_id:
|
||||
values['partner'] = partner_obj.browse(cr, uid, partner_id)
|
||||
shipping_ids = partner_obj.search(cr, uid, [("parent_id", "=", partner_id), ('type', "=", 'delivery')])
|
||||
values['shipping'] = None
|
||||
if shipping_ids:
|
||||
values['shipping'] = partner_obj.browse(cr, uid, shipping_ids[0])
|
||||
|
||||
values['countries'] = country_obj.browse(cr, uid, country_obj.search(cr, uid, [(1, "=", 1)]))
|
||||
values['states'] = country_state_obj.browse(cr, uid, country_state_obj.search(cr, uid, [(1, "=", 1)]))
|
||||
|
||||
return request.registry.get("ir.ui.view").render(cr, uid, "website_sale.checkout", values)
|
||||
|
||||
@http.route(['/shop/confirm_order'], type='http', auth="admin")
|
||||
def confirm_order(self, *arg, **post):
|
||||
def confirm_order(self, **post):
|
||||
cr, uid, partner_id = self.get_cr_uid()
|
||||
values = self.get_values()
|
||||
json = {'error': [], 'validation': False}
|
||||
partner_obj = request.registry.get('res.partner')
|
||||
obj_data = request.registry.get('ir.model.data')
|
||||
|
||||
if values['order'].state != 'draft':
|
||||
json['validation'] = True
|
||||
return json
|
||||
if not values['order'].order_line:
|
||||
json['error'].append("empty_cart")
|
||||
return json
|
||||
|
||||
# check values
|
||||
json = {'error': [], 'validation': False}
|
||||
required_field = ['phone', 'zip', 'email', 'street', 'city', 'name', 'country_id']
|
||||
for key in required_field:
|
||||
if not post.get(key):
|
||||
|
@ -267,19 +291,48 @@ class Ecommerce(http.Controller):
|
|||
'country_id': post['shipping_country_id'],
|
||||
'state_id': post['shipping_state_id'],
|
||||
}
|
||||
shipping_id = partner_obj.create(cr, uid, shipping_value)
|
||||
domain = [(key, '_id' in key and '=' or 'ilike', '_id' in key and int(value) or value)
|
||||
for key, value in shipping_value.items() if key in required_field + ["type", "parent_id"]]
|
||||
shipping_ids = partner_obj.search(cr, uid, domain)
|
||||
if shipping_ids:
|
||||
shipping_id = shipping_ids[0]
|
||||
partner_obj.write(cr, uid, [shipping_id], shipping_value)
|
||||
else:
|
||||
shipping_id = partner_obj.create(cr, uid, shipping_value)
|
||||
|
||||
values = self.get_values()
|
||||
values['order'].write({
|
||||
order_value = {
|
||||
'state': 'progress',
|
||||
'partner_id': partner_id,
|
||||
'partner_invoice_id': partner_id,
|
||||
'partner_shipping_id': shipping_id or partner_id
|
||||
})
|
||||
request.httprequest.session['ecommerce_partner_id'] = False
|
||||
request.httprequest.session['ecommerce_order'] = None
|
||||
}
|
||||
order_value.update(request.registry.get('sale.order').onchange_partner_id(cr, uid, [], uid, context={})['value'])
|
||||
values['order'].write(order_value)
|
||||
|
||||
json['validation'] = True
|
||||
return simplejson.dumps(json)
|
||||
|
||||
@http.route(['/shop/confirmed'], type='http', auth="admin")
|
||||
def confirmed(self, **post):
|
||||
cr, uid, partner_id = self.get_cr_uid()
|
||||
|
||||
if request.httprequest.session['ecommerce_order']:
|
||||
order = self.get_order(request.httprequest.session.get('ecommerce_order_old'))
|
||||
if order.state != 'draft':
|
||||
request.httprequest.session['ecommerce_order_old'] = order.id
|
||||
request.httprequest.session['ecommerce_order'] = None
|
||||
|
||||
order_old = self.get_order(request.httprequest.session.get('ecommerce_order_old'))
|
||||
if not order_old.order_line:
|
||||
return self.mycart(**post)
|
||||
|
||||
values = template_values()
|
||||
values.update({
|
||||
'temp': 0,
|
||||
'res_company': request.registry['res.company'].browse(request.cr, 1, 1),
|
||||
'order': order_old,
|
||||
'categories': self.get_categories(),
|
||||
})
|
||||
return request.registry.get("ir.ui.view").render(cr, uid, "website_sale.confirmed", values)
|
||||
|
||||
# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -189,3 +189,9 @@
|
|||
left: 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
.oe_ecommerce .oe_total td:last-child {
|
||||
text-align: right;
|
||||
}
|
||||
.oe_ecommerce .oe_total th:last-child {
|
||||
text-align: center;
|
||||
}
|
|
@ -8,6 +8,10 @@
|
|||
padding: 5px 10px
|
||||
table
|
||||
width: auto
|
||||
td:last-child
|
||||
text-align: right
|
||||
th:last-child
|
||||
text-align: center
|
||||
.oe_products
|
||||
.oe_product
|
||||
.oe_hidden
|
||||
|
|
|
@ -34,6 +34,7 @@ $(document).ready(function () {
|
|||
$checkout.find("input").css("border", "");
|
||||
$.post('/shop/confirm_order', values, function (result) {
|
||||
var result = JSON.parse(result);
|
||||
console.log(result);
|
||||
if (result.error.length) {
|
||||
$inputs = $checkout.find("input[name='" + result.error.join("'], input[name='") + "']");
|
||||
$inputs.css("border", "1px solid #dd0000");
|
||||
|
@ -41,7 +42,9 @@ $(document).ready(function () {
|
|||
}
|
||||
if (result.validation) {
|
||||
var $form = $(e.currentTarget).parent().find("input[name='submit']").click();
|
||||
window.location.href = "/shop";
|
||||
setTimeout(function() {
|
||||
window.location.href = "/shop/confirmed";
|
||||
}, 0);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<field name="arch" type="xml">
|
||||
<data>
|
||||
<xpath expr="(//li)[last()]" position="after">
|
||||
<li class="pull-right"><a href="/shop/mycart"><i class="icon-shopping-cart icon-large"></i> My cart</a></li>
|
||||
<li class="pull-right"><a href="/shop/mycart"><i class="icon-shopping-cart icon-large" style="position: absolute;"></i>&nbsp; &nbsp; &nbsp; My cart</a></li>
|
||||
<li class="pull-right"><a href="/shop">Shop</a></li>
|
||||
</xpath>
|
||||
</data>
|
||||
|
@ -145,14 +145,14 @@
|
|||
<t t-set="quantity" t-value="int(line.product_uom_qty)"/>
|
||||
<t t-call="website_sale.product_card"/>
|
||||
</t>
|
||||
<div class="media well well-small">
|
||||
<t t-call="website_sale.product_recommended"/>
|
||||
<t t-call="website_sale.total"/>
|
||||
<div class="media well well-small" t-if="order.order_line">
|
||||
<form action="/shop/mycart" class="navbar-form">
|
||||
<input name="code" type="text" placeholder="Reduction Code..."/>
|
||||
<button class="btn">Submit your Reduction Code</button>
|
||||
</form>
|
||||
</div>
|
||||
<t t-call="website_sale.product_recommended"/>
|
||||
<t t-call="website_sale.total"/>
|
||||
<a t-if="order.order_line" href="/shop/checkout"><button class="btn btn-success">Next stage</button></a>
|
||||
</span>
|
||||
</t>
|
||||
|
@ -193,7 +193,11 @@
|
|||
</thead>
|
||||
<tbody>
|
||||
<t t-foreach="order.order_line or []" t-as="line">
|
||||
<tr><td><t t-esc="line.product_id.name"/></td><td><t t-esc="int(line.product_uom_qty)"/></td><td></td></tr>
|
||||
<tr>
|
||||
<td><t t-esc="line.product_id.name"/></td>
|
||||
<td><t t-esc="int(line.product_uom_qty)"/></td>
|
||||
<td class="css_alignright"><t t-esc="line.product_id.list_price"/> €</td>
|
||||
</tr>
|
||||
</t>
|
||||
<tr><td colspan="3" style="visibility: hidden; border: 0">-</td></tr>
|
||||
<tr><th>Untaxed Amount</th><td></td><td><t t-esc="order.amount_untaxed"/> €</td></tr>
|
||||
|
@ -230,26 +234,27 @@
|
|||
</div>
|
||||
<div class="js_inputs js_shipping row" style="display:none">
|
||||
<h3 class="span8 oe_shipping" style="display:none">Shipping Information</h3>
|
||||
<label class="span8 css_required">Name and firstname<input class="span7" type="text" name="shipping_name" placeholder="Name and firstname"/></label>
|
||||
<label class="span4 css_required">Telephone<input type="tel" name="shipping_phone" placeholder="Telephone"/></label>
|
||||
<label class="span4">Fax<input type="tel" name="shipping_fax" placeholder="Fax"/></label>
|
||||
<label class="span8 css_required">Street<input class="span7" type="text" name="shipping_street" placeholder="Street address"/></label>
|
||||
<label class="span4 css_required">City<input type="text" name="shipping_city" placeholder="City"/></label>
|
||||
<label class="span8 css_required">Name and firstname<input class="span7" type="text" name="shipping_name" placeholder="Name and firstname" t-att-value="shipping.name or ''"/></label>
|
||||
<label class="span4 css_required">Telephone<input type="tel" name="shipping_phone" placeholder="Telephone" t-att-value="shipping.phone or ''"/></label>
|
||||
<label class="span4">Fax<input type="tel" name="shipping_fax" placeholder="Fax" t-att-value="shipping.fax or ''"/></label>
|
||||
<label class="span8 css_required">Street<input class="span7" type="text" name="shipping_street" placeholder="Street address" t-att-value="shipping.street or ''"/></label>
|
||||
<label class="span4 css_required">City<input type="text" name="shipping_city" placeholder="City" t-att-value="shipping.city or ''"/></label>
|
||||
<label class="span4">State / Province <select name="shipping_state_id">
|
||||
<option value="">State / Province...</option>
|
||||
<t t-foreach="states or []" t-as="state">
|
||||
<option t-att-value="state.id" t-att-selected="partner and partner.state_id and state.id == partner.state_id.id or None"><t t-esc="state.name"/></option>
|
||||
<option t-att-value="state.id" t-att-selected="shipping and shipping.state_id and state.id == shipping.state_id.id or None"><t t-esc="state.name"/></option>
|
||||
</t>
|
||||
</select></label>
|
||||
<label class="span4 css_required">Zip / Postal Code<input type="text" name="shipping_zip" placeholder="Zip/Postal Code"/></label>
|
||||
<label class="span4 css_required">Zip / Postal Code<input type="text" name="shipping_zip" placeholder="Zip/Postal Code" t-att-value="shipping.zip or ''"/></label>
|
||||
<label class="span4 css_required">Country <select name="shipping_country_id">
|
||||
<option value="">Country...</option>
|
||||
<t t-foreach="countries or []" t-as="country">
|
||||
<option t-att-value="country.id" t-att-selected="partner and partner.country_id and country.id == partner.country_id.id or None"><t t-esc="country.name"/></option>
|
||||
<option t-att-value="country.id" t-att-selected="shipping and shipping.country_id and country.id == shipping.country_id.id or None"><t t-esc="country.name"/></option>
|
||||
</t>
|
||||
</select></label>
|
||||
</div>
|
||||
<div class="js_payments css_payments">
|
||||
<div class="js_payments css_payments row">
|
||||
<h3 class="span8">Choose your payment method</h3>
|
||||
<div class="css_payment">
|
||||
<div class="js_error_payment css_error_payment"> </div>
|
||||
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
|
||||
|
@ -268,11 +273,30 @@
|
|||
</t>
|
||||
</template>
|
||||
|
||||
<template id="thanks">
|
||||
<template id="confirmed">
|
||||
<t t-call="website_sale.page">
|
||||
<t t-set="title">Order</t>
|
||||
<t t-set="shop_content">
|
||||
Thanks for your sale order
|
||||
<div class="oe_total">
|
||||
<table class="table table-condensed" t-if="order.order_line">
|
||||
<thead>
|
||||
<tr><th>Product</th><th>Qty.</th><th>Price</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<t t-foreach="order.order_line or []" t-as="line">
|
||||
<tr>
|
||||
<td><t t-esc="line.product_id.name"/></td>
|
||||
<td><t t-esc="int(line.product_uom_qty)"/></td>
|
||||
<td class="css_alignright"><t t-esc="line.product_id.list_price"/> €</td>
|
||||
</tr>
|
||||
</t>
|
||||
<tr><td colspan="3" style="visibility: hidden; border: 0">-</td></tr>
|
||||
<tr><th>Untaxed Amount</th><td></td><td><t t-esc="order.amount_untaxed"/> €</td></tr>
|
||||
<tr><th>Taxes</th><td></td><td><t t-esc="order.amount_tax"/> €</td></tr>
|
||||
<tr><th>Total</th><td></td><td><t t-esc="order.amount_total"/> €</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</t>
|
||||
</t>
|
||||
</template>
|
||||
|
|
Loading…
Reference in New Issue