Odoo Help


How to check field to be mandatory on create and write?

on 5/18/13, 7:48 AM 2,098 views

I have defined my 2 new fields first_name and last_name for a person-partner. Also when I say that the partner is a company then only name field is mandatory and other two are not.The problem comes when I set all 3 fields to mandatory by setting required=True which is not possible.So the solution is I need to check these at the create and write. How to go about it?



--Borni DHIFI--
| 6 8 9
Tunis, Tunisia
--Borni DHIFI--

Techno Functional Consultant Odoo(OpenERP) 


Skype : dhifi.borni

On 5/18/13, 8:12 AM


you must define the method create in your custom module and make tests in this function.

def create(self, cr, uid, vals, context=None):
       if context is None:
       if  not vals.get('is_company') : 
            if not vals.get('first_name') :
                raise osv.except_osv(('Error first_name'), 
                                     (' first_name required  ') )

            if not vals.get('last_name') :
                raise osv.except_osv(('Error last_name'), 
                                     (' last_name required  ') )
      return super(res_partner,self).create(cr, uid, vals, context=context)

and same in methods write and copy.


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 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 5/18/13, 7:48 AM
Seen: 2098 times
Last updated: 7/1/15, 3:20 AM