Skip to Content
Menu
This question has been flagged
4 Replies
3098 Views

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
Discard
Best Answer

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
Discard

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

Author Best Answer

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
Discard
Best Answer

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
Discard
Related Posts Replies Views Activity
0
Sep 24
383
0
Apr 24
361
0
Apr 24
93
4
Mar 24
298
2
Sep 22
1437