Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
4 Replies
3832 Tampilan

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
Buang
Jawaban Terbai

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
Buang

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

Penulis Jawaban Terbai

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
Buang
Jawaban Terbai

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
Buang
Post Terkait Replies Tampilan Aktivitas
0
Sep 24
1307
0
Apr 24
1242
0
Apr 24
862
4
Mar 24
1614
Singleton error Diselesaikan
2
Sep 22
2418