Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
4432 Lượt xem

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 ?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Tác giả

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

Câu trả lời hay nhất

@api.depends('order_line')

def _cant_ext(self):

        for order in self:

            order.cantidad = len(order.order_line)

Ảnh đại diện
Huỷ bỏ
Tác giả

thanks but that gives me an error

which error?

Tác giả
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.

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 7 24
2677
1
thg 6 24
5140
1
thg 10 23
10848
1
thg 10 23
98
1
thg 8 23
2193