show customer order reference and order date on invoice

Asked by Akshay Jain

In a sale order there are fields called 'Customer Ref' and 'Order Date'. Now when invoice is generated for a sale order then i need to have these fields of sale order in invoice also so that 'Customer Ref' and 'Order date' can be printed on invoice.

Question information

Language:
English Edit question
Status:
Solved
For:
Odoo Addons (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Solved by:
Akshay Jain
Solved:
Last query:
Last reply:
Revision history for this message
gpa(OpenERP) (gpa-openerp) said :
#1

Hello Akshay,

When you will create sale order and create invoice for the particular sale order, the field with the name 'Customer Ref' is passed in the field of the invoice with the name 'Description'.

But I do not understand why you need sale order date in invoice object because it is not necessary that when the sale order is created in similar date you have created invoice so if you want to use the sale order date you needed to change the invoice report and create one method in report py file which return the related sale order date.

Thanks.

Revision history for this message
Akshay Jain (akshay-jain-7983) said :
#2

I was looking at sale.py file in sale module and i found that there is a field 'invoice_ids' in sale.order class. this field is many2many, which means there is a many2many relationship between sale.order and account.invoice but this relation is referred only from sale.order. How can i refer this relation from account.invoice? Moreover it does make sense to have one invoice for many sale orders, for eg, there may be a contract where customer may place 10 sale orders in 3 months and a composite invoice is to be raised every three months. So in this situation the account.invoice should also have a many2many relationship with sale.order and when this relationship already exists then it just needs to be referred from invoice side. Tell me how to do it?
I tried by putting this in account.invoice class:
 'saleorder_ids': fields.many2many('sale.order', 'sale_order_invoice_rel', 'invoice_id', 'order_id', 'Sale Orders'),
but i get an error saying "Relation 'sale_order' does not exists"
Can you help please?

Revision history for this message
Vinay Rana (OpenERP) (vra-openerp) said :
#3

Hello Akshay Jain,

You cannot assign relation like that because there is already a relation exist in sale.order to account.invoice, you can easily take the sale order reference from account invoice with out adding any field in account.invoice , See in account.invoice object if it is related to particular sale.order then the sale.order reference is passes in Description field of account.invoice so on the bases of that you will easily get the sale.order id like following way:

'invoice' is browse object of account.invoice=>
ids = self.pool.get('sale.order').search(cr, uid, [('name','=',invoice.name)],context)
so in ids you can easily get the sale order id and with the help of browse or read method you can take any field of sale,order object data.

Hope This is enough for you to understand what i wanted to explain you.

Thanks.

Revision history for this message
Akshay Jain (akshay-jain-7983) said :
#4

My point is that when there is an existing relationship between sale.order and account.invoice and it is populated by sale.order then why can we not VIEW that relationship on account.invoice side.

I did this and was successful: in sale.py file append the below code

class account_invoice(osv.osv):
    _inherit = "account.invoice"
    _columns = {
        'saleorder_ids': fields.many2many('sale.order', 'sale_order_invoice_rel', 'invoice_id', 'order_id', 'Sale Order'),
    }
account_invoice()

This adds a new field to account.invoice that has many2many with sale.order and relationship name is same as that defined in sale.order so that both fields in both classes use same intermediate table for many2many.

Revision history for this message
Vinay Rana (OpenERP) (vra-openerp) said :
#5

Hello Akshay Jain,

This is your side requirement so you can change your code as you like. This is not available in tiny and If you want to provide this suggestion for some improvement so create blueprints so if it will functionally correct then it will be implemented in our code.So This is not a big issue.

Thanks for your suggestion.

Revision history for this message
Akshay Jain (akshay-jain-7983) said :
#6

I will work on blueprints for this.