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

Function field that returns list

By
Nikolay Fominykh
on 2/2/15, 7:55 AM 1,050 views

We're trying to create odoo function field, that renders as list. And problem, that function does not execute. 

Extended question with code here: http://stackoverflow.com/questions/28278120/odoo-function-field-that-returns-list

UPD Changed code according to Ivan's comment. Not helped. Question is more about, why it's not entering "_orders" function at all. 

1

Ivan

--Ivan--
3210
| 5 3 6
Jakarta, Indonesia
--Ivan--
Ivan
On 2/2/15, 8:19 AM

The return should be a dictionary which keys are the ids of the processed object and the values are the returned values.  I see that you are setting it as type many2many.  x2many has a special way to specify the entries to add.  For many2many the returned values need to be in the form of [(6, 0, [XXXX])]  where [XXXX] is the list of IDs that you want to link.

Also you are mixing v8 sytax with v7 syntax.  I'm not quite sure if it is OK.

So your method should look something like:

def _orders(self, cr, uid, ids, fields, arg, context=None):

    res = {}

    statement = self.browse(cr, uid, context.get('active_id', False), context=context)

    _order_pool = self.pool.get('sale.order')

    if statement and statement.partner_id:

         for _obj in self.browse(cr, uid, ids, context=context):

            _orders = _order_pool.search(cr, uid, [('partner_id', '=', statement.partner_id.id), ], context=context)

            res[_obj.id] = [(6, 0, _orders)]

    return res

To pre-populate the orders, you need to create the "account.bank.statement.review.wizard", passing the appropriate context, before displaying the view while passing the domain [('id', '=', created_wizard_id)].

what is the value of res[_obj.id] = [(6, 0, _orders)] ( 6,0 means)

Odoo
on 2/2/15, 9:06 AM

It's the command to ORM to populate x2many fields. Read more on that in the odoo/openerp/osv/fields.py, search for many2many class.

Ivan
on 2/2/15, 11:15 PM
0
Nikolay Fominykh
On 2/2/15, 10:02 AM

New code looks like this: 

http://pastebin.com/jGVsdE8W

Still not works. Just not entering "_orders" function. 

UPD 

Final solution: http://stackoverflow.com/questions/28278120/odoo-function-field-that-returns-list/28283303#28283303

Inspired from here: https://www.odoo.com/forum/help-1/question/how-to-declare-fields-function-in-odoo-8-standard-i-got-error-72079

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/2/15, 7:55 AM
Seen: 1050 times
Last updated: 3/16/15, 8:10 AM