Odoo Help

Welcome!

This community 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.

1

how to restrict number of records to create

By
Atchuthan - Technical Consultant, Sodexis Inc
on 8/5/13, 9:43 AM 1,362 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

1

Hiral Patel (hip)

--Hiral Patel (hip)--
Tiny ERP Pvt Ltd
http://www.odoo.com
913
| 2 1 5
India
--Hiral Patel (hip)--


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

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.

Xsias
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 ?

Xsias
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.

Xsias
on 8/7/13, 5:23 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

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