Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
I would like to have a feature on the one2many field. Usually we can add any number of values to a one2many field. But I want restrict the user to enter only the first three values and not more than three. Three is just an example count. I should be able to define it to any number.
To be more clear, I want the user to enter only 3 line items in the sales order. After entering 3 line items, the create/add option should disappear.
Is there any way already existing? or is it to be implemented yet?
Thanks in advance.
I have solution but without disappear Create/add option. To override create and write method and allow to user enter only 3 lines item.
def create(self, cr, uid, vals, context=None): if vals.get('order_line'): count = len(vals.get('order_line')) if count > 3: raise osv.except_osv(_('Warning!'), _('Limit to create 3 Lines')) return super(sale_order, self).create(cr, uid, vals, context=context) def write(self, cr, uid, id, vals, context=None): if vals.get('order_line'): count = len(vals.get('order_line')) if count > 3: raise osv.except_osv(_('Warning!'), _('Limit to create 3 Lines')) return super(sale_order, self).write(cr, uid, id, vals, context=context)
I posted similar question of yours, but I need when user add more than , let's say, 5 items I warn him and delete the extra elements.
I was able to do onchange method, but I am not able to delete the extra items he added. Also I don't need to wait until the user click the parent "Save" button, but I need once he added the extra child element I delete it before waiting until save.
I tried to delete the extra item from child_ids list, or to use the unlink function but of Parent and Child, but no luck =(
How to delete the extra elements?
here is my post:
I have found a solution that best suits my requirement. That is to have a on_change method for the x2many field and check the count using len() python function. If it is more than 3 or x number, then popup a error message.
Apart from these, there are two other solutions. they have been mentioned already by Yug Faa and Prakash. i.e
1) Customize the x2many widget using js
2) Inherit the create and write method
Thanks to Prakash and Yug for their contribution.
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.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 4/15/14, 7:38 AM|
|Seen: 2825 times|
|Last updated: 2/28/16, 10:52 AM|