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 display a field from a different model?

By
AJ Schrafel Paper Corp
on 6/5/13, 3:03 AM 1,276 views

I wrote a customer module and I want to display the website address of the partner in my view. I am storing partner_id in my custom module.

I realize that I could store the website in my custom module, but i think that is duplicative, a waste of hard drive space and gets much more complicated as you want to display more fields from different modules.

What can I put in my xml view for my custom module to retrieve the website of the partner_id I am presently viewing in the form?

0

AJ Schrafel Paper Corp

--AJ Schrafel Paper Corp--
2060
| 4 5 8
Bronx, United States
--AJ Schrafel Paper Corp--

Exploring OpenERP for business

AJ Schrafel Paper Corp
On 7/16/13, 11:37 AM

i couldn't get this to work exactly the way i wanted to, but i did come up with a solution. I added a function to my customer module which will retrieve the website from the partner record, but not store it.

    def _get_website(self, cr, uid, ids, partner_id, args, context=None):
        res={}
        context = {}
        partner_obj = self.pool.get('res.partner')
        for record in self.browse(cr, uid, ids, context=context):
            res[record.id] = {}
            website_ids=partner_obj.search(cr, uid, [('id','=',record.partner_id.id)])
            for website_brw in partner_obj.browse(cr, uid, website_ids, context=context):
                res[record.id] = website_brw.website
        return res

_columns = {
        'website': fields.function(_get_website, type="char", string='Website', store=False),
}

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: 6/5/13, 3:03 AM
Seen: 1276 times
Last updated: 3/16/15, 8:10 AM