Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
3 Відповіді
3372 Переглядів

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
2
серп. 24
4671
Upgrade from V14 to V15 Вирішено
1
жовт. 21
9126
1
трав. 24
2698
1
груд. 23
2113