Odoo Help


Transfer custom field value from Sale Order Line to Invoice Line

on 6/5/14, 9:55 AM 4,537 views

I've created a custom boolean field that appears in Sale Order lines and Invoice lines, and now I'm trying to transfer the values of the field to the Invoice when created from the Sale Order (wether the checkbox is marked or not...TRUE or FALSE), but for some reason my code is not working as expected, I'm not getting any error, but the values aren't being transfered from one module to the other either.

This is my code:


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

#Create fields in different models

class ti_print_choice_sale_order_line(osv.osv):

  _inherit = 'sale.order.line'
  _columns = {
    'x_printable_choice': fields.boolean(
      "Don't print",
      help='Mark if this product will NOT be printed in reports'

class ti_print_choice_account_invoice_line(osv.osv):

  _inherit = "account.invoice.line"
  _columns = {
    'x_printable_choice': fields.boolean(
      "Don't print",
      help='Mark if this product will NOT be printed in reports'

#Copy fields between modules: From Sale Order to Invoice

class sale_order(orm.Model):
    _inherit = 'sale.order'

    def _prepare_order_line_invoice_line(self, cr, uid, line, account_id=False, context=None):

        res = super(sale_order, self)._prepare_invoice(
            cr, uid, line, account_id=False, context=context
            'x_printable_choice': line.x_printable_choice,
        return res


I will be doing the same for Purchase Orders and Stock Moves...but for the sake of simplicity I've excluded it from this question

Any help or insight is appreciated 


On 6/5/14, 12:38 PM

The _prepare_invoice() method only returns a dictionary of the invoice values.  You will need to call the _make_invoice() method to create the invoice record.  Once the record is created, then you can update the boolean field on the invoice with the value set on the sales order

On 6/17/14, 5:59 AM

thanks for you reply Eric. But I'm a bit lost in figuring out how to accomplish your suggestion. If you have some spare time, can you provide me some specific details?

This is the _make_invoice() method in sale.py:


    def _make_invoice(self, cr, uid, order, lines, context=None):
        inv_obj = self.pool.get('account.invoice')
        obj_invoice_line = self.pool.get('account.invoice.line')
        if context is None:
            context = {}
        invoiced_sale_line_ids = self.pool.get('sale.order.line').search(cr, uid, [('order_id', '=', order.id), ('invoiced', '=', True)], context=context)
        from_line_invoice_ids = []
        for invoiced_sale_line_id in self.pool.get('sale.order.line').browse(cr, uid, invoiced_sale_line_ids, context=context):
            for invoice_line_id in invoiced_sale_line_id.invoice_lines:
                if invoice_li d.invoice_id.id not in from_line_invoice_ids:
        for preinv in order.invoice_ids:
            if preinv.state not in ('cancel',) and preinv.id not in from_line_invoice_ids:
                for preline in preinv.invoice_line:
                    inv_line_id = obj_invoice_line.copy(cr, uid, preline.id, {'invoice_id': False, 'price_unit': -preline.price_unit})
        inv = self._prepare_invoice(cr, uid, order, lines, context=context)
        inv_id = inv_obj.create(cr, uid, inv, context=context)
        data = inv_obj.onchange_payment_term_date_invoice(cr, uid, [inv_id], inv['payment_term'], time.strftime(DEFAULT_SERVER_DATE_FORMAT))
        if data.get('value', False):
            inv_obj.write(cr, uid, [inv_id], data['value'], context=context)
        inv_obj.button_compute(cr, uid, [inv_id])
        return inv_id



Anybody has resolved this?

on 11/20/14, 12:34 PM

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

2 follower(s)


Asked: 6/5/14, 9:55 AM
Seen: 4537 times
Last updated: 8/27/16, 4:11 AM