OpenERP model tracking external resource, hooking into parent's copy() or copy_data()

Posted by CB. on Stack Overflow See other posts from Stack Overflow or by CB.
Published on 2012-06-25T20:46:04Z Indexed on 2012/06/26 9:16 UTC
Read the original article Hit count: 156

Filed under:
|
|

I have added a new model (call it crm_lead_external) that is linked via a new one2many on crm_lead.

Thus, my module has two models defined: an updated crm_lead (with _name=crm_lead) and a new crm_lead_external.

This external model tracks a file and as such has a 'filename' field.

I also created a unique SQL index on this filename field.

This is part of my module:

def copy(self, cr, uid, id, default=None, context=None):
    if not default:
        default = {}
    default.update({
        'state': 'new',
        'filename': '',
    })
    ret = super(crm_lead_external, self).copy(cr, uid, id, default, context=context)
    #do file copy
    return ret

The intent here is to allow an external entity to be duplicated, but to retarget the file path.

Now, if I click duplicate on the Lead, I get an IntegrityError on my unique constraint. Is there a particular reason why copy() isn't being called?

Should I add this logic to copy_data()? Myst I really override copy() for the lead?

Thanks in advance.

© Stack Overflow or respective owner

Related posts about model

Related posts about copy