Odoo Help


how to restrict number of records to create

Atchuthan - Technical Consultant, Sodexis Inc
on 8/5/13, 9:43 AM 2,075 views

Hi friendz,

Is there any way to restrict the number of records to be created for a single object or table

My requirement needs me to create only 3 contacts for my company. Is there any way to do so.

Thanks & Regards, Atchuthan


Hiral Patel (hip)

--Hiral Patel (hip)--
| 2 1 5
--Hiral Patel (hip)--

Hiral Patel (hip)
On 8/6/13, 4:06 AM


You can do this by def create() like:

class test(osv.osv):

_name = "test"

def create(self, cr, uid, vals, context=None):
    limit = len(self.search(cr, uid, [], context=context))
    if(limit >= 15):
        raise osv.except_osv(_("Warning!"), _("Message to display"))
        return super(test, self).create(cr, uid, vals, context=context)

Here, test should be name of your object. I have given to 15 record's creation.

Exactly what i would have answering. Maybe you must overwritten the write too.

on 8/6/13, 6:05 AM

def write() is used to update the record. And in question it's to restrict number of records to create., So no needed to overwrite write().

Hiral Patel (hip)
on 8/6/13, 6:45 AM

When you add a contact to an already existing Customer, it don't pass by Customer write ?

on 8/6/13, 8:24 AM

@Xsias I have fetched all the records of 'test' object. We need to pass domain according to our requirement.

Hiral Patel (hip)
on 8/7/13, 3:15 AM

Exact, my bad.

on 8/7/13, 5:23 AM

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

Question tools

0 follower(s)


Asked: 8/5/13, 9:43 AM
Seen: 2075 times
Last updated: 3/31/15, 5:37 PM