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 check field to be mandatory on create and write?

By
Sohail
on 5/18/13, 7:48 AM 2,046 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?

-1

Borni DHIFI

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

Techno Functional Consultant Odoo(OpenERP) 

http://www.linkedin.com/in/borni

Skype : dhifi.borni

Borni DHIFI
On 5/18/13, 8:12 AM

Hi,

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:
            context={}       
       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.

Thanks.

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

0 follower(s)

Stats

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