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.

2

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

By
Sohail
on 5/17/13, 1:32 PM 3,391 views

The Question has been closed

by
Sudhir Arya (SA)
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.

4

Sudhir Arya (SA)

--Sudhir Arya (SA)--
10150
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

Stackoverflow

Sudhir Arya (SA)
On 5/17/13, 3:34 PM

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.

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 5/17/13, 1:32 PM
Seen: 3391 times
Last updated: 4/10/15, 7:18 AM