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.

0

OpenERP 7 _constraints [Closed]

By
priyankahdp
on 4/17/13, 3:57 AM 4,904 views

The Question has been closed

by
priyankahdp
on 04/18/2013 07:34:50
class deduction_registration(osv.osv):
    _name = "bpl.deduction.registration"
    _description = "Deduction Registration"
    _columns = {
        'name': fields.char('Deduction Name', size=256, required=True),
    }
    _sql_constraints = [('deduction_registration_name_unique', 'unique(name)', 'Deduction name already exists')]

deduction_registration()

I created above sql constraints for my model.but its still allow duplicate records without case sensitive.

like EPF and epf allowed how to add constraint for that.?

Did you restart the server? If yes and if it still not working then try it in new database.

Sudhir Arya (SA)
on 4/17/13, 3:58 AM

thanks Arya. issue with case sensitive.so i added below function for that.

Could you please advice on this ? http://help.openerp.com/question/11827/openerp-7-onclick-function/

priyankahdp
on 4/17/13, 4:01 AM

Achieved the same objective but with sql indexe

Laurent Mignon - Senior Software Engineer, Acsone
on 4/30/14, 11:35 AM
0

priyankahdp

--priyankahdp--
1089
| 5 5 6
Colombo, Sri Lanka
--priyankahdp--
Java Developer ORACLE Python J2EE Spring Hibernate Struts & Jquery............. :-)
priyankahdp
On 4/17/13, 4:00 AM
class deduction_registration(osv.osv):

    def _check_unique_insesitive(self, cr, uid, ids, context=None):
        sr_ids = self.search(cr, 1 , [], context=context)
        lst = [x.name.lower() for x in self.browse(cr, uid, sr_ids, context=context) if x.name and x.id not in ids]
        for self_obj in self.browse(cr, uid, ids, context=context):
            if self_obj.name and self_obj.name.lower() in  lst:
                return False
            return True

    _name = "bpl.deduction.registration"
    _description = "Deduction Registration"
    _columns = {
        'name': fields.char('Deduction Name', size=256, required=True),
    }
    _sql_constraints = [('deduction_registration_name_unique', 'unique(name)', 'Deduction name already exists')]
    _constraints = [(_check_unique_insesitive, 'Deduction name already exists', ['name'])]

deduction_registration()

with this code i have done my job :-)

About This Community

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

Question tools

0 follower(s)

Stats

Asked: 4/17/13, 3:57 AM
Seen: 4904 times
Last updated: 3/16/15, 8:10 AM