Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
2 Antwoorden
10997 Weergaven

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. 

Avatar
Annuleer
Beste antwoord

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)].

Avatar
Annuleer

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

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.

Auteur Beste antwoord

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

Avatar
Annuleer