Odoo Help


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.


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

Abegail Sanchez
on 10/15/14, 12:18 AM 1,023 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

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

1 follower(s)


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