Odoo Help


How to send a field value from sale order to invoice?

on 6/7/13, 3:46 AM 4,688 views

I added a custom field to sale order and i want to send this value from sale order to invoice view. I tried adding it through sale_line_invoice wizard and in _prepare_invoice method in sale.order. Also i added that field to account.invoice and its view. I then restarted my server, cleared cache and updated my module. But when i create any order and click on Create final invoice i get this error: Unknown Error can't adapt type 'browse_record'.


Davide Corio

--Davide Corio--

| 5 4 7
Bricherasio, Italy
--Davide Corio--

Odoo Evangelist and Consultant

Davide Corio
On 6/7/13, 4:20 AM

the _prepare_invoice method of sale.order is what you need. the comment says:

Prepare the dict of values to create the new invoice for a sales order.

so you need to override this method in a custom module of yours, in order to extend the invoice_vals dictionary, with something like:

class my_sale_order(osv.Model):
    _inherit = "sale.order"
    def _prepare_invoice(self, cr, uid, order, lines, context=None):
        ## your code

hey m not having any custom module but i just added a single custom field to sale order earlier and now i want to use that field in invoice too with the values.

on 6/7/13, 4:23 AM

then i guess you edited the openerp source code. it's always preferable to create a custom module and inherit the code, otherwise you're going to lose your changes with the next openerp update

Davide Corio
on 6/7/13, 4:25 AM

i know but i succesfully did everything but now my field shows this value which is obviously some error browse_record(res.reference, 1)

on 6/7/13, 4:27 AM

you're referring to an object instead of an attribute. probably your_value.name will fix this

Davide Corio
on 6/7/13, 4:28 AM

thanks a lot it works now with the attribute.

on 6/7/13, 4:45 AM
Tintu Mon
On 3/25/16, 9:41 AM

 For creating "account.invoice" from "sale.order" there is four selection option

  • delivered

  • all

  • percentage

  • fixed

I tried a function "def action_invoice_create(self, grouped=False, final=False): " using super in inherited sale.order. It works fine for sending a field value from sale.order to account.invoice, when the selection field is "delivered" or "all".

Instead of "def action_invoice_create(self, grouped=False, final=False): " I tried with "def _prepare_invoice(self, cr, uid, order, lines, context=None):" also. But same happened it's not working for "percentage" and "fixed" selections.

So I used another function "def _create_invoice(self, order, so_line, amount):" using super in inherited wizard/sale_make_invoice_advance.py

It propagated the field value from sale.order to account.invoice successfully. I have tested it in debug also.

Does it right way to achieve? or any other way?

Note: I worked on ODOO9

Amit Parik (amp)
On 6/7/13, 4:32 AM

Hello Evon,

You are doing a great, but you did a mistake on write a value on dict of _prepare_invoice_line. You have directly write a object instead of the field value. You have to use the field on vals by using the '.'. For example I have added a two field on sale order line as well as invoice line. 1.lot_id (many2one) 2.package_name (char).

So you have to pass this value on vals like this on _prepare_invoice_line method where the dict is generated as a vals for create the invoice line.

Suppose line_obj_browse is my browse object then

vals = { 'lot_id' : line_obj_browse.lot_id.id, 'package_name': line_obj_browse.package_name, }

I did it the same way

on 6/7/13, 8:44 AM
On 6/22/13, 6:41 PM

Can you please eplain me how you would extend the method "_prepare_inoive" with only one custom-field "example-field" ?

How should I modify the original method in my custom module?

Thanks René

About This Community

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


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 6/7/13, 3:46 AM
Seen: 4688 times
Last updated: 4/22/16, 5:51 AM