This question has been flagged
1 Reply
3395 Views

I added a one2many field by custom module like this : 

from openerp.osv import fields, orm

class AccountVoucher(orm.Model):

    _inherit = 'account.voucher'
    _name = 'account.voucher'
    _columns = {
        'bls_to_pay': fields.one2many('stock.picking.out','bl_id','BLS to pay'),
    }

Obviously I added on stock.picking.out (and stock.picking) a many2one field 'bl_id' like this : 

'bl_id': fields.many2one('account.voucher','Bls to pay'),

On the XML Side, I have my one2many field getting his values by an on change method, depending on the selected partner ( I made an onchange method on partner_id field ).

Now, when I select a partner, there are values displayed on the one2many field, I want to get the one2many fiel values, how this can be possible ?

I Know that a one2many field is a logical field, so data are stored on the stock.picking.out model, on the foreign key ( many2one ), I want to know how to access the one2many field values displayed via the foreign key many2one ?

Avatar
Discard

What do you want to do with the values? do you want to sum them up?

Author

I want just one field from the one2many relation, I want to display all its values on a selection field on the same view. it's like copying a column on a selection field.

Author

For that I'm trying another solution explained in my topic here : https://www.odoo.com/forum/help-1/question/functionnal-field-type-selection-issue-openerpv7-70178

Best Answer

Write an onchange_event on the One2many_field, then in onchange_method

use "self.resolve_o2m_commands_to_record_dicts(cr, uid, 'one2many_field', one2many_field, ["field1"])"

By using resolve, one can read the values from O2M_list of records, and use the same for your criteria,

Note: resolve... will wrk only on Onchange_method and default_get... So if this suits  your requirement, try it out...

Avatar
Discard

@deep i am using onchange on many2one field , so it can return some value in one2many , it can return value but whenever i hit button save all records dissapear do you know why ?