nitesh
nitesh

Reputation: 266

How can i validate for Creation of Lead in my Custom Module in Openerp

I have my custom module. When i create a new lead, it is validation for Subject (field name="name"), if that field is not filled we cannot create a Lead. But I want to create the Lead only if I enter either of Email or Phone number.

How can I check whether that those fields are empty or not before creating the Lead and inform user to enter either Email or Phone.

Thanks in advance.

Upvotes: 0

Views: 113

Answers (2)

Avadhesh
Avadhesh

Reputation: 4703

You can try the following in your .xml file:

<field name="email" attrs="{'required': [('phone','=', False)]}"/>
<field name="phone" attrs="{'required': [('email','=', False)]}"/>

Hope this will help you

Upvotes: 0

Bhavesh Odedra
Bhavesh Odedra

Reputation: 11143

If the Fields are required True, than we must give value for the Fields. If we forget to set value, the Notification comes like that filed is not set and mark with Red Rectangle.

  • Now Without Create Lead with No given Subject. Than You Need to change the Data Structure of Table. Search for name field and remove required=True, And Start server with -u module_name -d database_name

  • Now Create a Lead if Only Email or Phone Number has value. Need to below code of button Click Method. You can add attribute required=1 for Email and Phone. If the User not set the value than it's give notification like Subject For Example

    email = vals.get('email_from')
    phone = vals.get('phone')
    
    if not email:
        raise osv.except_osv(_('Warning!'), _('Please Enter Email.'))
    elif not phone:
        raise osv.except_osv(_('Warning!'), _('Please Enter Phone Number.'))
    

Upvotes: 1

Related Questions