From 0b17ef6b647bdc9b78583985f45f8ad8a06bbc3b Mon Sep 17 00:00:00 2001 From: jordan <jordan@le-filament.com> Date: Thu, 18 Nov 2021 13:24:27 +0100 Subject: [PATCH] [update] remove useless line_section in sale_order --- models/__init__.py | 1 + models/sale_order.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 models/sale_order.py diff --git a/models/__init__.py b/models/__init__.py index d3f915a..6e64884 100644 --- a/models/__init__.py +++ b/models/__init__.py @@ -2,3 +2,4 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) from . import sale_project +from . import sale_order diff --git a/models/sale_order.py b/models/sale_order.py new file mode 100644 index 0000000..2a39c40 --- /dev/null +++ b/models/sale_order.py @@ -0,0 +1,29 @@ +# Copyright 2021 Le Filament (https://le-filament.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from odoo import models + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + # ------------------------------------------------------ + # Business method + # ------------------------------------------------------ + def clean_sale_order(self): + super(SaleOrder, self).clean_sale_order() + sol_line_section = self.order_line.filtered( + lambda s: s.display_type == 'line_section' and s.sale_project_id is not None + ) + for sol_section in sol_line_section: + next_sol = False + for sol in self.order_line.sorted(key=lambda r: (r.sequence, r.id)): + if sol.sequence > sol_section.sequence \ + or (sol.sequence == sol_section.sequence + and sol.id > sol_section.id): + next_sol = sol + break + if not next_sol or\ + next_sol.sale_project_id != sol_section.sale_project_id \ + or not next_sol.product_id: + sol_section.unlink() -- GitLab