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

Hi,


I have added a button that when clicked, it should create multiple employees from my custom module.


Kindly help me with this, thanks

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

Hi,

This can be easily done by passing list of values to the create method.

Suppose if i need to create a record with name only in model_xyz, first prepare a list of dictionary as follows:

vals_list = [{'name': 'test 1'}, {'name': 'test 2'}]

then pass this created list to create orm method.

self.env['model.xyz'].create(vals_list)

Thanks

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

Hello Sasha Brown,

Please find below code it may help you to resolve this issue

Please find code in comment.
I Hope this will help you. 

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

อวตาร
ละทิ้ง

suppose you have one button(create_empoyee) in your custom module.This code added in your custom module.

def create_employee(self):
for rec in self.search([]):
Suppose you create employee record with name so Fist you create list of dictionary.

vals = ({field_name: rec.your_custom_model_field})

After this vals is passed to create function.
self.env['model.employee'].create(vals)

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
มิ.ย. 25
1174
3
ก.ค. 25
2908
1
พ.ค. 25
1092
1
พ.ค. 25
1368
4
พ.ค. 25
2489