I have two models Parent and Child. In the Parent form I am allowing the user to adding Childs based on the One2Many relation between Parent and Child. Then I need to prevent him from adding more than X number of Childs, how to achieve
I have two models Parent and Child. In the Parent form I am allowing the user to add Childs based on the One2Many relation between Parent and Child. Then I need to prevent from adding more than X number of Childs, how to achieve this?
Right now I am able to check the number of added childs using OnChange(). and the alert message appears to the user that he acceded the limit of childs.
Assume the limit is 3 childs, how can I do the following:
After adding the 4 childs, show alert message (this already done), then delete the last added child(s) that acceds the limit
Or, once childs max limit achieved, hide the "Add an Item" link
Hi Abu Faisal,
Should you create a pythonic constrain @api.constrains('One2many') and do a check on One2many field length using len() and raise warning.
Something like this, https://github.com/odoo/odoo/blob/9.0/addons/account/models/account_invoice.py#L1236
len(self.One2many_field) would give you records number and then you can raise warning.
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
|Asked: 2/28/16, 10:39 AM|
|Seen: 366 times|
|Last updated: 2/29/16, 1:39 AM|