Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
6368 มุมมอง

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

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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.

อวตาร
ละทิ้ง

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.