Community mailing list archives

community@mail.odoo.com

Re: Expected singleton error

by
Burhan Vakharia
- 06/24/2016 07:48:53
As you are getting multiple records, you need to loop through the records.

Try the below code,
@api.multi
@api.depends('qte','prixu')
def _get_total(self):
    for class_b_rec in self:
        class_b_rec.total = class_b_rec.qte * class_b_rec.prixu

Hope this helps,
Thank You

On Fri, Jun 24, 2016 at 5:11 PM, Khaled Hamed <khaled.hamed@grandtk.com> wrote:

You can use the following

for p in self:
    p.total......
    ........

And so on

On Jun 24, 2016 1:37 PM, "Omal Bastin" <omalbastin@gmail.com> wrote:
when using @api.multi, self will have multiple records. so you need to use for loop to get each record. So instead @api.multi use @api.one.
@api.one is depricated i think. but in your case it will be fine

On Fri, Jun 24, 2016 at 4:32 PM, Karim AJRAAM <karim.ajraam@gmail.com> wrote:
Hello community,

this is my code : 

class class_a(models.Model):
_name = 'class.a'
    @api.multi
@api.depends('class_a.total_b')
def _get_total(self):
       self.total_a = 0
       for i in self.class_a:
self.total_a += i.total_b

    total_a = fields.Float(compute='_get_total', string="Total", store=True)
    class_a = fields.One2many('class.b', 'class_a')

class class_b(models.Model):
_name = 'class.b'

@api.v8
@api.depends('qte','prixu')
def _get_total(self):
self.total = self.qte * self.prixu

qte = fields.Float('Quantite', required=True)
prixu = fields.Float('Prix U')
total_b = fields.Float(compute='_get_total', string="Total", store=True, readonly=True)
class_a = fields.Many2one('class.a')
i have this error : ValueError Expected singleton: class_b(56, 57, 55)
Please help.


_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-59
Post to: mailto:community@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe




--
Omal Bastin

_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-59
Post to: mailto:community@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe

_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-59
Post to: mailto:community@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe




--
 
--
 
Burhan Vakharia
https://about.me/burhanvakharia