Odoo Help

Welcome!

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.

0

Validation with _constraint gets aplied to all forms?

By
Ronald
on 5/6/14, 2:04 PM 1,078 views

After adding the following code I was able to add a custom field to the customer/supplier creation form and also got to validate the value entered in the field to be only numeric.

While testing I tried to change the language for the current user and the constraint got triggered there as well , any idea on how to limit it only to the customer/supplier creation form ?

Thanks again for reading this post.

class cs_dni(osv.Model):

_inherit = 'res.partner'

_columns = {
    'x_dni': fields.char('DNI.', size=13, required=True)
} 
.......
def _check_value(self, cr, uid, ids, context=None):
    for val in self.browse(cr, uid, ids, context=context):
        if val.x_dni and isinstance(val.x_dni, int):
            return True
    return False

_constraints = [
    (_check_value, 'You cannot add value other than integer".', ['x_dni']),
]

Here is the screen shoot i57.tinypic.com/1zxbnfo.png

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)

Stats

Asked: 5/6/14, 2:04 PM
Seen: 1078 times
Last updated: 3/16/15, 8:10 AM