From 04dd0a2dd481ed2f9d134df8fbafb67edb07642e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Maes?= Date: Wed, 13 Sep 2017 16:30:55 +0200 Subject: [PATCH] [IMP] sale: create an ananlytic on SO confirmation when at least an expense product This behavior kind of disappear with 48ea59d46e26b7b5a8eebfe06740482f1a263d72 Moreover, since the Analytic Accounting is hidden, and a AA on expense is required to reinvoice product on SO, an AA should be on the SO as default value. --- addons/sale/models/sale.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py index 5ff3dc3ab77..9b354af7ab6 100644 --- a/addons/sale/models/sale.py +++ b/addons/sale/models/sale.py @@ -520,6 +520,12 @@ class SaleOrder(models.Model): self.force_quotation_send() if self.env['ir.config_parameter'].sudo().get_param('sale.auto_done_setting'): self.action_done() + + # create an analytic account if at least an expense product + if any([expense_policy != 'no' for expense_policy in self.order_line.mapped('product_id.expense_policy')]): + if not self.analytic_account_id: + self._create_analytic_account() + return True @api.multi @@ -786,7 +792,9 @@ class SaleOrderLine(models.Model): if line.state == 'sale': msg = _("Extra line with %s ") % (line.product_id.display_name,) line.order_id.message_post(body=msg) - + # create an analytic account if at least an expense product + if line.product_id.expense_policy != 'no' and not self.order_id.analytic_account_id: + self.order_id._create_analytic_account() return line def _update_line_quantity(self, values):