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

I have a field type char "name" and a function onchange for this field. I want save the register complete when i modified the field "name" Something like:

@api.onchange('name')
    def _onchange_name(self):
        #Save the register on the BBDD (like press the save button)
อวตาร
ละทิ้ง

you want to have the history of name changes,, am I correct?

ผู้เขียน

I have more fields, i want automatically save all fields at the change the name

could you please explain in detail about what you want?

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

Finally override create method

@api.model
def create(self,values):
    <my code>
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

You need to have another field of type one2many for that and also set the new value in the return of the onchange. Something like this:

def _onchange_name(self, cr, uid, ids, name, history_ids, context=None):
history_ids.append(0,0,{'name': name})
return {'value': {'history_ids': history_ids}}

There are a few things to notice here, in the onchange with the new api does not allow you to return values for one2many or many2many fields so your need to hack into that to get it working. Like redefining the onchange method of your model like in this example:

https://www.odoo.com/forum/ayuda-1/question/access-one2many-list-in-many2one-onchange-event-93056#answer_93121

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
พ.ย. 22
3415
0
มิ.ย. 21
5965
0
มี.ค. 21
2783
2
ม.ค. 20
21755
4
ม.ค. 20
6361