[FIX] website: last_website_so_id is website dependent
Before this commit, if you use this field outside of a controller website, it will fail because this field depend of request.website that is only set on controller of type website. Now we return False if we call try to use this field outside of the website. Eg: call get_current_pricelist in json
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models
|
||||
from odoo.http import request
|
||||
|
||||
|
||||
class ResPartner(models.Model):
|
||||
@@ -12,6 +13,11 @@ class ResPartner(models.Model):
|
||||
@api.multi
|
||||
def _compute_last_website_so_id(self):
|
||||
SaleOrder = self.env['sale.order']
|
||||
website_team = self.env.ref('sales_team.salesteam_website_sales', raise_if_not_found=False)
|
||||
for partner in self:
|
||||
current_website_so = SaleOrder.search([('partner_id', '=', partner.id)]).filtered(lambda so: so.order_line.mapped('product_id.product_tmpl_id').can_access_from_current_website())
|
||||
partner.last_website_so_id = current_website_so and current_website_so[0]
|
||||
if request and hasattr(request, 'website'):
|
||||
my_website_so = SaleOrder.search([('partner_id', '=', partner.id), ('team_id', '=', website_team.id)])
|
||||
current_website_orders = my_website_so.filtered(lambda so: so.order_line.mapped('product_id.product_tmpl_id').can_access_from_current_website())
|
||||
partner.last_website_so_id = current_website_orders and current_website_orders[0]
|
||||
else:
|
||||
partner.last_website_so_id = False # Not in a website context
|
||||
|
||||
Reference in New Issue
Block a user