Odoo Help


How to limit the adding of item in a one2many field?

Abegail Sanchez
on 10/15/14, 12:18 AM 1,815 views

I just want to limit the item that can be input in my

module( let's say 20 lines) which has one2many relationship.

Abegail Sanchez
On 10/16/14, 10:14 AM

I made some dirty hack in js

I added this line:

                if(this.records.length < this.o2m.options.add_limit){
                    this._super.apply(this, arguments);
                    alert('Cannot add an item \nLimit Exceed:'+this.o2m.options.add_limit);
                this._super.apply(this, arguments);

and this in my view.xml:

<field name="one2many_field' options="{"add_limit":28}" />

So the user cannot add item next of it.


Nirav Jani
On 10/15/14, 12:43 AM


you can use limit in one2many field. like this:

'order_line': fields.one2many('sale.order.line', 'order_id', 'Order Lines', limit=10),


It will limit only the display but adding can still continue. What I mean is that adding of item should stop after 20 lines. Or the "add item" should disappear.

Abegail Sanchez
on 10/15/14, 3:24 AM

Hello you can check on create method like this: def create(self, cr, uid, vals, context=None): if len(vals.get('line_ids')) > 3: raise osv.except_osv(_('Warning!'), _('Record limit is over!'))

Nirav Jani
on 10/15/14, 8:28 AM

About This Community

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


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 10/15/14, 12:18 AM
Seen: 1815 times
Last updated: 3/16/15, 8:10 AM