[FIX] website_sale_coupon: fix performance issue on cart update.
It was a bad idea to recompute_coupon_lines into the function 'sale_get_order'. This function is called several times on each pages. The purpose of this one is to return a browse record only and IF needed recompute more. But apply a method that take several secondes will dramastically reduce the ecommerce performance. Now, we call the method only when we change the cart and so potentially change the right to benefit of a coupon or not. And not at each call of the method 'sale_get_order'. In checkout, that reduce from 6 call on some page to one this costly method that take several seconds.
This commit is contained in:
@@ -3,4 +3,3 @@
|
||||
|
||||
import sale_coupon_rule
|
||||
import sale_order
|
||||
import website
|
||||
|
||||
@@ -17,3 +17,9 @@ class SaleOrder(models.Model):
|
||||
if error and delete:
|
||||
request.session.pop('error_promo_code')
|
||||
return error
|
||||
|
||||
@api.multi
|
||||
def _cart_update(self, product_id=None, line_id=None, add_qty=0, set_qty=0, attributes=None, **kwargs):
|
||||
res = super(SaleOrder, self)._cart_update(product_id=product_id, line_id=line_id, add_qty=add_qty, set_qty=set_qty, attributes=attributes, **kwargs)
|
||||
self.recompute_coupon_lines()
|
||||
return res
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from odoo import models, fields, api
|
||||
|
||||
|
||||
class Website(models.Model):
|
||||
_inherit = "website"
|
||||
|
||||
@api.multi
|
||||
def sale_get_order(self, force_create=False, code=None, update_pricelist=False, force_pricelist=False):
|
||||
order = super(Website, self).sale_get_order(force_create, code, update_pricelist, force_pricelist)
|
||||
order.recompute_coupon_lines()
|
||||
return order
|
||||
Reference in New Issue
Block a user