Odoo Help


Where in account module do fields get copied over? [From SO --> Invoice]

on 6/12/13, 1:21 PM 1,639 views

In what file, and where, can I find where fields get copied over from the Sale Order to the invoice? For instance client_order_ref --> name and payment_term.

I want to copy my custom field value over to another custom field I have under the invoices. But I can not find where I have to inherit.

Can someone show me where this happens?

Ray Carnes
On 6/12/13, 1:54 PM

It isn't the account module, it is the sale module.

sale.order has a _make_invoice method that uses the order lines to create an Invoice.

The python for adding the new field to the invoice (assuming both custom fields already exist on sale.order and account.invoice) might look something like this:

from openerp.osv import fields,osv
from tools.translate import _

class sale_order(osv.osv):
    _inherit = 'sale.order'

def _make_invoice(self, cr, uid, order, lines, context=None):
    inv_id = super(sale_order, self)._make_invoice(cr, uid, order, lines, context)
    inv_obj = self.pool.get('account.invoice')
    if order.name_of_custom_order_field:
        inv_obj.write(cr, uid, [inv_id], {'name_of_custom_invoice_field': order.name_of_custom_order_field.id}, context=context)
    return inv_id

(I copied this from an example so I haven't actually tested the code).

The original function above you are overriding is in addons\sale\sale.py

Thanks Ray, I had found it already; guess I was just braindead for a moment. Obviously the function is called in the sale model. Already made my module, and it's up and running. However your instruction was spot on, great feedback man.

on 6/14/13, 9:19 AM

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/12/13, 1:21 PM
Seen: 1639 times
Last updated: 3/16/15, 8:10 AM