This question has been flagged
2 Replies
4895 Views

For example I have two fields Name =divya and Email=kalluru@gmail.com after saving Email = divya<kalluru@gmail.com>

 <field name="name"/>

<field name="email"/>

how to replace email by  splitting  it in to this formate can any please provide code for it.

 

Avatar
Discard

Divya, you should create either a functonal field, or run an onchange method to combine them.

Best Answer

It can be easily achieved by overriding create and  write functions. for Example,

def create(self, cr, uid, vals, context=None):
    if vals.get('name') and vals.get('email'):
        vals.update({'email': vals.get('name') + ' <' + vals.get('email') + '>'})
    return super(class_name, self).create(cr, uid, vals, context)

and write method

def write(self, cr, uid, ids, vals, context=None):
    for rec in self.browse(cr, uid, ids, context):
        if vals.get('name') or vals.get('email'):
            vals.update({'email': vals.get('name') or rec.name + ' <' + vals.get('email') or rec.email + '>'})
    return super(class_name, self).write(cr, uid, ids, vals, context)

Hope this helps.

 

Avatar
Discard
Best Answer

Use Python Regular expressions and String Split Method ,

Emails Example

Suppose you want to find the email address inside the string 'xyz alice-b@google.com purple monkey'. We'll use this as a running example to demonstrate more regular expression features. Here's an attempt using the pattern r'\w+@\w+':

  str = 'purple alice-b@google.com monkey dishwasher'   match = re.search(r'\w+@\w+', str)   if match:     print match.group()  ## 'b@google'

The search does not get the whole email address in this case because the \w does not match the '-' or '.' in the address. We'll fix this using the regular expression features below.

Avatar
Discard