Odoo Help

0

0
5 Answers
2
Avatar

Prakash

--Prakash--

11546
| 6 7 9
Bikaner, India
--Prakash--

OpenERP Developer at SunARC Technology

Prakash
15/04/14, 08:18

I have solution but without disappear Create/add option. To override create and write method and allow to user enter only 3 lines item.

Example:-

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)
1 Comment
Vivekrajan Rayappan
15/04/14, 08:36

Prakash, that works but a little late while saving the form. But It should work instantly as we try to add the fourth one. Because, i will be able to add more than 3 upto any number with your solution and it is going to warn me only at the moment of saving the form. my time of entering more than 3 should be saved right upfront. I think it is only possible if we make changes in the x2many widget java scripts

1
Yug Faa
15/04/14, 09:35

You will find a addons here :

bzr branch lp:~sylvain-legal/web-addons/web_field_float_compute

Module named : web_m2x_options

Make it resolved !

0
Ameen Rabea
28/02/16, 10:52

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: 

https://www.odoo.com/fr_FR/forum/aide-1/question/how-to-prevent-adding-more-than-x-items-into-one2many-98375



0
Vivekrajan Rayappan
26/04/14, 04:55

Hi,

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.

Ask a Question
Keep Informed
0 follower(s)
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 eLearning platform and experience all Odoo Apps through learning videos, use cases and quizzes.

Test it now