Odoo Help


Question about attachments stored to the Sale Order

on 5/14/13, 2:32 PM 3,162 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"?


Brett Lehrer

--Brett Lehrer--

| 5 5 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.


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. :)

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

Francesco OpenCode

--Francesco OpenCode--

| 6 8 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

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


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