From 89958e5cfe48d3ac41a1026ff00d7e8477c73b9e Mon Sep 17 00:00:00 2001 From: Daniel Reis Date: Tue, 17 Dec 2019 13:30:51 +0000 Subject: [PATCH] [FIX] Ensure Analytic Account is copied from SO to Agreement --- agreement_legal_sale/models/agreement.py | 3 ++- agreement_legal_sale/models/sale_order.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/agreement_legal_sale/models/agreement.py b/agreement_legal_sale/models/agreement.py index 6e064886..47ba502e 100644 --- a/agreement_legal_sale/models/agreement.py +++ b/agreement_legal_sale/models/agreement.py @@ -9,7 +9,8 @@ class Agreement(models.Model): sale_id = fields.Many2one('sale.order', string='Sales Order') analytic_account_id = fields.Many2one( - 'account.analytic.account', 'Analytic Account', readonly=True, + 'account.analytic.account', + 'Analytic Account', copy=False) diff --git a/agreement_legal_sale/models/sale_order.py b/agreement_legal_sale/models/sale_order.py index 95cde3dd..53967e2f 100644 --- a/agreement_legal_sale/models/sale_order.py +++ b/agreement_legal_sale/models/sale_order.py @@ -44,3 +44,18 @@ class SaleOrder(models.Model): 'agreement_id': order.agreement_id.id, }) return res + + def action_confirm(self): + # If sale_timesheet is installed, the _action_confirm() + # may be setting an Analytic Account on the SO. + # But since it is not a dependency, that can happen after + # we create the Agreement. + # To work around that, we check if that is the case, + # and make sure the SO Analytic Account is copied to the Agreement. + res = super(SaleOrder, self).action_confirm() + for order in self: + agreement = order.agreement_id + if (order.analytic_account_id and agreement and + not agreement.analytic_account_id): + agreement.analytic_account_id = order.analytic_account_id + return res