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

Trying to show informations

By
Lawrence
on 2/18/13, 5:10 PM 1,206 views

I'm trying to display function fields in a sort of listview (not editable). Something like Customer Invoices in Accounting.

Here is my current code. (py) I use a function field with a range, etc just to do a test.

def _get_partners(self, cr, uid, ids, name, arg, context):
res = {}
partners_obj = self.pool.get('res.partner')
listIds = range(1, 10000)
partners_list = partners_obj.search(cr, uid, [('id', 'in', listIds)])
for element in partners_list:
    partner = partners_obj.browse(cr,uid, element)
    partner_name = partner.name
    res[partner.id] = partner_name
print(res)
return res

_name = 'aged.partner.balance'   
_description = 'Aged Partner Balance'
_columns = {
    'partner_id': fields.function(_get_partners, type='char', store=False, method=True,)

aged_partner_balance()

<record id="aged_partner_tree" model="ir.ui.view"> <field name="name">aged.partner.balance.tree</field> <field name="model">aged.partner.balance</field> <field name="arch" type="xml"> <tree string="Aged Partner Balance" >="" <field="" name="partner_id" string="Name"/> </tree>
</field> </record>

and where is the question?

tolstoj
on 2/18/13, 6:45 PM

ops ye. well It doesnt show the information that my function return. I see 'name' and nothing else. Wondering what i did wrong

Lawrence
on 2/18/13, 8:00 PM
1

Cyril Gaspard (GEM)

--Cyril Gaspard (GEM)--
4136
| 5 6 8
Paris, France
--Cyril Gaspard (GEM)--

Forum contributor since 2008

Cyril Gaspard (GEM)
On 3/2/13, 4:12 PM

Hi,

try this :

in your function _get_partners, you must find list of ids you need corresponding to result you want :

def _get_partners(self, cr, uid, ids, name, arg, context):
    if context is None:
        context = {}
    res = {}
    for info in self.browse(cr, uid, ids, context=context):
        cr.execute("""SELECT id FROM res_partner WHERE id BETWEEN 1 AND 10000""")
        list_ids = cr.dictfetchall()
        if list_ids:
            final_list = []
            for info in list_ids:
                 final_list.apend(info)
            res[info.id] = final_list
    print res
    return res

_name = 'aged.partner.balance'   
_description = 'Aged Partner Balance'
_columns = {
    'partner_ids': fields.function(_get_partners, type='one2many' relation='res.partner', method=True, string='Name displayed field')

Hope this will help and work.

Bye

I update my answer to add possibility to display the tree. Bye

Cyril Gaspard (GEM)
on 3/9/13, 8:52 AM

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: 2/18/13, 5:10 PM
Seen: 1206 times
Last updated: 3/16/15, 8:10 AM