From 8fd7c2030ebd24b8297abe8225ebe32c24f4373a Mon Sep 17 00:00:00 2001
From: jordan <jordan@le-filament.com>
Date: Thu, 18 Nov 2021 12:42:11 +0100
Subject: [PATCH] [update] refactor code to put update_order_lines in project +
add clean_sale_order function
---
models/__init__.py | 2 +-
.../{sale_intervention.py => sale_project.py} | 20 +++++++++----------
2 files changed, 11 insertions(+), 11 deletions(-)
rename models/{sale_intervention.py => sale_project.py} (91%)
diff --git a/models/__init__.py b/models/__init__.py
index cd97890..d3f915a 100644
--- a/models/__init__.py
+++ b/models/__init__.py
@@ -1,4 +1,4 @@
# Copyright 2021 Le Filament (https://le-filament.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
-from . import sale_intervention
+from . import sale_project
diff --git a/models/sale_intervention.py b/models/sale_project.py
similarity index 91%
rename from models/sale_intervention.py
rename to models/sale_project.py
index bdc2324..8493b1b 100644
--- a/models/sale_intervention.py
+++ b/models/sale_project.py
@@ -4,10 +4,10 @@
from odoo import models
-class SaleIntervention(models.Model):
- _inherit = "sale.intervention"
+class SaleProject(models.Model):
+ _inherit = "sale.project"
- def _update_order_lines(self):
+ def update_order_lines(self):
"""
Rewrite function to use Taxes
"""
@@ -21,8 +21,8 @@ class SaleIntervention(models.Model):
vat_furniture_categ = (
self.env["product.category"].browse(furniture_categ_id.id).taxes_id
)
- lines = self.read_group(
- (("project_id", "=", self.project_id.id),),
+ lines = self.env['sale.intervention'].read_group(
+ (("project_id", "=", self.id),),
("price", "intervention_length", "plant_qty"),
"intervention_type_id",
lazy=False,
@@ -51,7 +51,7 @@ class SaleIntervention(models.Model):
plant_price = plant_pricelist_item.fixed_price
existing_lines = self.sale_order_id.order_line.filtered(
lambda r: r.product_id.id == product_tmpl.product_variant_id.id
- and r.sale_project_id.id == self.project_id.id
+ and r.sale_project_id.id == self.id
)
if existing_lines:
sol_plant = existing_lines.filtered(
@@ -87,10 +87,10 @@ class SaleIntervention(models.Model):
"order_id": self.sale_order_id.id,
"product_id": product_tmpl.product_variant_id.id,
"product_uom_qty": quantity,
- "sale_project_id": self.project_id.id,
+ "sale_project_id": self.id,
}
sol_name = (
- "Projet " + self.project_id.name + " - " + product_tmpl.name
+ "Projet " + self.name + " - " + product_tmpl.name
)
sols.append(
{
@@ -124,6 +124,6 @@ class SaleIntervention(models.Model):
)
for sol in sols:
self.env["sale.order.line"].create(sol)
-
else:
- super(SaleIntervention, self)._update_order_lines()
+ super(SaleProject, self).update_order_lines()
+ self.sale_order_id.clean_sale_order()
--
GitLab