Is it possible to set up something to have an attachment stored to the Sales Order, accesible from the attachments from the generated invoice (from this SO)?
So if I were to add a PDF with delivery dates to the sales order; I would like to automatically have this attachment linked to the invoice once the invoice is created.
Alternatively, in case this isn't feasible - is there a way to force the name a file gets when stored? For instance if I add the attachment "Receipt.pdf" to SO010, can I force it to be saved as "ReceiptSO010.pdf"?
Yes, I wrote a module for this precise concept. FOREWARNING: This was written for 6.1 and has not been tested on 7.0. It also only modifies behavior in the web client, but that's also all we use.
Essentially you are inheriting the original attachment reading function and looking for a many2one 'sale_id' field within that model. If it's set, find all of the relevant attachments from that record and display them in the list of attachments along with everything from the invoice itself. This module was configured for our heavy manufacturing use, but could easily be adapted to search from other models.
I tried to be careful in adding this new function so that the extra overhead is as minimal as possible when not needed (it gets called a lot), but I'm sure it could be written better than it is.
If you want this you can create a module that follow this steps:
- Inherit sale order confirmation function
- When the order is confermed, get the invoice id
- Search in ir.attachment (attachments class) the document with res_model = 'sale.order' and res_id = confirmed order
- Duplicate this attachment record and change res_model to 'account.invoice' and res_id to new invoice id
In this way you have the some attachment in two different classes and records.
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
|Asked: 5/14/13, 2:32 PM|
|Seen: 2186 times|
|Last updated: 3/16/15, 8:10 AM|