Skip to content
Extraits de code Groupes Projets
Valider f7c8b329 rédigé par jordan's avatar jordan
Parcourir les fichiers

[update] refactor function update_order_lines to be defined in sale_intervention class

parent 45446841
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -686,7 +686,7 @@ class SaleIntervention(models.Model):
% rec.project_subvention_id.name
)
total_price += rec.price
rec.sale_order_id.update_order_lines()
rec._update_order_lines()
return total_price
def _get_plants_qties(self):
......@@ -868,6 +868,34 @@ class SaleIntervention(models.Model):
# ------------------------------------------------------
# Business methods
# ------------------------------------------------------
def _update_order_lines(self):
product_tmpl = self.intervention_type_id
quantity = (
self.intervention_length
if product_tmpl.uom_name == "m"
else self.plant_qty
)
if quantity != 0:
data = {
"price_unit": self.price / quantity,
"product_uom_qty": quantity,
}
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
)
if existing_lines:
# Update these lines
existing_lines.write(data)
else:
# Add missing fields and create new lines
data.update({
'order_id': self.sale_order_id.id,
'name': self.project_id.name + " - " + product_tmpl.name,
'product_id': product_tmpl.product_variant_id.id,
'sale_project_id': self.project_id.id
})
self.env["sale.order.line"].create(data)
class SaleInterventionStock(models.Model):
......
......@@ -20,45 +20,3 @@ class SaleOrder(models.Model):
inverse_name="sale_order_id",
string="Articles d'interventions'",
)
# TODO: add compute of products for creating stock picking delivery at confirm time
def update_order_lines(self):
for rec in self.sale_project_ids:
lines = self.env["sale.intervention"].read_group(
(("project_id", "=", rec.id),),
("price", "intervention_length", "plant_qty"),
"intervention_type_id",
lazy=False,
)
for line in lines:
product_tmpl_id = line["intervention_type_id"][0]
product_tmpl = self.env["product.template"].browse(product_tmpl_id)
quantity = (
line["intervention_length"]
if product_tmpl.uom_name == "m"
else line["plant_qty"]
)
data = {}
if quantity != 0:
data = {
"price_unit": line["price"] / quantity,
"product_uom_qty": quantity,
}
# TODO manage case where we need 2 sale order line per product
# (when taxes = 10% for plants, 20% for other)
# search for sale order lines for this product_id and sale_project_id
existing_lines = self.order_line.filtered(
lambda r: r.product_id.id == product_tmpl.product_variant_id.id
and r.sale_project_id.id == rec.id
)
if existing_lines:
# Update these lines
existing_lines.write(data)
else:
# Add missing fields and create new lines
data["order_id"] = rec.sale_order_id.id
data["name"] = rec.name + " - " + product_tmpl.name
data["product_id"] = product_tmpl.product_variant_id.id
data["sale_project_id"] = rec.id
self.env["sale.order.line"].create(data)
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter