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

import new field values from sale_order to invoice

By
wizardz
on 12/7/15, 4:40 AM 284 views

Hello, 

I have a new field in sale_order named: myfield

Now when I create a invoice from the sale_order , the myfield value is empty in invoice.

How can I move the value from my new field to invoice, when it creates a new invoice from the sale_order.


I tried something like this:


I see that the _prepare_invoice function is used to put values from sale_order to invoice.

Now when I make something like this it's not working.

I have the same field in invoice like "myfield" in sale_order:

def _prepare_invoice(self, cr, uid, order, lines, context=None):
"""Prepare the dict of values to create the new invoice for a
sales order. This method may be overridden to implement custom
invoice generation (making sure to call super() to establish
a clean extension chain).

:param browse_record order: sale.order record to invoice
:param list(int) line: list of invoice line IDs that must be
attached to the invoice
:return: dict of value to create() the invoice
"""
if context is None:
context = {}
journal_ids = self.pool.get('account.journal').search(cr, uid,
[('type', '=', 'sale'), ('company_id', '=', order.company_id.id)],
limit=1)
if not journal_ids:
raise osv.except_osv(_('Error!'),
_('Please define sales journal for this company: "%s" (id:%d).') % (order.company_id.name, order.company_id.id))
invoice_vals = {
'myfield': order.myfield,

}

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: 12/7/15, 4:40 AM
Seen: 284 times
Last updated: 12/7/15, 9:37 AM