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

it's work on formview but not on kanban view

the state change in terminal when print it but not save it in database

code:

@api.onchange('stage_id')
def onchange_win_state(self):
for record in self:
if len(record.x_refs) > 0:
if record.stage_id.success_stage:
record.x_refs[0].write({"state": "not"})

อวตาร
ละทิ้ง

Record.x_refs[0].state = 'not'

ผู้เขียน

i try it and it nor working

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

For anyone who is still looking for answer, here is solution that will work.

Onchange method only works in from or list view. To achieve the same functionality, we can override write method. For example:

def write(self, vals):
​result = super(CRMLeadInherit, self).write(vals)
​if vals.get('stage_id'):
​stage_rec = self.env['crm.stage'].search([('id ', '=', vals.get('stage_id'))], limit=1)
​if stage_rec:
  ​// Put you code here ..
​return result

อวตาร
ละทิ้ง

yes this is correct, the only way is to "track" some changes from write() method and update it from there

ผู้เขียน คำตอบที่ดีที่สุด

@Tadeusz Jan Karpiński i try it and it nor working

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

onchange on Kanban view? onchange is triggered when you change a value. and this is done in a form or in a tree view if its editable. try using @api.depends('stage_id')

อวตาร
ละทิ้ง
ผู้เขียน

also not work on kanban!

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

This could be happening if you declare readonly the field state in your view, the solution is to use attribute force_save="1" in view to save value of readonly field.

it will save value of state field when onchange trigger.

อวตาร
ละทิ้ง
ผู้เขียน

hello sarra , try it on crm.lead model onchange on kanban it will not work

Hi Raouf, try to inherit the write method of 'crm.lead'
def write(self, vals):
# stage change:
write_result = super(Lead, self).write(vals)
if 'stage_id' in vals:
if len(write_result.x_refs) > 0:
if write_result.stage_id.success_stage:
write_result.x_refs[0].write({"state": "not"})
return write_result

ผู้เขียน

i have found the solution:

why it's not work on kanbanview like it work in formview? pls help
Avatar
jabri raouf
13 janvier 2022
raouf.jabri@samsa-it.de
crmkanbanonchangeformviewOdoo13.0
it's work on formview but not on kanban view

the state change in terminal when print it but not save it in database

code:

@api.onchange('stage_id')
def onchange_win_state(self):
for record in self:
if len(record.x_refs) > 0:
if record.stage_id.success_stage:
self._cr.execute(''' update public.x_ref set state = 'not' where id={id}'''.format(id=self._origin.id))

Related Posts ตอบกลับ มุมมอง กิจกรรม
5
ธ.ค. 22
5536
1
ธ.ค. 24
1624
CRM - kanban order แก้ไขแล้ว
1
มี.ค. 24
2526
2
ก.พ. 23
4163
2
มิ.ย. 21
6444