1 # -*- coding: utf-8 -*-
7 from openerp import SUPERUSER_ID
8 from openerp.addons.web import http
9 from openerp.addons.web.http import request
10 from openerp.addons.website.models import website
12 PPG = 20 # Products Per Page
13 PPR = 4 # Products Per Row
16 class CheckoutInfo(object):
17 mandatory_billing_fields = ["name", "phone", "email", "street", "city", "country_id", "zip"]
18 optional_billing_fields = ["company", "state_id"]
19 string_billing_fields = ["name", "phone", "email", "street", "city", "zip"]
21 mandatory_shipping_fields = ["shipping_name", "shipping_phone", "shipping_street", "shipping_city", "shipping_country_id", "shipping_zip"]
22 optional_shipping_field = ["shipping_state_id"]
23 string_shipping_fields = ["shipping_name", "shipping_phone", "shipping_street", "shipping_city", "shipping_zip"]
25 def mandatory_fields(self):
26 return self.mandatory_billing_fields + self.mandatory_shipping_fields
28 def optional_fields(self):
29 return self.optional_billing_fields + self.optional_shipping_field
32 return self.mandatory_fields() + self.optional_fields()
35 return dict.fromkeys(self.all_fields(), '')
37 def from_partner(self, partner, address_type='billing'):
38 assert address_type in ('billing', 'shipping')
39 if address_type == 'billing':
43 result = dict((prefix + field_name, getattr(partner, field_name)) for field_name in self.string_billing_fields if getattr(partner, field_name))
44 result[prefix + 'state_id'] = partner.state_id and partner.state_id.id or ''
45 result[prefix + 'country_id'] = partner.country_id and partner.country_id.id or ''
46 result[prefix + 'company'] = partner.parent_id and partner.parent_id.name or ''
49 def from_post(self, post):
50 return dict((field_name, post[field_name]) for field_name in self.all_fields() if post[field_name])
54 # Compute grid of products according to their sizes
56 class table_compute(object):
60 def _check_place(self, posx, posy, sizex, sizey):
61 for y in range(sizey):
62 for x in range(sizex):
65 row = self.table.setdefault(posy+y, {})
66 if row.setdefault(posx+x) is not None:
70 def process(self, products):
71 # Compute products positions on the grid
82 while not self._check_place(pos%PPR, pos/PPR, x, y):
85 if index>PPG and (pos/PPR)>maxy:
88 if x==1 and y==1: # simple heuristic for CPU optimization
93 self.table[(pos/PPR)+y2][(pos%PPR)+x2] = False
94 self.table[pos/PPR][pos%PPR] = {
95 'product': p, 'x':x, 'y': y,
96 'class': " ".join(map(lambda x: x.html_class, p.website_style_ids))
99 maxy=max(maxy,y+(pos/PPR))
102 # Format table according to HTML needs
103 rows = self.table.items()
105 rows = map(lambda x: x[1], rows)
106 for col in range(len(rows)):
107 cols = rows[col].items()
109 rows[col] = map(lambda x: x[1], cols)
110 return filter(bool, rows)
113 class Ecommerce(http.Controller):
115 _order = 'website_published desc, website_sequence desc'
117 def get_characteristic_ids(self):
118 characteristics_obj = request.registry['product.characteristic']
119 characteristics_ids = characteristics_obj.search(request.cr, request.uid, [], context=request.context)
120 return characteristics_obj.browse(request.cr, request.uid, characteristics_ids, context=request.context)
122 def get_pricelist(self):
123 """ Shortcut to get the pricelist from the website model """
124 return request.registry['website'].ecommerce_get_pricelist_id(request.cr, request.uid, None, context=request.context)
127 """ Shortcut to get the current ecommerce quotation from the website model """
128 return request.registry['website'].ecommerce_get_current_order(request.cr, request.uid, context=request.context)
130 def get_products(self, product_ids):
131 product_obj = request.registry.get('product.template')
132 request.context['pricelist'] = self.get_pricelist()
133 # search for checking of access rules and keep order
134 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)]
135 return product_obj.browse(request.cr, request.uid, product_ids, context=request.context)
137 def has_search_filter(self, characteristic_id, value_id=None):
138 if request.httprequest.args.get('filters'):
139 filters = simplejson.loads(request.httprequest.args['filters'])
142 for key_val in filters:
143 if key_val[0] == characteristic_id and (not value_id or value_id in key_val[1:]):
147 @http.route(['/shop/filters/'], type='http', auth="public", website=True, multilang=True)
148 def filters(self, **post):
151 for key, val in post.items():
153 if len(cat) < 3 or cat[2] in ('max','minmem','maxmem'):
157 minmem = float(post.pop("att-%s-minmem" % cat[1]))
158 maxmem = float(post.pop("att-%s-maxmem" % cat[1]))
159 _max = int(post.pop("att-%s-max" % cat[1]))
161 if (minmem != _min or maxmem != _max) and cat_id not in index:
162 filters.append([cat_id , [_min, _max] ])
164 elif cat_id not in index:
165 filters.append([ cat_id, int(cat[2]) ])
169 if cat[2] not in filters[index.index(cat_id)][1:]:
170 filters[index.index(cat_id)].append( cat[2] )
173 return request.redirect("/shop/?filters=%s%s%s" % (
174 simplejson.dumps(filters),
175 post.get("search") and ("&search=%s" % post.get("search")) or "",
176 post.get("category") and ("&category=%s" % post.get("category")) or ""
179 def characteristics_to_ids(self, characteristics):
180 obj = request.registry.get('product.characteristic.product')
182 for key_val in characteristics:
183 domain.append(("characteristic_id", "=", key_val[0]))
184 if isinstance(key_val[1], list):
185 domain.append(("value", ">=", key_val[1][0]))
186 domain.append(("value", "<=", key_val[1][1]))
188 domain.append(("value_id", "in", key_val[1:]))
189 att_ids = obj.search(request.cr, request.uid, domain, context=request.context)
190 att = obj.read(request.cr, request.uid, att_ids, ["product_tmpl_id"], context=request.context)
191 return [r["product_tmpl_id"][0] for r in att]
193 @http.route(['/shop/pricelist'], type='http', auth="public", website=True, multilang=True)
194 def shop_promo(self, promo=None, **post):
195 request.registry['website']._ecommerce_change_pricelist(request.cr, request.uid, code=promo, context=request.context)
196 return request.redirect("/shop/mycart/")
200 '/shop/page/<int:page>/',
201 '/shop/category/<model("product.public.category"):category>/',
202 '/shop/category/<model("product.public.category"):category>/page/<int:page>/'
203 ], type='http', auth="public", website=True, multilang=True)
204 def shop(self, category=None, page=0, filters='', search='', **post):
205 cr, uid, context = request.cr, request.uid, request.context
206 product_obj = request.registry.get('product.template')
207 domain = request.registry.get('website').ecommerce_get_product_domain()
210 ('name', 'ilike', "%%%s%%" % search),
211 ('description', 'ilike', "%%%s%%" % search)]
213 domain.append(('product_variant_ids.public_categ_id', 'child_of', category.id))
215 filters = simplejson.loads(filters)
217 ids = self.characteristics_to_ids(filters)
218 domain.append(('id', 'in', ids or [0]))
220 product_count = product_obj.search_count(cr, uid, domain, context=context)
221 pager = request.website.pager(url="/shop/", total=product_count, page=page, step=PPG, scope=7, url_args=post)
223 request.context['pricelist'] = self.get_pricelist()
225 pids = product_obj.search(cr, uid, domain, limit=PPG+10, offset=pager['offset'], order=self._order, context=context)
226 products = product_obj.browse(cr, uid, pids, context=context)
230 style_obj = request.registry.get('website.product.style')
231 style_ids = style_obj.search(request.cr, request.uid, [], context=request.context)
232 styles = style_obj.browse(request.cr, request.uid, style_ids, context=request.context)
236 category_obj = request.registry.get('product.public.category')
237 category_ids = category_obj.search(cr, uid, [], context=context)
238 categories = category_obj.browse(cr, uid, category_ids, context=context)
239 categs = filter(lambda x: not x.parent_id, categories)
242 'products': products,
243 'bins': table_compute().process(products),
248 'category': category and category.id,
253 'categories': categs,
254 'Ecommerce': self, # TODO fp: Should be removed
255 'style_in_product': lambda style, product: style.id in [s.id for s in product.website_style_ids],
257 return request.website.render("website_sale.products", values)
259 @http.route(['/shop/product/<model("product.template"):product>/'], type='http', auth="public", website=True, multilang=True)
260 def product(self, product, search='', category='', filters='', **kwargs):
261 website.preload_records(product, on_error="website_sale.404")
263 category_obj = request.registry.get('product.public.category')
265 category_ids = category_obj.search(request.cr, request.uid, [], context=request.context)
266 category_list = category_obj.name_get(request.cr, request.uid, category_ids, context=request.context)
267 category_list = sorted(category_list, key=lambda category: category[1])
270 category = category_obj.browse(request.cr, request.uid, int(category), context=request.context)
272 request.context['pricelist'] = self.get_pricelist()
276 'category': category,
277 'category_list': category_list,
278 'main_object': product,
282 'category': category and str(category.id),
286 return request.website.render("website_sale.product", values)
288 @http.route(['/shop/product/comment'], type='http', auth="public", methods=['POST'], website=True)
289 def product_comment(self, product_template_id, **post):
290 cr, uid, context = request.cr, request.uid, request.context
291 if post.get('comment'):
292 request.registry['product.template'].message_post(
293 cr, uid, product_template_id,
294 body=post.get('comment'),
296 subtype='mt_comment',
297 context=dict(context, mail_create_nosubcribe=True))
298 return werkzeug.utils.redirect(request.httprequest.referrer + "#comments")
300 @http.route(['/shop/add_product/'], type='http', auth="user", methods=['POST'], website=True, multilang=True)
301 def add_product(self, name="New Product", category=0, **post):
302 Product = request.registry.get('product.product')
303 product_id = Product.create(request.cr, request.uid, {
304 'name': name, 'public_categ_id': category
305 }, context=request.context)
306 product = Product.browse(request.cr, request.uid, product_id, context=request.context)
308 return request.redirect("/shop/product/%s/?enable_editor=1" % product.product_tmpl_id.id)
310 @http.route(['/shop/mycart/'], type='http', auth="public", website=True, multilang=True)
311 def mycart(self, **post):
312 cr, uid, context = request.cr, request.uid, request.context
313 prod_obj = request.registry.get('product.product')
315 # must have a draft sale order with lines at this point, otherwise reset
316 order = self.get_order()
317 if order and order.state != 'draft':
318 request.registry['website'].sale_reset_order(cr, uid, context=context)
319 return request.redirect('/shop/')
326 for line in order.order_line:
327 suggested_ids += [p.id for p in line.product_id and line.product_id.suggested_product_ids or []]
328 product_ids.append(line.product_id.id)
329 suggested_ids = list(set(suggested_ids) - set(product_ids))
331 suggested_ids = prod_obj.search(cr, uid, [('id', 'in', suggested_ids)], context=context)
333 # select 3 random products
334 suggested_products = []
335 while len(suggested_products) < 3 and suggested_ids:
336 index = random.randrange(0, len(suggested_ids))
337 suggested_products.append(suggested_ids.pop(index))
339 context = dict(context or {}, pricelist=request.registry['website'].ecommerce_get_pricelist_id(cr, uid, None, context=context))
343 'suggested_products': prod_obj.browse(cr, uid, suggested_products, context),
345 return request.website.render("website_sale.mycart", values)
347 @http.route(['/shop/add_cart/'], type='http', auth="public", methods=['POST'], website=True, multilang=True)
348 def add_cart(self, product_id, remove=None, **kw):
349 request.registry['website']._ecommerce_add_product_to_cart(request.cr, request.uid,
350 product_id=int(product_id),
351 context=request.context)
352 return request.redirect("/shop/mycart/")
354 @http.route(['/shop/change_cart/<int:order_line_id>/'], type='http', auth="public", website=True, multilang=True)
355 def add_cart_order_line(self, order_line_id=None, remove=None, **kw):
356 request.registry['website']._ecommerce_add_product_to_cart(request.cr, request.uid,
357 order_line_id=order_line_id, number=(remove and -1 or 1),
358 context=request.context)
359 return request.redirect("/shop/mycart/")
361 @http.route(['/shop/add_cart_json/'], type='json', auth="public", website=True)
362 def add_cart_json(self, product_id=None, order_line_id=None, remove=None):
363 quantity = request.registry['website']._ecommerce_add_product_to_cart(request.cr, request.uid,
364 product_id=product_id, order_line_id=order_line_id, number=(remove and -1 or 1),
365 context=request.context)
366 order = self.get_order()
368 order.get_number_of_products(),
370 request.website._render("website_sale.total", {'website_sale_order': order})]
372 @http.route(['/shop/set_cart_json/'], type='json', auth="public", website=True)
373 def set_cart_json(self, path=None, product_id=None, order_line_id=None, set_number=0, json=None):
374 return request.registry['website']._ecommerce_add_product_to_cart(request.cr, request.uid,
375 product_id=product_id, order_line_id=order_line_id, set_number=set_number,
376 context=request.context)
378 @http.route(['/shop/checkout/'], type='http', auth="public", website=True, multilang=True)
379 def checkout(self, **post):
380 cr, uid, context, registry = request.cr, request.uid, request.context, request.registry
382 # must have a draft sale order with lines at this point, otherwise reset
383 order = self.get_order()
384 if not order or order.state != 'draft' or not order.order_line:
385 request.registry['website'].ecommerce_reset(cr, uid, context=context)
386 return request.redirect('/shop/')
387 # if transaction pending / done: redirect to confirmation
388 tx = context.get('website_sale_transaction')
389 if tx and tx.state != 'draft':
390 return request.redirect('/shop/payment/confirmation/%s' % order.id)
394 orm_partner = registry.get('res.partner')
395 orm_user = registry.get('res.users')
396 orm_country = registry.get('res.country')
397 country_ids = orm_country.search(cr, SUPERUSER_ID, [], context=context)
398 countries = orm_country.browse(cr, SUPERUSER_ID, country_ids, context)
399 state_orm = registry.get('res.country.state')
400 states_ids = state_orm.search(cr, SUPERUSER_ID, [], context=context)
401 states = state_orm.browse(cr, SUPERUSER_ID, states_ids, context)
403 info = CheckoutInfo()
405 'countries': countries,
407 'checkout': info.empty(),
408 'shipping': post.get("shipping_different"),
411 checkout = values['checkout']
412 error = values['error']
415 public_id = request.registry['website'].get_public_user(cr, uid, context)
416 if not request.uid == public_id:
417 partner = orm_user.browse(cr, uid, uid, context).partner_id
418 elif order.partner_id and (not order.partner_id.user_ids or public_id not in [u.id for u in order.partner_id.user_ids]):
419 partner = orm_partner.browse(cr, SUPERUSER_ID, order.partner_id.id, context)
422 partner_info = info.from_partner(partner)
423 checkout.update(partner_info)
424 shipping_ids = orm_partner.search(cr, SUPERUSER_ID, [("parent_id", "=", partner.id), ('type', "=", 'delivery')], limit=1, context=context)
426 values['shipping'] = "true"
427 shipping_partner = orm_partner.browse(cr, SUPERUSER_ID, shipping_ids[0], context)
428 checkout.update(info.from_partner(shipping_partner, address_type='shipping'))
430 return request.website.render("website_sale.checkout", values)
432 @http.route(['/shop/confirm_order/'], type='http', auth="public", website=True, multilang=True)
433 def confirm_order(self, **post):
434 cr, uid, context, registry = request.cr, request.uid, request.context, request.registry
435 order_line_obj = request.registry.get('sale.order')
437 # must have a draft sale order with lines at this point, otherwise redirect to shop
438 order = self.get_order()
439 if not order or order.state != 'draft' or not order.order_line:
440 request.registry['website'].ecommerce_reset(cr, uid, context=context)
441 return request.redirect('/shop/')
442 # if transaction pending / done: redirect to confirmation
443 tx = context.get('website_sale_transaction')
444 if tx and tx.state != 'draft':
445 return request.redirect('/shop/payment/confirmation/%s' % order.id)
447 orm_parter = registry.get('res.partner')
448 orm_user = registry.get('res.users')
449 orm_country = registry.get('res.country')
450 country_ids = orm_country.search(cr, SUPERUSER_ID, [], context=context)
451 countries = orm_country.browse(cr, SUPERUSER_ID, country_ids, context)
452 orm_state = registry.get('res.country.state')
453 states_ids = orm_state.search(cr, SUPERUSER_ID, [], context=context)
454 states = orm_state.browse(cr, SUPERUSER_ID, states_ids, context)
456 info = CheckoutInfo()
458 'countries': countries,
460 'checkout': info.empty(),
461 'shipping': post.get("shipping_different"),
464 checkout = values['checkout']
465 checkout.update(post)
466 error = values['error']
468 for field_name in info.mandatory_billing_fields:
469 if not checkout[field_name]:
470 error[field_name] = 'missing'
471 if post.get("shipping_different"):
472 for field_name in info.mandatory_shipping_fields:
473 if not checkout[field_name]:
474 error[field_name] = 'missing'
476 return request.website.render("website_sale.checkout", values)
478 company_name = checkout['company']
481 company_ids = orm_parter.search(cr, SUPERUSER_ID, [("name", "ilike", company_name), ('is_company', '=', True)], context=context)
482 company_id = (company_ids and company_ids[0]) or orm_parter.create(cr, SUPERUSER_ID, {'name': company_name, 'is_company': True}, context)
484 billing_info = dict((k, v) for k,v in checkout.items() if "shipping_" not in k and k != "company")
485 billing_info['parent_id'] = company_id
487 if request.uid != request.registry['website'].get_public_user(cr, uid, context):
488 partner_id = orm_user.browse(cr, SUPERUSER_ID, uid, context=context).partner_id.id
489 orm_parter.write(cr, SUPERUSER_ID, [partner_id], billing_info, context=context)
491 partner_id = orm_parter.create(cr, SUPERUSER_ID, billing_info, context=context)
494 if post.get('shipping_different'):
496 'phone': post['shipping_phone'],
497 'zip': post['shipping_zip'],
498 'street': post['shipping_street'],
499 'city': post['shipping_city'],
500 'name': post['shipping_name'],
501 'email': post['email'],
503 'parent_id': partner_id,
504 'country_id': post['shipping_country_id'],
505 'state_id': post['shipping_state_id'],
507 domain = [(key, '_id' in key and '=' or 'ilike', '_id' in key and value and int(value) or value)
508 for key, value in shipping_info.items() if key in info.mandatory_billing_fields + ["type", "parent_id"]]
510 shipping_ids = orm_parter.search(cr, SUPERUSER_ID, domain, context=context)
512 shipping_id = shipping_ids[0]
513 orm_parter.write(cr, SUPERUSER_ID, [shipping_id], shipping_info, context)
515 shipping_id = orm_parter.create(cr, SUPERUSER_ID, shipping_info, context)
518 'partner_id': partner_id,
519 'message_follower_ids': [(4, partner_id)],
520 'partner_invoice_id': partner_id,
521 'partner_shipping_id': shipping_id or partner_id
524 order_info.update(registry.get('sale.order').onchange_partner_id(cr, SUPERUSER_ID, [], partner_id, context=context)['value'])
527 order_line_obj.write(cr, SUPERUSER_ID, [order.id], order_info, context=context)
529 return request.redirect("/shop/payment/")
531 @http.route(['/shop/payment/'], type='http', auth="public", website=True, multilang=True)
532 def payment(self, **post):
533 """ Payment step. This page proposes several payment means based on available
534 payment.acquirer. State at this point :
536 - a draft sale order with lines; otherwise, clean context / session and
538 - no transaction in context / session, or only a draft one, if the customer
539 did go to a payment.acquirer website but closed the tab without
542 cr, uid, context = request.cr, request.uid, request.context
543 payment_obj = request.registry.get('payment.acquirer')
545 # if no sale order at this stage: back to checkout beginning
546 order = self.get_order()
547 if not order or order.state != 'draft' or not order.order_line:
548 request.registry['website'].ecommerce_reset(cr, uid, context=context)
549 return request.redirect("/shop/")
550 # alread a transaction: forward to confirmation
551 tx = context.get('website_sale_transaction')
552 if tx and tx.state != 'draft':
553 return request.redirect('/shop/confirmation/%s' % order.id)
555 shipping_partner_id = False
557 if order.partner_shipping_id.id:
558 shipping_partner_id = order.partner_shipping_id.id
560 shipping_partner_id = order.partner_invoice_id.id
563 'order': request.registry['sale.order'].browse(cr, SUPERUSER_ID, order.id, context=context)
565 values.update(request.registry.get('sale.order')._get_website_data(cr, uid, order, context))
567 # fetch all registered payment means
569 acquirer_ids = [tx.acquirer_id.id]
571 acquirer_ids = payment_obj.search(cr, SUPERUSER_ID, [('portal_published', '=', True)], context=context)
572 values['acquirers'] = payment_obj.browse(cr, uid, acquirer_ids, context=context)
573 render_ctx = dict(context, submit_class='btn btn-primary', submit_txt='Pay Now')
574 for acquirer in values['acquirers']:
575 render_ctx['tx_url'] = '/shop/payment/transaction/%s' % acquirer.id
576 acquirer.button = payment_obj.render(
577 cr, SUPERUSER_ID, acquirer.id,
580 order.pricelist_id.currency_id.id,
581 partner_id=shipping_partner_id,
583 'return_url': '/shop/payment/validate',
587 return request.website.render("website_sale.payment", values)
589 @http.route(['/shop/payment/transaction/<int:acquirer_id>'],
590 type='http', methods=['POST'], auth="public", website=True)
591 def payment_transaction(self, acquirer_id, **post):
592 """ Hook method that creates a payment.transaction and redirect to the
593 acquirer, using post values to re-create the post action.
595 :param int acquirer_id: id of a payment.acquirer record. If not set the
596 user is redirected to the checkout page
597 :param dict post: should coutain all post data for the acquirer
599 # @TDEFIXME: don't know why we received those data, but should not be send to the acquirer
600 post.pop('submit.x', None)
601 post.pop('submit.y', None)
602 cr, uid, context = request.cr, request.uid, request.context
603 payment_obj = request.registry.get('payment.acquirer')
604 transaction_obj = request.registry.get('payment.transaction')
605 order = self.get_order()
607 if not order or not order.order_line or acquirer_id is None:
608 return request.redirect("/shop/checkout/")
610 # find an already existing transaction
611 tx = context.get('website_sale_transaction')
613 tx_id = transaction_obj.create(cr, SUPERUSER_ID, {
614 'acquirer_id': acquirer_id,
616 'amount': order.amount_total,
617 'currency_id': order.pricelist_id.currency_id.id,
618 'partner_id': order.partner_id.id,
619 'reference': order.name,
620 'sale_order_id': order.id,
622 request.httprequest.session['website_sale_transaction_id'] = tx_id
623 elif tx and tx.state == 'draft': # button cliked but no more info -> rewrite on tx or create a new one ?
625 'acquirer_id': acquirer_id,
628 acquirer_form_post_url = payment_obj.get_form_action_url(cr, uid, acquirer_id, context=context)
629 acquirer_total_url = '%s?%s' % (acquirer_form_post_url, urllib.urlencode(post))
630 return request.redirect(acquirer_total_url)
632 @http.route('/shop/payment/get_status/<int:sale_order_id>', type='json', auth="public", website=True, multilang=True)
633 def payment_get_status(self, sale_order_id, **post):
634 cr, uid, context = request.cr, request.uid, request.context
636 order = request.registry['sale.order'].browse(cr, SUPERUSER_ID, sale_order_id, context=context)
637 assert order.website_session_id == request.httprequest.session['website_session_id']
644 tx_ids = request.registry['payment.transaction'].search(
646 '|', ('sale_order_id', '=', order.id), ('reference', '=', order.name)
652 tx = request.registry['payment.transaction'].browse(cr, uid, tx_ids[0], context=context)
657 @http.route('/shop/payment/validate/', type='http', auth="public", website=True, multilang=True)
658 def payment_validate(self, transaction_id=None, sale_order_id=None, **post):
659 """ Method that should be called by the server when receiving an update
660 for a transaction. State at this point :
664 cr, uid, context = request.cr, request.uid, request.context
666 sale_order_obj = request.registry['sale.order']
668 if transaction_id is None:
669 tx = context.get('website_sale_transaction')
671 return request.redirect('/shop/')
673 tx = request.registry['payment.transaction'].browse(cr, uid, transaction_id, context=context)
675 if sale_order_id is None:
676 order = self.get_order()
678 order = request.registry['sale.order'].browse(cr, SUPERUSER_ID, sale_order_id, context=context)
679 assert order.website_session_id == request.httprequest.session['website_session_id']
681 if tx.state == 'done':
682 # confirm the quotation
683 sale_order_obj.action_button_confirm(cr, SUPERUSER_ID, [order.id], context=request.context)
685 email_act = sale_order_obj.action_quotation_send(cr, SUPERUSER_ID, [order.id], context=request.context)
686 elif tx.state == 'pending':
688 email_act = sale_order_obj.action_quotation_send(cr, SUPERUSER_ID, [order.id], context=request.context)
689 elif tx.state == 'cancel':
690 # cancel the quotation
691 sale_order_obj.action_cancel(cr, SUPERUSER_ID, [order.id], context=request.context)
693 # clean context and session, then redirect to the confirmation page
694 request.registry['website'].ecommerce_reset(cr, uid, context=context)
696 return request.redirect('/shop/confirmation/%s' % order.id)
698 @http.route(['/shop/confirmation/<int:sale_order_id>'], type='http', auth="public", website=True, multilang=True)
699 def payment_confirmation(self, sale_order_id, **post):
700 """ End of checkout process controller. Confirmation is basically seing
701 the status of a sale.order. State at this point :
703 - should not have any context / session info: clean them
704 - take a sale.order id, because we request a sale.order and are not
705 session dependant anymore
707 cr, uid, context = request.cr, request.uid, request.context
709 order = request.registry['sale.order'].browse(cr, SUPERUSER_ID, sale_order_id, context=context)
710 assert order.website_session_id == request.httprequest.session['website_session_id']
712 request.registry['website']._ecommerce_change_pricelist(cr, uid, None, context=context or {})
714 return request.website.render("website_sale.confirmation", {'order': order})
716 @http.route(['/shop/change_sequence/'], type='json', auth="public", website=True)
717 def change_sequence(self, id, sequence):
718 product_obj = request.registry.get('product.template')
719 if sequence == "top":
720 product_obj.set_sequence_top(request.cr, request.uid, [id], context=request.context)
721 elif sequence == "bottom":
722 product_obj.set_sequence_bottom(request.cr, request.uid, [id], context=request.context)
723 elif sequence == "up":
724 product_obj.set_sequence_up(request.cr, request.uid, [id], context=request.context)
725 elif sequence == "down":
726 product_obj.set_sequence_down(request.cr, request.uid, [id], context=request.context)
728 @http.route(['/shop/change_styles/'], type='json', auth="public", website=True)
729 def change_styles(self, id, style_id):
730 product_obj = request.registry.get('product.template')
731 product = product_obj.browse(request.cr, request.uid, id, context=request.context)
735 for style in product.website_style_ids:
736 if style.id == style_id:
737 remove.append(style.id)
741 style = request.registry.get('website.product.style').browse(request.cr, request.uid, style_id, context=request.context)
744 product.write({'website_style_ids': [(3, rid) for rid in remove]})
746 product.write({'website_style_ids': [(4, style.id)]})
750 @http.route(['/shop/change_size/'], type='json', auth="public", website=True)
751 def change_size(self, id, x, y):
752 product_obj = request.registry.get('product.template')
753 product = product_obj.browse(request.cr, request.uid, id, context=request.context)
754 return product.write({'website_size_x': x, 'website_size_y': y})
756 # vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4: