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.

0

Get values from python method - Odoo 8

By
Alejandro Perez Cosio
on 12/18/14, 10:45 AM 640 views

Hello all

Is there a way to call a method in the .py file from the xml without define a new field?
E.g.:

model.py
@api.model
def get_companies(self):
    return 
self.env['res.partner'].search(['is_company', '=', True])

view.py
<field name="get_companies" colspan="4" nolabel="1">
    <tree string="Companies">
        <field name="id"/>
        <field name="name"/>
        <field name="vat"/>
    </tree>
</field>

Regards
Alejandro

0

Ivan

--Ivan--
3210
| 5 3 6
Jakarta, Indonesia
--Ivan--
Ivan
On 12/18/14, 12:07 PM

If the method does not depends on specific records, you may want to try to use context supplied from fields_view_get.  However I think function field is easier to implement.

Thank you Ivan, then, I will use a function field to reference those values. Could you please include some source or explanation for fields_view_get usage to accept your answer as the solution?

Alejandro Perez Cosio
on 12/18/14, 12:49 PM

The two samples that you'll find most useful, AFAIK, is from account.voucher (odoo/addons/account_voucher/account_voucher.py) and account.invoice (odoo/addons/account/account_invoice.py). They are a model that is used for several purposes (types) and the view need to be customised for each purpose/type.

Ivan
on 12/18/14, 9:12 PM

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)

Stats

Asked: 12/18/14, 10:45 AM
Seen: 640 times
Last updated: 3/16/15, 8:10 AM