Skip to Content
Menu
This question has been flagged
2 Replies
2460 Views

Hi there,

i try to get a relation between account_invoice and sales_order to show a custom field of sales_order in my invoice report. Therefore i inherit account.invoice with a sales_order_id field.

# -*- coding: utf-8 -*-
from odoo import models, fields, api
class account_invoice(models.Model):
    _inherit = "account.invoice" sale_order_id = fields.Many2one('sale.order', string='Related Order') 

I want to access the value of the custom field ( e.g. tm_short_description ) in the invoice report ( o.sale_order_id.tm_short_description )
The problem is, creating a new invoice, the account_invoice.sales_order_id will not be filled. Updating it manually the report is ok. Do i have to override some default original function to get the sales_order_id to account.invoice ?

Thanks for your help,

Franz

Avatar
Discard
Best Answer

You should not create new field in  the invoice, based on invoice line we can  get sale order id.

Example :

order=invoice.invoice_line_ids.mapped('sale_line_ids').mapped('order_id')

This may help you.

Avatar
Discard
Author Best Answer

Sorry,

I didn't understand the way you show to me. Where do I have to place such code to get the sale_order field in my invoice report ? Do you have a link for me to read more about this way ?

Kind regards,

Franz

Problem has been solved. I added t-field="l.invoice_line_ids.sale_line_ids.order_id.tm_short_description" to the report and this will show me the field from sale_order in my invoice report.
Thank you so much !

Avatar
Discard