Odoo Help


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.


On change a relational field

Javier Batres Velásquez
on 3/4/15, 10:02 AM 377 views

Hello I am trying to make an on change. Everything is ok, The field call the method and all. BUt when this had that feed another field this give me error:

I am trying to feed a relational(Many2one) with the results of a query. Here is my code:


    invoice = fields.Many2one('account.invoice', string='Factura')
    client = fields.Many2one('res.partner', string='Cliente', domain=[('customer', '=', True)])

    def _searchInvoice(self):
        if self.client is not None:
            invoice = self.env['account.invoice'].search([('type', '=', 'out_invoice'),
                                                           ('partner_id', '=', self.client.id)])
            self.invoice = invoice


Cyril Gaspard (GEM)

--Cyril Gaspard (GEM)--
| 5 6 8
Paris, France
--Cyril Gaspard (GEM)--

Forum contributor since 2008

Cyril Gaspard (GEM)
On 3/4/15, 6:43 PM

Hi, there is some troubles in your code :

0) names field should be invoice_id and partner_id instead invoice and client.

1) You define 2 fields many2one and a search on account_invoice objet with domain partner_id => a partner has just one invoice ? Is there a reference between current objet and acccount_invoice to add in search domain to get maximum one id in the returned list by the search ? If not,, you should use a one2many field type for account_invoice relation, the name of the field will be invoice_ids instead invoice in this case.

2) a search return a list of id, with your code you try to set a list in a many2one, it is not possible, you must set an id.


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)


Asked: 3/4/15, 10:02 AM
Seen: 377 times
Last updated: 3/16/15, 8:10 AM