Duplicate funtion can't work with constraints!

Asked by Cuong

Hi,

I make some constraints on some fields of table (object) to make sure that these fields are unique. In the form view, there is a button 'Duplicate' to make a copy of existed record. But it failed due to these constraints.

So I wonder there are some ways to empty these unique fields when doing Duplicate action to avoid these constraints.

In my case, I make a constraint to avoid overlapping in time between contracts for the same employee.
1. contract 1: from 1/1/2011 to 31/12/2011
2. contract 2: must not be in the interval of contract 1. Maybe from 1/1/2010 to 31/12/2010, not 1/1/2011. Or maybe from 1/1/2012, not 15/12/2011.

When I do Duplicate action, this constraint is activated, so can't make a new record.

Thanks.

Question information

Language:
English Edit question
Status:
Solved
For:
Odoo Server (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Solved by:
OpenBMS JSC
Solved:
Last query:
Last reply:
Revision history for this message
Best OpenBMS JSC (openbmsjsc) said :
#1

You can override the copy method to reset values for fields in the newly created copy.

Revision history for this message
Cuong (bhcuong2008) said :
#2

Could you show me how? I have a little understanding of OpenERP.

Thank you very much.

Revision history for this message
OpenBMS JSC (openbmsjsc) said :
#3

There are plenty of example in the code, e.g. addons/account/account.py