Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

2

Question about attachments stored to the Sale Order

By
Laurens
on 5/14/13, 2:32 PM 2,186 views

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"?

4

Brett Lehrer

--Brett Lehrer--
1252
| 5 4 8
Milwaukee, United States
--Brett Lehrer--
Director of IT and open source enthusiast.
Brett Lehrer
On 5/14/13, 3:17 PM

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.

https://code.launchpad.net/~brett-lehrer/+junk/attachment_nested_read

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.

Thanks for this, Brett! It's not working straight away in v7, but I'll see what I can change to make it work for me tomorrow morning. I'm sure I can learn a great deal from your code to aid me in what I'm trying to do. :)

Laurens
on 5/14/13, 8:25 PM

Note: To make this work in 7.0, just comment out the line containing "res['ids'] += extra_ids". I've updated the module to reflect that.

Brett Lehrer
on 5/29/13, 1:13 PM
2

Francesco OpenCode

--Francesco OpenCode--
3608
| 5 7 9
Grottaglie, Italy
--Francesco OpenCode--

Italian Odoo (OpenERP) Modules Developer LINKEDIN: http://www.linkedin.com/in/francescoapruzzese

Francesco OpenCode
On 5/14/13, 3:18 PM

If you want this you can create a module that follow this steps:

  1. Inherit sale order confirmation function
  2. When the order is confermed, get the invoice id
  3. Search in ir.attachment (attachments class) the document with res_model = 'sale.order' and res_id = confirmed order
  4. 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.

This was what my initial approach was, but there were two big problems: attachments added after the invoice is generated aren't pushed over, and this explodes the database/filesystem size with duplicates.

Brett Lehrer
on 5/14/13, 3:25 PM

Your Answer

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

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 5/14/13, 2:32 PM
Seen: 2186 times
Last updated: 3/16/15, 8:10 AM