Help

How to write my own validation on default save button in partners ?

Closed
Avatar
Sohail

The question has been closed

by
Sudhir Arya (ERP Harbor Consulting Services)
on 05/18/2013 07:40:20

I need to write my own validation on default save button of openerp 7.0 in partners where I check validation for certain fields.

Avatar
Discard
1 Answer
5

For that you need to override two methods in res.partner class.

  1. create: Which is called when new record is created.
  2. write: Which is when existing record is updated.

Override create:

def create(self, cr, uid, vals, context=None):
    #Your code goes here
    res = super(your_class_name, self).create(cr, uid, vals, context=context)
    #Your code goes here
    return res

Override write:

def write(self, cr, uid, ids, vals, context=None):
    #Your code goes here
    res = super(your_class_name, self).write(cr, uid, ids, vals, context=context)
    #Your code goes here
    return res

You can use _constraints also to validate your fields.

def _my_check_method(self, cr, uid, ids, context=None):
    #Your code goes here
    return True or False

_constraints = [(_my_check_method, 'Your Message', ['your_field']),]

Return True if your validation condition satisfy, False otherwise from your method of constraints.

Avatar
Discard