Odoo Help


How to pull the right columns from a data source

on 6/19/15, 8:54 AM 789 views

My code so far:

import re

template=My name is [name] and on [date] I have to give [amount] to my friend.

placeholder = re.compile('(\[([a-z]+)\])')

find_placeholder = placeholder.findall(template.text)# get the template

for tgt in tgt_ids: #for each target(i have many),get the name,date,amount

    name = self.pool.get(model).browse(cr, uid, tgt).name # the model is res.partner

    date = self.pool.get(model).browse(cr, uid, tgt).date

    amount = self.pool.get(model).browse(cr, uid, tgt).credit_limit

val = {'val_name': name,

    'val_date': date,

    'val_amount': amount,


message = template.text

for placeholder, key in find_placeholders:

    message = message.replace(placeholder, val.get('val_' + key, placeholder))

    print message

This is working right now, but if i want to get data from another data source(maybe external), probably the fields will have a different name.

For example - The key `name` might be changed to `first_name` or `date` to `payment_date`.

I want the code to be more flexible and to choose the right field every time. Is there any way to do this? Or do I have to change my code every time I change the source?Any ideas?

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

1 follower(s)


Asked: 6/19/15, 8:54 AM
Seen: 789 times
Last updated: 6/20/15, 8:30 AM