Search Here

Duplicate Records on Button Click in Odoo15

 In this article, you will learn how to duplicate records in Odoo15 using a button click instead of the "Duplicate" button located in the "Action" menu. To duplicate records at the click of a button we are going to use Odoo built-in methods (copy and copy_data).

Duplicate Records on Button Click in Odoo15

How to duplicate records using the copy and copy_data function

Odoo15 provides a built-in method copy to create new a record, by default this function uses the copy_data function to create new records with existing data. To create new or duplicate records you can also use Odoo by default "Duplicate" feature.

Read More: How to Use Copy Function in Odoo8

But in this article, I will show you how to achieve this functionality by clicking the button. Below are the steps to create a duplicate record.

duplicate_record.xml

<button class="oe_stat_button" icon="fa-files-o" name="btn_duplicate" type="object" string="Duplicate"/>


duplicate_record.py 


How to use copy() and copy_data() function in Odoo15

copy() function is used to copy or duplicate records, in the above code we have the .copy() function, this function takes some optional parameters in the form of a dictionary. If you want to add or modify some default data then you can pass the dictionary in the copy function like below.

duplicate_rec = self.copy({field_1:'Test', 'field_2':self.field_name})

To get the data of a model you can use the .copy_data() function, this function will return the list of dictionaries with all the existing data of a record set.

Post a Comment

0 Comments