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

How to browse One2many field in Odoo?

By
elalaoui
on 4/22/15, 11:32 AM 719 views

hi,

how can I list items of  one2many fields ?

this is my code:

class import_invoice(osv.osv):

_name = 'import.invoice'

_columns = {

'name' : fields.char(string="Nom Facture", required=True),

'account_id' : fields.many2one('account.invoice', string="Facture Achat"),

'dossier_import_id' : fields.many2one("dossier.import", string="Dossier Import"),

'complementary_invoice_ids' : fields.one2many('complementary.invoice','import_invoice_id', string="Facture Complementaire"),

'import_invoice_lines_ids' : fields.one2many('import.invoice.lines','import_invoice_id', string="Articles"),

}

string_tab = [('cout', "Cout"),('quantity', "Quantity"),]

class complementary_invoice(osv.osv):

_name='complementary.invoice'

_columns = {

'name' : fields.char(string="Nom Facture", required=True),

'supplier_invoice' : fields.many2one('account.invoice', string="Facture Origine"),

'montant_id' : fields.related('supplier_invoice','amount_total',type="float",string="Montant"),

'bursting_type' : fields.selection(string_tab, string="Type Eclatement", default="cout"),

'complementary_invoice_lines_ids' : fields.one2many('complementary.invoice.lines','complementary_invoice_id', string="Articles", required=True),

'import_invoice_id': fields.many2one('import.invoice', string="Facture Import"),

}

and i want to list all items of 'complementary_invoice_ids' fields because i need excatly the montant_id and bursting_type of each complementary_invoice_ids .

Thank you very much

you can get list items of one2many field by browse_record.field_name, where browse record will be the record of model in which one2many field is present. For example you want to list order lines of a sale order. You will be having sale_id order_lines_items = self.pool.get('sale.order').browse(cr,uid,sale_id).order_line Here order_line is one2many field. order_line_items will contain list of browse records of sale order line. I hope this what you are asking about.

Michael Pol
on 4/22/15, 11:47 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: 4/22/15, 11:32 AM
Seen: 719 times
Last updated: 4/22/15, 6:07 PM