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,
}