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

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??

Awatar
Odrzuć
Najlepsza odpowiedź

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)

Awatar
Odrzuć

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

Autor Najlepsza odpowiedź

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)

Awatar
Odrzuć
Najlepsza odpowiedź

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)
Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
0
wrz 24
1342
0
kwi 24
1276
0
kwi 24
908
4
mar 24
1655
Singleton error Rozwiązane
2
wrz 22
2433