From 6272ac13ff0dee22565e9e3915876963d7c8d235 Mon Sep 17 00:00:00 2001 From: jem-odoo Date: Mon, 20 Nov 2017 10:21:37 +0100 Subject: [PATCH] [IMP] sale: factorize condition to determine sol on AAL Simple code 'optimization' to make it clearer and reduce the number of generated environnement. --- addons/sale/models/analytic.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/sale/models/analytic.py b/addons/sale/models/analytic.py index ae0e5ab3d7f..7c92065aa05 100644 --- a/addons/sale/models/analytic.py +++ b/addons/sale/models/analytic.py @@ -41,7 +41,7 @@ class AccountAnalyticLine(models.Model): @api.multi def _sale_postprocess(self, values, additional_so_lines=None): if 'so_line' not in values: # allow to force a False value for so_line - self.with_context(sale_analytic_norecompute=True)._sale_determine_order_line() + self.sudo().filtered(lambda aal: not aal.so_line and aal.product_id and aal.product_id.expense_policy != 'no').with_context(sale_analytic_norecompute=True)._sale_determine_order_line() if any(field_name in values for field_name in self._sale_get_fields_delivered_qty()): if not self._context.get('sale_analytic_norecompute'): @@ -102,7 +102,7 @@ class AccountAnalyticLine(models.Model): @api.multi def _sale_determine_order(self): mapping = {} - for analytic_line in self.sudo().filtered(lambda aal: not aal.so_line and aal.product_id and aal.product_id.expense_policy != 'no'): + for analytic_line in self: sale_order = self.env['sale.order'].search([('analytic_account_id', '=', analytic_line.account_id.id), ('state', '=', 'sale')], limit=1) if not sale_order: sale_order = self.env['sale.order'].search([('analytic_account_id', '=', analytic_line.account_id.id)], limit=1) @@ -119,7 +119,7 @@ class AccountAnalyticLine(models.Model): # determine SO : first SO open linked to AA sale_order_map = self._sale_determine_order() # determine so line - for analytic_line in self.sudo().filtered(lambda aal: not aal.so_line and aal.product_id and aal.product_id.expense_policy != 'no'): + for analytic_line in self: sale_order = sale_order_map.get(analytic_line.id) if not sale_order: continue