Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

How can I modify the default "copy" duplicate function??

By
Tajjajt
on 4/17/13, 1:20 PM 5,388 views

plz can anyone told me how to modify the default "copy" duplicate function by inheretance???

2

Ray Carnes

--Ray Carnes--
15677
| 9 7 9
Greater Los Angeles, United States
--Ray Carnes--

Senior Odoo Analyst

OpenERP 6.1, 7.0 and Odoo 8.0, 9.0 (Since 2012)

Completed Functional and Technical Training.

Major Skills:

  • Needs Discovery and Requirements Analysis;

  • Function and Technical Specifications;

  • Project Planning;

  • Prototyping and Proof of concepts;

  • Data migration;

  • Configuration & Customization (UI and modules);

  • Integration - data, business logic and service levels;

  • Training and Knowledge transfer;

  • Go Live support;

  • Help desk;

  • Version Migration.

I have over 20 years of experience empowering and enabling users with enterprise information systems that make a real and measurable difference in their ability to proactively manage their businesses and organizations. 

Ray Carnes
On 4/18/13, 12:34 AM

Write a new function that overrides the original one and calls the original with your changes:

def copy(self, cr, uid, id, default={}, context=None):
    if not default:
        default = {}
    default.update({
        '[field you want to change the default value of]': '[value you want]',
    })
    return super([class you are changing], self).copy(cr, uid, id, default, context=context)`
3
Levent Karakaş
On 8/1/15, 10:21 AM

with new api:

@api.one

def copy(self, default=None):

default = dict(default or {})

default.update({

 '[field you want to change the default value of]': '[value you want]',

})

return super([class you are changing], self).copy(default)

+1 for using new API

Limitless Virtual Enterprise, Andre de Kock
on 8/3/15, 1:20 AM
2

Sudhir Arya (SA)

--Sudhir Arya (SA)--
10150
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

Stackoverflow

Sudhir Arya (SA)
On 4/18/13, 3:07 AM

Here is the syntax to override def copy function in your module:

def copy(self, cr, uid, id, default=None, context=None):
    """
    Duplicate record with given id updating it with default values
    :param default: dictionary of field values to override in the original values of the copied record, e.g: ``{'field_name': overriden_value, ...}``
    :type default: dictionary
    """
    if default is None:
        default = {}
    #Todo code (You can pass your value of any field in default)
    default.update({'your_field': value})
    return super(your_class_name, self).copy(cr, uid, id, default=default, context=context)

You can refer ORM Copy Method.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 4/17/13, 1:20 PM
Seen: 5388 times
Last updated: 7/30/16, 4:17 PM