İçereği Atla
Menü
Bu soru işaretlendi
4 Cevaplar
3837 Görünümler

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
Vazgeç
En İyi Yanıt

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
Vazgeç

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

Üretici En İyi Yanıt

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
Vazgeç
En İyi Yanıt

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
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
0
Eyl 24
1314
0
Nis 24
1251
0
Nis 24
877
4
Mar 24
1624
Singleton error Çözüldü
2
Eyl 22
2420