Odoo Help


4 答案

Pawan Kumar Sharma 印度

--Pawan Kumar Sharma--
SunArc Technologies
| 6 3 7
Gangashahar(Bikaner), 印度
--Pawan Kumar Sharma--

Pawan Kumar Sharma 印度
2018/1/24 上午6:55

I already added this, but it's not work for me. Your solution from old api link, i already seen this link

_sql_constraints = [

('rental_manag_location_uniq', 'unique(location_id)', 'Location ID must be unique !'),


1 备注
Nikhil Krishnan 阿拉伯联合酋长国
2018/1/24 上午6:57

Try it in new database, you can get it,


Nikhil Krishnan 阿拉伯联合酋长国

--Nikhil Krishnan--
| 7 7 10
Sharjah, 阿拉伯联合酋长国
--Nikhil Krishnan--

-- Nikhilkrishnan --

Exploring new ways in odoo..!
And want to become a key to the new odoo trends.

-> Odoo Consultancy,
-> Functional and Technical Consultant,
-> Requirement Collection and Analysis,
-> Module Customization,
-> Odoo ERP Community Contributor,
-> Handling ERP/Odoo projects,
-> ERP Workshop Facilitator.
Feel happy working with best and good supporting team.

#PITS Family

Nikhil Krishnan


Nikhil Krishnan 阿拉伯联合酋长国
2018/1/24 上午6:50

Hai Pawan Sharma, 

_sql_constraints = [        ('name_uniq', 'UNIQUE (name)',  'You can not have two users with the same name !')    ]

'name_uniq' is constraint name give any name.(no need to define)

Example _constraints:-

    def _check_name(self, cr, uid, ids, context=None):
        for val in self.read(cr, uid, ids, ['name'], context=context):
            if val['name']:
                if len(val['name']) < 6: 
                   return False       

            return True

    _constraints = [        (_check_name, 'Name must have at least 6 characters.', ['name'])    ]

Note: Based on the above example in the records name field any duplicate record or name field less than 6 character then remove the records and add the constraints in python restart the server, update the module then only it works.

Sehrish 巴基斯坦
2018/2/14 上午3:42
 _sql_constraints = [
('value_campus_studenttype_policyfor_uniq', 'unique (campus_id,student_type,policy_for)', 'Record for this Campus and Student Type and Policy are already exists !')

Try this one

Keep Informed
1 关注者(s)
About This Community

This platform 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.

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now