Permalink
Browse files

[FIX] website_sale: performance when creating a cart

- When creating an eCommerce cart using the Public User, the code tries
  to access all the sale orders linked to it.

  Depending on the count of sale orders linked to the partner, the
  loading can take a lot of time.

  To avoid this, we only search for the sale orders of connected users
  and we only retrieve the last one.
  • Loading branch information...
tbe-odoo committed Oct 26, 2018
1 parent ae3997b commit fe518f1feaabc0101e201b2542acf18deca9693f
Showing with 4 additions and 2 deletions.
  1. +4 −2 addons/website_sale/models/website.py
@@ -161,8 +161,10 @@ def _prepare_sale_order_values(self, partner, pricelist):
affiliate_id = request.session.get('affiliate_id')
salesperson_id = affiliate_id if self.env['res.users'].sudo().browse(affiliate_id).exists() else request.website.salesperson_id.id
addr = partner.address_get(['delivery', 'invoice'])
if len(partner.sale_order_ids): # first = me
addr['delivery'] = partner.sale_order_ids[0].partner_shipping_id.id
if not request.website.is_public_user():
last_sale_order = self.env['sale.order'].search([('partner_id', '=', partner.id)], limit=1, order="date_order desc, id desc")
if last_sale_order: # first = me
addr['delivery'] = last_sale_order.partner_shipping_id.id
default_user_id = partner.parent_id.user_id.id or partner.user_id.id
values = {
'partner_id': partner.id,

0 comments on commit fe518f1

Please sign in to comment.