콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
6421 화면

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.