From e04b44dad1df732cf0bf09eb4ece825cb5432c67 Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Mon, 19 Sep 2016 15:28:24 +0200 Subject: [PATCH] [FIX] sale: Correct sale order management on accounting entries creation If an analytic account is not linked to sale order, do nothing (and do not return False which is not a valid value for a write ({} would have been valid)). We should allow the simple analytic accounting without sales order. --- addons/sale/models/sale_analytic.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/addons/sale/models/sale_analytic.py b/addons/sale/models/sale_analytic.py index 81852f4a8a2..36340863725 100644 --- a/addons/sale/models/sale_analytic.py +++ b/addons/sale/models/sale_analytic.py @@ -80,9 +80,7 @@ class AccountAnalyticLine(models.Model): so_line = result.get('so_line', False) or self.so_line if not so_line and self.account_id and self.product_id and (self.product_id.expense_policy != 'no'): order = self.env['sale.order'].search([('project_id', '=', self.account_id.id)], limit=1) - if not order: - return False - if order.state != 'sale': + if order and order.state != 'sale': raise UserError(_('The Sale Order %s linked to the Analytic Account must be validated before registering expenses.') % order.name) order = self.env['sale.order'].search([('project_id', '=', self.account_id.id), ('state', '=', 'sale')], limit=1)