From 3293ffa069e698fdae5c04aa2e4ea736daa0e39e Mon Sep 17 00:00:00 2001
From: Adrien Peiffer <adrien.peiffer@acsone.eu>
Date: Mon, 11 Jul 2022 15:03:24 +0000
Subject: [PATCH] [FIX] sale: avoid creating analytic lines for section &
 notes.

Currently, When we create an invoice from a sale order containing some notes or sections. The analytic account from the sale order is set on the invoice/move line. During the creation of analytic lines, a line is created from the section/note line.

This commit makes no analytic line is created for section/notes.

Video :

https://youtu.be/AqyrXEIcKvg

--
I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr

closes odoo/odoo#95786

Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
---
 addons/sale/models/sale.py                      | 2 +-
 addons/sale/wizard/sale_make_invoice_advance.py | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py
index 97a1fd182470..e0da4ed71db0 100644
--- a/addons/sale/models/sale.py
+++ b/addons/sale/models/sale.py
@@ -1521,7 +1521,7 @@ class SaleOrderLine(models.Model):
             'discount': self.discount,
             'price_unit': self.price_unit,
             'tax_ids': [(6, 0, self.tax_id.ids)],
-            'analytic_account_id': self.order_id.analytic_account_id.id,
+            'analytic_account_id': self.order_id.analytic_account_id.id if not self.display_type else False,
             'analytic_tag_ids': [(6, 0, self.analytic_tag_ids.ids)],
             'sale_line_ids': [(4, self.id)],
         }
diff --git a/addons/sale/wizard/sale_make_invoice_advance.py b/addons/sale/wizard/sale_make_invoice_advance.py
index ea47e0145171..68e8d5f95bdc 100644
--- a/addons/sale/wizard/sale_make_invoice_advance.py
+++ b/addons/sale/wizard/sale_make_invoice_advance.py
@@ -97,7 +97,7 @@ class SaleAdvancePaymentInv(models.TransientModel):
                 'tax_ids': [(6, 0, so_line.tax_id.ids)],
                 'sale_line_ids': [(6, 0, [so_line.id])],
                 'analytic_tag_ids': [(6, 0, so_line.analytic_tag_ids.ids)],
-                'analytic_account_id': order.analytic_account_id.id or False,
+                'analytic_account_id': order.analytic_account_id.id if not so_line.display_type and order.analytic_account_id.id else False,
             })],
         }
 
-- 
GitLab