Skip to content
Extraits de code Groupes Projets
Valider 3cf2e921 rédigé par Rémi - Le Filament's avatar Rémi - Le Filament
Parcourir les fichiers

[ADD] generate sale_order_line

parent 070b50d4
Branches
Étiquettes
Aucune requête de fusion associée trouvée
......@@ -27,7 +27,7 @@ class SaleIntervention(models.Model):
# ------------------------------------------------------
# TODO: implement sequence on name (project.name-number), order by name
# make this field as required auto-calculated and remove sequence field
name = fields.Char("Nom")
name = fields.Char("Nom", group_operator="count")
sequence = fields.Integer("Sequence", default=10)
project_id = fields.Many2one(
comodel_name="sale.project", string="Projet", ondelete="cascade", required=True
......@@ -47,6 +47,7 @@ class SaleIntervention(models.Model):
],
ondelete="restrict",
required=True,
group_operator="count_distinct",
)
intervention_uom_name = fields.Char(
related="intervention_type_id.uom_name", string="Unité de mesure intervention"
......@@ -54,7 +55,7 @@ class SaleIntervention(models.Model):
latitude = fields.Float(string="Geo Latitude", digits=(16, 5))
longitude = fields.Float(string="Geo Longitude", digits=(16, 5))
# TODO: create default values in a csv file in NextCloud
# TODO: create default values in a csv file in NextCloud ?
financial_help_ids = fields.Many2many(
comodel_name="sale.financial.help",
relation="sale_financial_help_rel",
......@@ -64,13 +65,17 @@ class SaleIntervention(models.Model):
)
# If calculated by meters
intervention_length = fields.Float("Longueur de Haie (en m)")
plant_interval = fields.Float("Intervalle entre les plants (en m)")
intervention_length = fields.Float("Longueur de Haie (en m)", group_operator="sum")
plant_interval = fields.Float(
"Intervalle entre les plants (en m)", group_operator="sum"
)
# If calculated by units
plant_qty = fields.Integer("Nombre de Plants")
plant_qty = fields.Integer("Nombre de Plants", group_operator="sum")
surface = fields.Integer(
"Surface (en m2)", help="Information ne rentrant pas dans les calculs"
"Surface (en m2)",
help="Information ne rentrant pas dans les calculs",
group_operator="sum",
)
city = fields.Char(
string="Commune intervention",
......@@ -213,13 +218,19 @@ class SaleIntervention(models.Model):
"Nombre de plants supplémentaires", compute="_compute_quantities", default=0
)
plants_qty = fields.Integer(
"Nombre total de plants", compute="_compute_quantities", default=0
"Nombre total de plants",
compute="_compute_quantities",
default=0,
group_operator="sum",
)
plants_type_qty = fields.Integer(
"Nombre d'espèces différentes", compute="_compute_quantities", default=0
)
plants_local_qty = fields.Integer(
"Nombre de végétal total", compute="_compute_quantities", default=0
"Nombre de végétal local",
compute="_compute_quantities",
default=0,
group_operator="sum",
)
plant_price = fields.Float(
......@@ -307,6 +318,7 @@ class SaleIntervention(models.Model):
readonly=True,
default=0.0,
digits="Product Price",
group_operator="sum",
)
sale_order_id = fields.Many2one(
......@@ -318,11 +330,11 @@ class SaleIntervention(models.Model):
inverse_name="sale_intervention_id",
string="Lignes de devis / commande",
)
sale_intervention_line_ids = fields.One2many(
comodel_name="sale.intervention.line",
inverse_name="sale_intervention_id",
string="Lignes d'interventions'",
)
# sale_intervention_line_ids = fields.One2many(
# comodel_name="sale.intervention.line",
# inverse_name="sale_intervention_id",
# string="Lignes d'interventions'",
# )
# ------------------------------------------------------
# SQL Constraints
......@@ -604,15 +616,33 @@ class SaleIntervention(models.Model):
products = []
qty = []
if rec.sequence_type == "sequence":
iteration = 0
for sequence in rec.plant_sequence_ids:
products.append(sequence.product_id)
# TODO: add calculation for plants out of sequence
# add calculation for plants out of sequence, based on iteration
extra_plant = 0
extra_alter_plant = 0
if rec.extra_plants_qty and iteration < rec.extra_plants_qty:
# if the full number of sequence is odd
# (or no alternance plant is defined),
# we add the main plant
if (
rec.full_seq_qty % 2 == 0
or not sequence.product_alternance_id
):
extra_plant = 1
# otherwise, we add the alternance plant
else:
extra_alter_plant = 1
if sequence.product_alternance_id:
qty.append(math.ceil(rec.full_seq_qty / 2))
qty.append(math.ceil(rec.full_seq_qty / 2) + extra_plant)
products.append(sequence.product_alternance_id)
qty.append(math.floor(rec.full_seq_qty / 2))
qty.append(math.floor(rec.full_seq_qty / 2) + extra_alter_plant)
else:
qty.append(rec.full_seq_qty)
qty.append(rec.full_seq_qty + extra_plant)
iteration += 1
elif rec.sequence_type == "list":
products = rec.plant_list_ids.mapped("product_id")
qty = rec.plant_list_ids.mapped("qty")
......@@ -622,7 +652,7 @@ class SaleIntervention(models.Model):
# ------------------------------------------------------
# CRUD methods (ORM overrides)
# ------------------------------------------------------
# TODO: create intervention lines for project
# TODO: create intervention lines for project - to be removed
# @api.model_create_multi
# def create(self, vals_list):
# import pdb; pdb.set_trace()
......@@ -708,37 +738,38 @@ class SaleIntervention(models.Model):
# ------------------------------------------------------
class SaleInterventionLine(models.Model):
_name = "sale.intervention.line"
_description = "Ligne d'interventions'"
sale_intervention_id = fields.Many2one(
comodel_name="sale.intervention",
string="Intervention",
ondelete="cascade",
required=True,
)
product_id = fields.Many2one(
"product.product",
string="Product",
required=True,
change_default=True,
ondelete="restrict",
)
product_template_id = fields.Many2one(related="product_id.product_tmpl_id")
name = fields.Char(string="Name", related="product_id.name")
product_uom_qty = fields.Float(
string="Quantity", digits="Product Unit of Measure", required=True, default=1.0
)
price_unit = fields.Float(
"Unit Price", required=True, digits="Product Price", default=0.0
)
price_total = fields.Float(
compute="_compute_amount", string="Total", readonly=True, store=True
)
@api.depends("product_uom_qty", "price_unit")
def _compute_amount(self):
for rec in self:
rec.price_total = rec.product_uom_qty * rec.price_unit
#
# class SaleInterventionLine(models.Model):
#
# _name = "sale.intervention.line"
# _description = "Ligne d'interventions'"
#
# sale_intervention_id = fields.Many2one(
# comodel_name="sale.intervention",
# string="Intervention",
# ondelete="cascade",
# required=True,
# )
# product_id = fields.Many2one(
# "product.product",
# string="Product",
# required=True,
# change_default=True,
# ondelete="restrict",
# )
# product_template_id = fields.Many2one(related="product_id.product_tmpl_id")
# name = fields.Char(string="Name", related="product_id.name")
# product_uom_qty = fields.Float(
# string="Quantity", digits="Product Unit of Measure", required=True, default=1.0
# )
# price_unit = fields.Float(
# "Unit Price", required=True, digits="Product Price", default=0.0
# )
# price_total = fields.Float(
# compute="_compute_amount", string="Total", readonly=True, store=True
# )
#
# @api.depends("product_uom_qty", "price_unit")
# def _compute_amount(self):
# for rec in self:
# rec.price_total = rec.product_uom_qty * rec.price_unit
......@@ -15,3 +15,32 @@ class SaleOrder(models.Model):
inverse_name="sale_order_id",
string="Projets",
)
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 = {
"order_id": rec.sale_order_id.id,
"name": product_tmpl.name,
"product_id": product_tmpl.product_variant_id.id,
"price_unit": line["price"] / quantity,
"product_uom_qty": quantity,
"sale_project_id": rec.id,
}
# TODO search for existing line, if none exist, create
self.env["sale.order.line"].create(data)
......@@ -163,6 +163,7 @@ class SaleProject(models.Model):
"domain": [("project_id", "=", self.id)],
"context": {
"default_project_id": self.id,
"search_default_group_by_intervention_type": True,
},
}
......
......@@ -7,5 +7,4 @@ sale_project_admin_state_salesteam,sale_project_admin_state_salesteam,model_sale
sale_financial_help_salesteam,sale_financial_help_salesteam,model_sale_financial_help,sales_team.group_sale_salesman,1,1,1,1
sale_intervention_salesteam,sale_intervention_salesteam,model_sale_intervention,sales_team.group_sale_salesman,1,1,1,1
sale_intervention_plant_sequence_salesteam,sale_intervention_plant_sequence_salesteam,model_sale_intervention_plant_sequence,sales_team.group_sale_salesman,1,1,1,1
sale_intervention_line_salesteam,sale_intervention_line_salesteam,model_sale_intervention_line,sales_team.group_sale_salesman,1,1,1,1
sale_project_subvention_salesteam,sale_project_subvention_salesteam,model_sale_project_subvention,sales_team.group_sale_salesman,1,1,1,1
......@@ -217,7 +217,7 @@
<field name="plants_type_qty" />
<field name="plants_local_qty" />
</group>
<group name="details" string="Détails" readonly="True">
<!--group name="details" string="Détails" readonly="True">
<field
string="Détails"
......@@ -240,7 +240,7 @@
<field name="price_total" sum="Prix Total" />
</tree>
</field>
</group>
</group-->
</sheet>
<div class="oe_chatter">
<field name="message_follower_ids" />
......@@ -254,13 +254,15 @@
<field name="name">Tree view for sale intervention</field>
<field name="model">sale.intervention</field>
<field name="arch" type="xml">
<tree string="Interventions">
<field name="name" />
<field name="sale_order_id" invisible="True" />
<field name="project_id" invisible="True" />
<field name="intervention_length" />
<field name="plant_qty" />
<field name="surface" />
<tree string="Interventions" expand="True">
<field name="name" optional="show" />
<field name="sale_order_id" optional="hide" />
<field name="project_id" optional="hide" />
<field name="intervention_type_id" optional="show" />
<field name="intervention_length" sum="Total" optional="show" />
<field name="plant_qty" sum="Total" optional="show" />
<field name="surface" sum="Total" optional="show" />
<field name="price" sum="Total" optional="show" />
</tree>
</field>
</record>
......@@ -271,6 +273,12 @@
<search string="Recherche d'Interventions">
<field name="sale_order_id" />
<group expand="0" string="Group By">
<filter
name="group_by_intervention_type"
string="Type d'intervention"
domain="[]"
context="{'group_by':'intervention_type_id'}"
/>
<filter
name="group_by_project"
string="Projet"
......
......@@ -23,11 +23,15 @@
string="Projets"
>
<tree editable="bottom">
<field name="name" />
<field name="project_subvention_id" />
<field name="user_id" />
<field name="admin_state_id" />
<field name="intervention_ids" readonly="1" />
<field name="name" optional="show" />
<field name="project_subvention_id" optional="show" />
<field name="user_id" optional="show" />
<field name="admin_state_id" optional="show" />
<field
name="intervention_ids"
readonly="1"
optional="hide"
/>
<!-- TODO: display buttons in a more visible way -->
<button
type="object"
......@@ -43,6 +47,12 @@
/>
</tree>
</field>
<button
type="object"
name="update_order_lines"
string="Mettre à jour lignes de devis"
class="oe_read_only"
/>
</field>
</field>
</record>
......
......@@ -41,15 +41,33 @@
/>
</group>
<group name="interventions" class="oe_read_only">
<!-- TODO: display buttons in a more visible way -->
<button
type="object"
name="action_interventions"
string="Interventions"
class="oe_read_only"
/>
<field name="intervention_ids" mode="tree">
<!-- TODO : group by intervention_type_id and calculate sum of length, qty and surface -->
<tree>
<field name="name" />
<field name="intervention_type_id" />
<field name="intervention_length" />
<field name="plant_qty" />
<field name="surface" />
<field name="price" />
<!-- TODO : group by intervention_type_id -->
<tree default_order="intervention_type_id,name">
<field name="name" optional="show" />
<field
name="intervention_type_id"
optional="show"
/>
<field
name="intervention_length"
sum="Total"
optional="show"
/>
<field
name="plant_qty"
sum="Total"
optional="show"
/>
<field name="surface" sum="Total" optional="show" />
<field name="price" sum="Total" optional="show" />
</tree>
</field>
</group>
......@@ -67,12 +85,12 @@
<field name="model">sale.project</field>
<field name="arch" type="xml">
<tree string="Projet de Création" create="false">
<field name="name" />
<field name="sale_order_id" />
<field name="project_subvention_id" />
<field name="user_id" />
<field name="admin_state_id" />
<field name="intervention_ids" />
<field name="name" optional="show" />
<field name="sale_order_id" optional="show" />
<field name="project_subvention_id" optional="show" />
<field name="user_id" optional="show" />
<field name="admin_state_id" optional="show" />
<field name="intervention_ids" optional="hide" />
<button
type="object"
name="action_interventions"
......
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