Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
4 Antwoorden
3844 Weergaven

hi i get this error 

there is my code :


@api.depends('projet.projetbc_ligne_ids')

    def _total(self):

        for variant in self.projet.projetbc_ids:

            variant.quantite_encoure = sum(line.quantite for line in self.projet.projetbc_ligne_ids)


it works if i have one record in my table but it show the error if i have more .. any idea??

Avatar
Annuleer
Beste antwoord

It may be raised because you tried to write to more than one record at the same time.

If it works for record with single record, Try this code:

@api.depends('projet.projetbc_ligne_ids')

def _total(self):

        for variant in self.projet.projetbc_ids:

            for variant_one in variant:

                variant_one.quantite_encoure = sum(line.quantite for line in self.projet.projetbc_ligne_ids)

Avatar
Annuleer

If you cant solve it plz add more details like the type of variables used your method

Auteur Beste antwoord

hi thank you for your replys in fact i solve it yestrday after posting the quation and yes @IT LIbertqs you re right . i just add the first loop for and it works there 's my code :


@api.depends('projet.projetbc_ligne_ids')

    def _total(self):

        for record in self :

            for variant in record.projet.projetbc_ids:

                variant.quantite_encoure = sum(line.quantite for line in record.projet.projetbc_ligne_ids)

Avatar
Annuleer
Beste antwoord

Not sure what projetbc_ids & projetbc_ligne_ids meant.  However, there is a strong error in your code. You are using the decorator api@multi (the default decorator if you haven't specified any). Thus, you should iterate over self.

@api.depends('projet.projetbc_ligne_ids')
def _total(self):
    for object in self:
        for variant in object.projet.projetbc_ids:
            variant.quantite_encoure = sum(line.quantite for line in object.projet.projetbc_ligne_ids)
Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
0
sep. 24
1328
0
apr. 24
1263
0
apr. 24
892
4
mrt. 24
1640
2
sep. 22
2426