Odooers论坛

欢迎!

该社区面向专业人士和我们产品和服务的爱好者。
分享和讨论最好的内容和新的营销理念,建立您的专业形象,一起成为更好的营销人员。


0

Function to create multiple records when a button is clicked.

形象
odoo
形象
丢弃
2 答案
0
形象
odoo
最佳答案

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

形象
丢弃
0
形象
odoo
最佳答案

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

1 备注
形象
丢弃
形象
odoo
-

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)