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

Hello All,


i am getting issue when applying compute method(_compute_days) in integer field(days) for odoo 13.

error is:-

lead.age.audit(<NewId origin=39>,).days

my code is below:-


class crm_lead_age(models.Model):
    _inherit = 'crm.lead'

    age_audit = fields.One2many('lead.age.audit', 'lead_id', index=True, store=True)


class crm_lead_age_audit(models.Model):
    _name = 'lead.age.audit'

    lead_id = fields.Many2one('crm.lead')
    stage_id = fields.Many2one('crm.stage')
    date_in = fields.Date()
    date_out = fields.Date()
    days = fields.Integer(compute='_compute_days', store=True)

    @api.depends('date_in', 'date_out')
    def _compute_days(self):
        for res in self:
            if res.date_in and res.date_out:
                res.days = (res.date_out - res.date_in).days


Thanks in advance.

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

Hello Pawan,


You need to assign empty Value before the Loop

All the computed fields need to be assigned an empty value at least

@api.depends('date_in', 'date_out')
    def _compute_days(self):
        self.days = 0
        for res in self:
            if res.date_in and res.date_out:
                res.days = (res.date_out - res.date_in).days
Ảnh đại diện
Huỷ bỏ
Tác giả

Thanks swapnesh.... it's work.

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

AttributeError: 'agri.projects' object has no attribute '_compute_wdays'

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 1 25
3833
1
thg 5 22
2767
1
thg 6 25
15347
3
thg 4 25
5488
Compute Fields Đã xử lý
2
thg 7 24
2454