Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
3 Replies
4339 Tampilan

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

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
Buang
Penulis

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

Jawaban Terbai

@api.depends('order_line')

def _cant_ext(self):

        for order in self:

            order.cantidad = len(order.order_line)

Avatar
Buang
Penulis

thanks but that gives me an error

which error?

Penulis
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.

Post Terkait Replies Tampilan Aktivitas
2
Jul 24
2501
1
Jun 24
4995
1
Okt 23
10679
1
Okt 23
98
1
Agu 23
2193