Technical archives des diffusions par email


sale order to invoice custom field

- 30/05/2017 09:43:02

I’m in the process of my first module which is roughly intended to customize invoices and sale orders with a new layout and a few customs fields.

I’ve added a custom 'First date' in the sale orders, and I would like it to be shown on my invoice form and report.

To create the field here is my file :
# -*- coding: utf-8 -*-

from odoo import models, fields, api
class AccountInvoiceInherited(models.Model):
	_inherit = 'account.invoice'
	moutiers_first_date = fields.Date(string='First visit')
	moutiers_start_date = fields.Date(string="Start Date")
	moutiers_end_date = fields.Date(string="End Date")
	sale_order_id = fields.Many2one('sale.order',string='orders')
	moutiers_first_date = fields.Date(related='sale_order_id.moutiers_first_date')

#Define new fields for sale orders
class SaleOrderInherited(models.Model):
	_inherit = 'sale.order'
	moutiers_intro = fields.Html(string='Intro text')
	moutiers_first_date = fields.Date(string='First visit')
	invoice_id = fields.One2many('account.invoice','sale_order_id',string='sale_id')

In my Views.xml I wrote :


First visit: Start date: End date:
_________________ So now, here is what is happening. When I create a sale order, I can enter a date for my First date field. When I ask to create an invoice, the date is not going from the sale order to the invoice. More, if in the invoice I want to enter a date in the First date field, it takes a date and it disappears as soon as I save the invoice. Digging in the database showed me that there’s no link between sale order and invoice, i.e. the sale_order_id field is Null in the invoice table. Last, I don’t see the reverse link invoice_id field in the sale_order table. I also tried to inherit the _prepare_invoice, but that was a mess. __________ def _prepare_invoice(self, cr, iud, order, lines, context=None): ret = super(SaleOrderInherited, self)._prepare_invoice(cr, uid, order, lines, context=context) if id: if order.moutiers_first_date: ret['moutiers_first_date'] = order.moutiers_first_date return ret ________________ I’m surely missing something. If anyone can point me where I’m wrong that would be nice. I’m new to Odoo, new to Python and even if I did some PHP I consider myself as a good code copy-paster but not a devel. Thanks for your help Regards V.