Odoo Help


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.


How to pull the right columns from a data source

on 6/19/15, 8:54 AM 352 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?

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

1 follower(s)


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