From 19ceece675176af5bb2e19ccdd48c60ff2f8098c Mon Sep 17 00:00:00 2001
From: Victor Feyens <vfe@odoo.com>
Date: Tue, 22 Mar 2022 08:09:50 +0000
Subject: [PATCH] [FIX] sale_management: SO company change should not reset all
 lines

unless there is another template to apply by default

closes odoo/odoo#86899

Task-id: 2798588
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
---
 addons/sale_management/models/sale_order.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/addons/sale_management/models/sale_order.py b/addons/sale_management/models/sale_order.py
index 6eb22c73cfe7..61a10d010f71 100644
--- a/addons/sale_management/models/sale_order.py
+++ b/addons/sale_management/models/sale_order.py
@@ -36,7 +36,9 @@ class SaleOrder(models.Model):
                 # Especially when installing sale_management in a db
                 # already containing SO records
                 continue
-            order.sale_order_template_id = order.company_id.sale_order_template_id.id
+            company_template = order.company_id.sale_order_template_id
+            if company_template and order.sale_order_template_id != company_template:
+                order.sale_order_template_id = order.company_id.sale_order_template_id.id
 
     @api.depends('partner_id', 'sale_order_template_id')
     def _compute_note(self):
-- 
GitLab