Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
1 Vastaa
6383 Näkymät

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

Avatar
Hylkää
Paras vastaus

Hello,

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"))
    else:
        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.

Avatar
Hylkää

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

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().

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

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

Exact, my bad.