[FIX] Empty all current line(s) when you change template. Before, the display do...
[odoo/odoo.git] / addons / mail / ir_attachment.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2014-TODAY OpenERP SA (http://www.openerp.com)
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 ##############################################################################
21
22 from openerp.osv import fields, osv
23
24 import os.path
25
26
27 class IrAttachment(osv.Model):
28     """ Update partner to add a field about notification preferences """
29     _name = "ir.attachment"
30     _inherit = 'ir.attachment'
31
32     _fileext_to_type = {
33         '7z': 'archive',
34         'aac': 'audio',
35         'ace': 'archive',
36         'ai': 'vector',
37         'aiff': 'audio',
38         'apk': 'archive',
39         'app': 'binary',
40         'as': 'script',
41         'asf': 'video',
42         'ass': 'text',
43         'avi': 'video',
44         'bat': 'script',
45         'bin': 'binary',
46         'bmp': 'image',
47         'bzip2': 'archive',
48         'c': 'script',
49         'cab': 'archive',
50         'cc': 'script',
51         'ccd': 'disk',
52         'cdi': 'disk',
53         'cdr': 'vector',
54         'cer': 'certificate',
55         'cgm': 'vector',
56         'cmd': 'script',
57         'coffee': 'script',
58         'com': 'binary',
59         'cpp': 'script',
60         'crl': 'certificate',
61         'crt': 'certificate',
62         'cs': 'script',
63         'csr': 'certificate',
64         'css': 'html',
65         'csv': 'spreadsheet',
66         'cue': 'disk',
67         'd': 'script',
68         'dds': 'image',
69         'deb': 'archive',
70         'der': 'certificate',
71         'djvu': 'image',
72         'dmg': 'archive',
73         'dng': 'image',
74         'doc': 'document',
75         'docx': 'document',
76         'dvi': 'print',
77         'eot': 'font',
78         'eps': 'vector',
79         'exe': 'binary',
80         'exr': 'image',
81         'flac': 'audio',
82         'flv': 'video',
83         'gif': 'webimage',
84         'gz': 'archive',
85         'gzip': 'archive',
86         'h': 'script',
87         'htm': 'html',
88         'html': 'html',
89         'ico': 'image',
90         'icon': 'image',
91         'img': 'disk',
92         'iso': 'disk',
93         'jar': 'archive',
94         'java': 'script',
95         'jp2': 'image',
96         'jpe': 'webimage',
97         'jpeg': 'webimage',
98         'jpg': 'webimage',
99         'jpx': 'image',
100         'js': 'script',
101         'key': 'presentation',
102         'keynote': 'presentation',
103         'lisp': 'script',
104         'lz': 'archive',
105         'lzip': 'archive',
106         'm': 'script',
107         'm4a': 'audio',
108         'm4v': 'video',
109         'mds': 'disk',
110         'mdx': 'disk',
111         'mid': 'audio',
112         'midi': 'audio',
113         'mkv': 'video',
114         'mng': 'image',
115         'mp2': 'audio',
116         'mp3': 'audio',
117         'mp4': 'video',
118         'mpe': 'video',
119         'mpeg': 'video',
120         'mpg': 'video',
121         'nrg': 'disk',
122         'numbers': 'spreadsheet',
123         'odg': 'vector',
124         'odm': 'document',
125         'odp': 'presentation',
126         'ods': 'spreadsheet',
127         'odt': 'document',
128         'ogg': 'audio',
129         'ogm': 'video',
130         'otf': 'font',
131         'p12': 'certificate',
132         'pak': 'archive',
133         'pbm': 'image',
134         'pdf': 'print',
135         'pem': 'certificate',
136         'pfx': 'certificate',
137         'pgf': 'image',
138         'pgm': 'image',
139         'pk3': 'archive',
140         'pk4': 'archive',
141         'pl': 'script',
142         'png': 'webimage',
143         'pnm': 'image',
144         'ppm': 'image',
145         'pps': 'presentation',
146         'ppt': 'presentation',
147         'ps': 'print',
148         'psd': 'image',
149         'psp': 'image',
150         'py': 'script',
151         'r': 'script',
152         'ra': 'audio',
153         'rar': 'archive',
154         'rb': 'script',
155         'rpm': 'archive',
156         'rtf': 'text',
157         'sh': 'script',
158         'sub': 'disk',
159         'svg': 'vector',
160         'sxc': 'spreadsheet',
161         'sxd': 'vector',
162         'tar': 'archive',
163         'tga': 'image',
164         'tif': 'image',
165         'tiff': 'image',
166         'ttf': 'font',
167         'txt': 'text',
168         'vbs': 'script',
169         'vc': 'spreadsheet',
170         'vml': 'vector',
171         'wav': 'audio',
172         'webp': 'image',
173         'wma': 'audio',
174         'wmv': 'video',
175         'woff': 'font',
176         'xar': 'vector',
177         'xbm': 'image',
178         'xcf': 'image',
179         'xhtml': 'html',
180         'xls': 'spreadsheet',
181         'xlsx': 'spreadsheet',
182         'xml': 'html',
183         'zip': 'archive'
184     }
185
186     def get_attachment_type(self, cr, uid, ids, name, args, context=None):
187         result = {}
188         for attachment in self.browse(cr, uid, ids, context=context):
189             fileext = os.path.splitext(attachment.datas_fname or '')[1].lower()[1:]
190             result[attachment.id] = self._fileext_to_type.get(fileext, 'unknown')
191         return result
192
193     _columns = {
194         'file_type_icon': fields.function(get_attachment_type, type='char', string='File Type Icon'),
195         'file_type': fields.related('file_type_icon', type='char'),     # FIXME remove in trunk
196     }