How to Use the copy() Method in Odoo 19

March 30, 2026 by
admin


                                                                                                                 



How to Use the copy() Method in Odoo 19
Introduction
Duplicating records is one of the most common tasks in any business application. Instead of creating similar records from scratch every time, odoo allows you to duplicate an existing one with a single click saving time and reducing errors.
By default, clicking duplicate on any form view creates an exact copy of that record. But what if you want more control over what gets copied? In many business scenarios, you need the duplicate to start fresh with a new name and a reset status rather than inheriting everything from the original. This is where the copy() method comes in handy.
This blog demonstrates how to override the copy() method in Odoo 19. We'll use a custom course model as our example, since it gives us full control to define the fields and duplication behavior from scratch.
This module demonstrates how to override the copy() method in Odoo 19. It includes:
  • A custom course model with a name field and a state field (Draft / Confirmed / Done)
  • An overridden copy() method that automatically renames the duplicate by appending "(copy)" to the name
  • The state field is reset back to Draft on every duplicate regardless of the original record's status
  • No wizard or server action needed just a clean python override inside the model class
In Odoo, the copy() method can be overridden directly inside the model class. The default parameter is a dictionary used to pass the field values that should be modified in the duplicated record.
1. Create the Model
    Create a new python file inside your module:
     models/course.py
This model defines two fields name and state. The state field uses a Selection field with three options: Draft, Confirmed, and Done. The default state is Draft. Two helper methods action_confirm() and action_draft() allow changing the state through buttons in the view. The copy() method override is also defined here.
2. Create the View
     The form view for the course record includes action buttons and a status bar.
      views/course_views.xml
The form view contains a header with two buttons confirm and reset to draft. These buttons are shown or hidden depending on the current state using the invisible attribute. The statusbar widget displays the state progression. The sheet section contains the name field. A menu item is also added so that courses appear in the top navigation bar.
3. Access Rights
     Add the access rights file to allow users to read, write, create, and delete course records.
      security/ir.model.access.csv      
  
4. Manifest File
    This file registers all data files required for the module to install correctly.
    __manifest__.py
  • Course records are shown in a form view. Each record displays the course name and the current status.

  • Clicking the gear icon opens a dropdown with the duplicate option. Clicking duplicate triggers the overridden copy() method.
  • The duplicate record opens automatically with the name renamed to "Python Programming (copy)"
  • The status is reset back to Draft — regardless of the original record's confirmed status
Conclusion
Overriding the copy() method in Odoo 19 is a simple and powerful way to control how records are duplicated. Instead of getting an exact copy every time, you can define exactly what changes such as resetting the name and the status  with just a few lines of python code inside your model class.
By using this approach, you ensure that every duplicated record starts in a clean, predictable state reducing errors and saving time for users. The copy() method requires no wizard, no server action, and no XML configuration, just a clean python override.
If you are looking for an ERP implementation partner with diverse industry experience feel free to contact us. We have proven track record of successful implementations across various sectors including Odoo for Manufacturing, Odoo for Trading, Odoo for FMCG, Odoo for Oil & Gas, Odoo for Diary, Odoo for Pharma, Odoo for Cosmetic Clinic, Odoo for Contracting Companies, Odoo for HVAC, Odoo for Logistics, Odoo for Automobile, Odoo for Laundry, Odoo for Field Service, Odoo for E-Commerce & many more
ZestyBeanz offers Developer / Consultant outsourcing programs, Chat with us in Whatsapp and Hire Odoo Developers, Mobile Application Developers, Consultants.
#OdooDevelopment #Odoo18 #CustomChatterButton #TechnicalBlog #OdooCustomization #OdooTips #Odoofeatures