Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
183 Widoki

je veux dire que pour cette  on peut choisir max 2 valeur de cette attribut. par examp on a une repas avec 5 variant de accompagnement pour ce repas on peut choisir que 2 max  


MAX_VALUES = 2  # Limite autorisée

TARGET_PRODUCT_ID = 95  # ID du produit cible à contrôler


for rec in records:

    if rec.id == TARGET_PRODUCT_ID:

        attributes = rec.product_template_attribute_value_ids.mapped('attribute_id')

        for attr in attributes:

            if attr.type == 'multi' and len(attr.value_ids) > MAX_VALUES:

                raise UserError(

                    "L'attribut '%s' (type multi) du produit '%s' ne peut pas avoir plus de %d valeurs."

                    % (attr.name or '', rec.name, MAX_VALUES)

                )

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
maj 21
6827
5
sie 16
5701
1
lip 15
7931
0
lut 25
1797
1
sty 25
11035