From e38d3b40af5842f999393b5c60f910cf1e065b35 Mon Sep 17 00:00:00 2001 From: Julien Ortet <julien@le-filament.com> Date: Thu, 30 May 2024 17:09:37 +0200 Subject: [PATCH] [ADD] configure product accessory --- models/__init__.py | 1 + models/product_category.py | 1 + models/product_template.py | 51 ++++++++++++++++++++++++++++++++ models/sale_intervention.py | 26 +++++++++++++--- views/product_template_views.xml | 12 ++++++++ 5 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 models/product_template.py diff --git a/models/__init__.py b/models/__init__.py index 7d875aa..5b7d17b 100644 --- a/models/__init__.py +++ b/models/__init__.py @@ -11,3 +11,4 @@ from . import sale_intervention from . import sale_intervention_stock from . import res_partner from . import product_category +from . import product_template diff --git a/models/product_category.py b/models/product_category.py index ef64a70..c2330f9 100644 --- a/models/product_category.py +++ b/models/product_category.py @@ -11,6 +11,7 @@ class ProductCategory(models.Model): # Fields declaration # ------------------------------------------------------ symbol = fields.Char("Symbole") + accessory_label = fields.Char("Nom de l'accessoire associƩ") # ------------------------------------------------------ # SQL Constraints diff --git a/models/product_template.py b/models/product_template.py new file mode 100644 index 0000000..20c154c --- /dev/null +++ b/models/product_template.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +import itertools +import logging +from collections import defaultdict + +from odoo import api, fields, models, tools, _, SUPERUSER_ID +from odoo.exceptions import ValidationError, RedirectWarning, UserError +from odoo.osv import expression + +_logger = logging.getLogger(__name__) + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + # ------------------------------------------------------ + # Fields declaration + # ------------------------------------------------------ + nb_accesories = fields.Float(string="Nombre d'accessoires") + + # ------------------------------------------------------ + # SQL Constraints + # ------------------------------------------------------ + + # ------------------------------------------------------ + # Default methods + # ------------------------------------------------------ + + # ------------------------------------------------------ + # Computed fields / Search Fields + # ------------------------------------------------------ + + # ------------------------------------------------------ + # Onchange / Constraints + # ------------------------------------------------------ + + # ------------------------------------------------------ + # CRUD methods (ORM overrides) + # ------------------------------------------------------ + + # ------------------------------------------------------ + # Actions + # ------------------------------------------------------ + def get_accessory_label(self): + return self.env["product.category"].browse(self.gateg_id).accessory_label + # ------------------------------------------------------ + # Business methods + # ------------------------------------------------------ + diff --git a/models/sale_intervention.py b/models/sale_intervention.py index 9894b37..aec1d02 100644 --- a/models/sale_intervention.py +++ b/models/sale_intervention.py @@ -537,7 +537,12 @@ class SaleIntervention(models.Model): @api.onchange("high_protection_qty") def _onchange_high_protection_qty(self): - self.stake_qty = self.high_protection_qty + if self.high_protection_id.nb_accesories: + stake_multiplier = self.high_protection_id.nb_accesories + else: + stake_multiplier = 1 + + self.stake_qty = stake_multiplier * self.high_protection_qty @api.onchange("low_protection_qty") def _onchange_low_protection_qty(self): @@ -705,7 +710,11 @@ class SaleIntervention(models.Model): # Staples if rec.mulch_has_staples or rec.mulch2_has_staples: products.append(staples_product_id) - quantities.append(rec.mulch_qty * 2 or 0) + if rec.mulch_id.nb_accesories: + staples_multipier = rec.mulch_id.nb_accesories + else: + staples_multipier = 2 + quantities.append(rec.mulch_qty * staples_multipier or 0) partners.append(partner) # High Protections @@ -860,15 +869,20 @@ class SaleIntervention(models.Model): } ) if self.mulch_has_staples: + if self.mulch_id.nb_accesories: + staples_multipier = self.mulch_id.nb_accesories + else: + staples_multipier = 2 data.append( { "sale_intervention_id": self.id, "product_id": staples_product_id.product_variant_id.id, - "product_uom_qty": self.mulch_qty * 2, + "product_uom_qty": self.mulch_qty * staples_multipier, "price_unit": self.staple1_price, } ) if self.mulch2_id and self.mulch2_qty > 0: + data.append( { "sale_intervention_id": self.id, @@ -878,11 +892,15 @@ class SaleIntervention(models.Model): } ) if self.mulch2_has_staples: + if self.mulch2_id.nb_accesories: + staples_2_multipier = self.mulch2_id.nb_accesories + else: + staples_2_multipier = 2 data.append( { "sale_intervention_id": self.id, "product_id": staples_product_id.product_variant_id.id, - "product_uom_qty": self.mulch2_qty * 2, + "product_uom_qty": self.mulch2_qty * staples_2_multipier, "price_unit": self.staple2_price, } ) diff --git a/views/product_template_views.xml b/views/product_template_views.xml index 75c9c23..61d95ce 100644 --- a/views/product_template_views.xml +++ b/views/product_template_views.xml @@ -9,9 +9,21 @@ <field name="arch" type="xml"> <field name="parent_id" position="after"> <field name="symbol" /> + <field name="accessory_label" /> </field> </field> </record> + <record id="product_template_only_form_view_ap" model="ir.ui.view"> + <field name="name">product.template.product.form.inherit</field> + <field name="model">product.template</field> + <field name="inherit_id" ref="product.product_template_form_view"/> + <field name="arch" type="xml"> + <field name="categ_id" position="after"> + <field name="nb_accesories"> Nombre d accessoire </field> + </field> + </field> + </record> + </data> </odoo> -- GitLab