Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
6377 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ

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.