Skip to Content
Menu
This question has been flagged
3 Replies
7760 Views

class scheme_type_info(osv.osv):
    
    _name='scheme.type.info'
    
    _columns={
              'scheme_id':fields.integer('Scheme Type',required=True,size=50),
              'interval':fields.integer('Start Days',required=True,size=64,help="set the number of start date interval"),
              'interval1':fields.integer('End Days',required=True,size=64,help="set the number of end date interval"),
              'criteria':fields.integer('Number of Tickets',required=True),
              'salary':fields.float('Amount',required=True),
              'active':fields.boolean('Active')
              }
    _sql_constraints=[('unique_scheme_id','unique(scheme_id)','Error! scheme Id Already Exist')]

    _sql_constraints=[('unique_interval','unique(interval)','Error! Start Day Already Exist')]
    
    _sql_constraints=[('unique_interval1','unique(interval1)','Error! End Day Already Exist')]
    
scheme_type_info()

Avatar
Discard
Best Answer

_sql_constraints is a list so you can add them like: 

_sql_constraints =[('unique_scheme_id','unique(scheme_id)','Error! scheme Id Already Exist'), ('unique_interval','unique(interval)','Error! Start Day Already Exist'),('unique_interval1','unique(interval1)','Error! End Day Already Exist')]

 

Avatar
Discard
Best Answer

I'm not sure how your code will perform, either throw an error, or just use the last constraint.

But what you want is easy to achieve:

sql_constraints is a list of tuples: So add all your constraints into one list:

_sql_constraints = [
    ('unique_scheme_id', 'unique(scheme_id)', 'Error! scheme Id Already Exist'),
    ('unique_interval', 'unique(interval)', 'Error! Start Day Already Exist'),
    ('unique_interval1', 'unique(interval1)', 'Error! End Day Already Exist')
]

Note: It might be possible that you want the combination of those three fields to be unique. In that case, use only one unique statement with all fields as argument:

_sql_constraints = [('unique_sheme_type', 'unique(scheme_id,interval,interval1), 'Error! This Type already exists!')]

 

Regards.

Avatar
Discard
Author

Hi, This time only two constraints is taken not excecute 'unique_interval1', 'unique(interval1)', 'Error! End Day Already Exist') this constraints fields

Hi,

I'm facing this issue just last constraint is getting added, and all are adding as index in postgres, can you suggest me any solution

Best Answer

Try this : It will work

_sql_constraints = [('unique_scheme_id','unique(scheme_id)','Error! scheme Id Already Exist'),

                                       ('unique_interval','unique(interval)','Error! Start Day Already Exist')]

 

Avatar
Discard