Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
3743 มุมมอง

Setting a field value in python (i.e., action button) does not trigger @api.onchange('field').

do I need to use a decorator or something?


Any help would be appreciated


อวตาร
ละทิ้ง

why you need to action button to trigger onchange function, you can trigger directly call function. Onchange working on textbox or others field when changing any value.

คำตอบที่ดีที่สุด

Hi,

You don't need api.onchange for date alone. You can do it in your button action as below,

@api.multi

def action_draft(self):

    for each in self:

        each.state = 'draft'

        each.draft_date = fields.Date.context_today(self)

    return True

อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

I have an action button that calls the following function in python:

def action_draft(self):

    self.state = 'draft'

and want to set draft_date once the state is set as draft. like this:

@api.onchange('state')

def _onchange_state(self):

    if self.state == 'draft':

        self.draft_date = fields.Date.today()

อวตาร
ละทิ้ง

Hi,

I have updated my answer, hope it helps

Thanks