콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
3 답글
4655 화면

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 ?

아바타
취소
베스트 답변

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

아바타
취소
작성자

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

베스트 답변

@api.depends('order_line')

def _cant_ext(self):

        for order in self:

            order.cantidad = len(order.order_line)

아바타
취소
작성자

thanks but that gives me an error

which error?

작성자
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.

관련 게시물 답글 화면 활동
2
7월 24
2968
1
6월 24
5418
1
10월 23
11195
1
10월 23
98
1
8월 23
2194