OpenERP model tracking external resource, hooking into parent's copy() or copy_data()
- by CB.
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.