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.

1

Access one2many field values openerp7

By
Yassine TEIMI
on 12/11/14, 9:06 AM 845 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 ?

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

Abdullah Sofan
on 12/11/14, 10:17 AM

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.

Yassine TEIMI
on 12/11/14, 10:29 AM

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

Yassine TEIMI
on 12/11/14, 10:30 AM
3

deep

--deep--
1617
| 5 4 7
Bengaluru, India
--deep--

Techno-Functional Associate with 6+ years of experience in Odoo (formerly known as OpenERP).

deep
On 1/3/15, 3:19 AM

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

@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 ?

Ajeng Shilvie
on 1/16/15, 4:29 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

5 follower(s)

Stats

Asked: 12/11/14, 9:06 AM
Seen: 845 times
Last updated: 3/16/15, 8:10 AM