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

Hi guys,

In my medical module, I created 2 models, "appointment" and "evaluation".
on the appointment form, I created a "confirm" button which changes the appointment state from the draft state to the confirmed one, with the following function:


def confirm(self):
self.write({'state': 'confirmed'})

It works like perfect, but I need when I click in the same button, to create a new record in the "evalutation" table, and copy the data of this appointment.

How to do it please? any advice?

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

you can try the following:
self.env['evaluation.model'].create({'name': self.name_of_new_record})

Keep in mind in the create dictionary, you have to set all required fields for the evaluation model.

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

Hi, Nomad_King answered your question pertfecly. I just want to add some information. self.env['model_name'].create(list_of_dictionaries) creates new records of the model 'model_name'. 'list_of_dictionaries' is, well, a list of dictionaries. Each dictionary is a new record. It basically looks like this {'field_name1': value, 'field_name2': value, ...} You get it. Be carefull with related fields: One2many and Many2many fields use special 'commands'. Check the documentation for more info.

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

Thanks so much for your quick reply,

I will try it and let you know


อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
ม.ค. 22
465
rest api not working in postman แก้ไขแล้ว
2
ส.ค. 24
5087
Upgrade from V14 to V15 แก้ไขแล้ว
1
ต.ค. 21
9374
1
พ.ค. 24
3149
1
ธ.ค. 23
2525