This question has been flagged
3 Replies
2981 Views

I made a new module from sales.order (odoo11).  I have a field "cantidad" that should show the number of lines in the order but is not working .. not errors but not work

I try sereral example but the computed field desn't work

 here is the code 


from odoo import api, fields, models

class aleOrder(models.Model):

    _name = "ale.order"

    _description = "Forma"

    name = fields.Char(string='OT')

    partner_id = fields.Many2one('res.partner', string='Cliente',  required=True,  track_visibility='always')

       order_line = fields.One2many('ale.order.line', 'order_id', string='Trabajos', copy=True, auto_join=True)

    cantidad = fields.Float(string='Extintores', store='True', readonly='True', compute='_cant_ext')


@api.depends('order_line')

def _cant_ext(self):

        for line in self:

            cantidad += line.sequence

        order.update({

        'cantidad': cantidad,

        })


class aleOrderLine(models.Model):

    _name = 'ale.order.line'

    _description = 'Lines'

    order_id = fields.Many2one('ale.order', string='Order Reference', required=True, ondelete='cascade', index=True, copy=False)

    name = fields.Text(string='Description')

    sequence = fields.Float(string='Sequence', default=10)



any help ?

Avatar
Discard
Best Answer

Hi,

Please update your compute function like this and restart the service and see,

@api.depends('order_line', 'order_line.sequence')
def _cant_ext(self):
cantidad = 0
for line in self:
cantidad += line.sequence
self.update({
'cantidad': cantidad
})

Compute Field in Odoo: How to Write Compute Field and its Function in Odoo12


Thanks

Avatar
Discard
Author

Thanks Niyas but still not working, the number is not changing

Best Answer

@api.depends('order_line')

def _cant_ext(self):

        for order in self:

            order.cantidad = len(order.order_line)

Avatar
Discard
Author

thanks but that gives me an error

which error?

Author
sorry Ravi

my mistake , the error was my fault. It loads , but the computed field doesn't change. I tested it on 2 different servers.

Mauricio Gah C.
Los Muermos - Chile
+56 9 91820076


On Thu, Sep 24, 2020 at 3:15 PM Ravi Gadhia <raviit2004@gmail.com> wrote:

which error?

Sent by Odoo S.A. using Odoo.