Merge lp:~therp-nl/therp-addons/7.0-fetchmail_inbox into lp:~therp-nl/therp-addons/7.0
- 7.0-fetchmail_inbox
- Merge into 7.0
Proposed by
Holger Brunn (Therp)
Status: | Merged |
---|---|
Merged at revision: | 96 |
Proposed branch: | lp:~therp-nl/therp-addons/7.0-fetchmail_inbox |
Merge into: | lp:~therp-nl/therp-addons/7.0 |
Diff against target: |
954 lines (+814/-0) 24 files modified
fetchmail_inbox/__init__.py (+22/-0) fetchmail_inbox/__openerp__.py (+81/-0) fetchmail_inbox/model/__init__.py (+22/-0) fetchmail_inbox/model/fetchmail_inbox.py (+30/-0) fetchmail_inbox/model/mail_message.py (+127/-0) fetchmail_inbox/security/ir.model.access.csv (+2/-0) fetchmail_inbox/security/res_groups.xml (+8/-0) fetchmail_inbox/view/mail_message.xml (+33/-0) fetchmail_inbox/view/menu.xml (+21/-0) fetchmail_inbox/wizard/__init__.py (+22/-0) fetchmail_inbox/wizard/fetchmail_inbox_attach_existing_wizard.py (+84/-0) fetchmail_inbox/wizard/fetchmail_inbox_attach_existing_wizard.xml (+23/-0) fetchmail_inbox/wizard/fetchmail_inbox_create_wizard.py (+54/-0) fetchmail_inbox/wizard/fetchmail_inbox_create_wizard.xml (+21/-0) fetchmail_inbox_invoice/__init__.py (+22/-0) fetchmail_inbox_invoice/__openerp__.py (+60/-0) fetchmail_inbox_invoice/model/__init__.py (+22/-0) fetchmail_inbox_invoice/model/fetchmail_inbox_invoice.py (+28/-0) fetchmail_inbox_invoice/model/mail_message.py (+32/-0) fetchmail_inbox_invoice/security/ir.model.access.csv (+2/-0) fetchmail_inbox_invoice/view/mail_message.xml (+17/-0) fetchmail_inbox_invoice/view/menu.xml (+18/-0) fetchmail_inbox_invoice/wizard/__init__.py (+21/-0) fetchmail_inbox_invoice/wizard/fetchmail_inbox_attach_existing_wizard.py (+42/-0) |
To merge this branch: | bzr merge lp:~therp-nl/therp-addons/7.0-fetchmail_inbox |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Stefan Rijnhart (Opener) (community) | Needs Information | ||
Review via email:
|
Commit message
[ADD] fetchmail_inbox, fetchmail_
Description of the change
A base module to put incoming mails into an inbox for further (manual) processing.
Also a small usability module to do that specifically for invoices.
To post a comment you must log in.
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Stefan Rijnhart (Opener) (stefan-opener) wrote : | # |
review:
Needs Information
- 104. By Holger Brunn (Therp)
-
[FIX] get pool model from mail.message's model to have more fine grained
control over permissions on different fetchmail.inbox.* models
[ADD] set default search filter to mail author's commercial partner for
invoices
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Holger Brunn (Therp) (hbrunn) wrote : | # |
Thanks for your input Stefan, appreciated and implemented!
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Stefan Rijnhart (Opener) (stefan-opener) wrote : | # |
Great work, thanks. I posted my remaining nits as a proposal on this branch. https:/
- 105. By Stefan Rijnhart (Opener)
-
[RFR] Customize for use by accountants
[IMP] Filter on incoming invoices
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Holger Brunn (Therp) (hbrunn) wrote : | # |
They're merged now
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added directory 'fetchmail_inbox' |
2 | === added file 'fetchmail_inbox/__init__.py' |
3 | --- fetchmail_inbox/__init__.py 1970-01-01 00:00:00 +0000 |
4 | +++ fetchmail_inbox/__init__.py 2014-01-15 09:28:30 +0000 |
5 | @@ -0,0 +1,22 @@ |
6 | +# -*- coding: utf-8 -*- |
7 | +############################################################################## |
8 | +# |
9 | +# OpenERP, Open Source Management Solution |
10 | +# This module copyright (C) 2014 Therp BV (<http://therp.nl>). |
11 | +# |
12 | +# This program is free software: you can redistribute it and/or modify |
13 | +# it under the terms of the GNU Affero General Public License as |
14 | +# published by the Free Software Foundation, either version 3 of the |
15 | +# License, or (at your option) any later version. |
16 | +# |
17 | +# This program is distributed in the hope that it will be useful, |
18 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20 | +# GNU Affero General Public License for more details. |
21 | +# |
22 | +# You should have received a copy of the GNU Affero General Public License |
23 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
24 | +# |
25 | +############################################################################## |
26 | +import model |
27 | +import wizard |
28 | |
29 | === added file 'fetchmail_inbox/__openerp__.py' |
30 | --- fetchmail_inbox/__openerp__.py 1970-01-01 00:00:00 +0000 |
31 | +++ fetchmail_inbox/__openerp__.py 2014-01-15 09:28:30 +0000 |
32 | @@ -0,0 +1,81 @@ |
33 | +# -*- coding: utf-8 -*- |
34 | +############################################################################## |
35 | +# |
36 | +# OpenERP, Open Source Management Solution |
37 | +# This module copyright (C) 2014 Therp BV (<http://therp.nl>). |
38 | +# |
39 | +# This program is free software: you can redistribute it and/or modify |
40 | +# it under the terms of the GNU Affero General Public License as |
41 | +# published by the Free Software Foundation, either version 3 of the |
42 | +# License, or (at your option) any later version. |
43 | +# |
44 | +# This program is distributed in the hope that it will be useful, |
45 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
46 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
47 | +# GNU Affero General Public License for more details. |
48 | +# |
49 | +# You should have received a copy of the GNU Affero General Public License |
50 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
51 | +# |
52 | +############################################################################## |
53 | +{ |
54 | + "name" : "Fetch mail into inbox", |
55 | + "version" : "1.0", |
56 | + "author" : "Therp BV", |
57 | + "complexity": "normal", |
58 | + "description": """ |
59 | +In some cases, you may not want to have OpenERP create objects directly |
60 | +on mail arrival, but put them into an inbox for further (possibly manual) |
61 | +processing. |
62 | + |
63 | +This module provides the base for this workflow and elementary UI for |
64 | +processing. |
65 | + |
66 | +Usage |
67 | +----- |
68 | + |
69 | +Create a fetchmail configuration and use 'Fetchmail inbox' as object to be |
70 | +created on mail arrival. Be sure to check Advanced/Keep original in order |
71 | +not to lose data in the intermediate step via the inbox. |
72 | + |
73 | +Mails fetched from this configuration end up in Email/Fetchmail Inbox, |
74 | +where they can be reviewed and eventually used to create new objects or |
75 | +attached to existing objects. |
76 | + |
77 | +Further development |
78 | +------------------- |
79 | + |
80 | +This module deals with emails in a very generic way, which is good for |
81 | +flexibility, but bad for usability. Fortunately, it was developed with |
82 | +extensibility in mind so that it is very simple to write extension modules |
83 | +to ease handling emails for specific models in a more user friendly manner. |
84 | + |
85 | +In simple cases, if you want to force specifying objects of just one model, |
86 | +you can put 'default_res_model': 'your.model' into the menu action's |
87 | +context and you're done. |
88 | + """, |
89 | + "category" : "Dependency", |
90 | + "depends" : [ |
91 | + 'mail', |
92 | + 'fetchmail', |
93 | + ], |
94 | + "data" : [ |
95 | + "security/res_groups.xml", |
96 | + "wizard/fetchmail_inbox_create_wizard.xml", |
97 | + "wizard/fetchmail_inbox_attach_existing_wizard.xml", |
98 | + "view/mail_message.xml", |
99 | + "view/menu.xml", |
100 | + 'security/ir.model.access.csv', |
101 | + ], |
102 | + "js": [ |
103 | + ], |
104 | + "css": [ |
105 | + ], |
106 | + "qweb": [ |
107 | + ], |
108 | + "auto_install": False, |
109 | + "installable": True, |
110 | + "external_dependencies" : { |
111 | + 'python' : [], |
112 | + }, |
113 | +} |
114 | |
115 | === added directory 'fetchmail_inbox/data' |
116 | === added directory 'fetchmail_inbox/model' |
117 | === added file 'fetchmail_inbox/model/__init__.py' |
118 | --- fetchmail_inbox/model/__init__.py 1970-01-01 00:00:00 +0000 |
119 | +++ fetchmail_inbox/model/__init__.py 2014-01-15 09:28:30 +0000 |
120 | @@ -0,0 +1,22 @@ |
121 | +# -*- coding: utf-8 -*- |
122 | +############################################################################## |
123 | +# |
124 | +# OpenERP, Open Source Management Solution |
125 | +# This module copyright (C) 2014 Therp BV (<http://therp.nl>). |
126 | +# |
127 | +# This program is free software: you can redistribute it and/or modify |
128 | +# it under the terms of the GNU Affero General Public License as |
129 | +# published by the Free Software Foundation, either version 3 of the |
130 | +# License, or (at your option) any later version. |
131 | +# |
132 | +# This program is distributed in the hope that it will be useful, |
133 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
134 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
135 | +# GNU Affero General Public License for more details. |
136 | +# |
137 | +# You should have received a copy of the GNU Affero General Public License |
138 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
139 | +# |
140 | +############################################################################## |
141 | +import fetchmail_inbox |
142 | +import mail_message |
143 | |
144 | === added file 'fetchmail_inbox/model/fetchmail_inbox.py' |
145 | --- fetchmail_inbox/model/fetchmail_inbox.py 1970-01-01 00:00:00 +0000 |
146 | +++ fetchmail_inbox/model/fetchmail_inbox.py 2014-01-15 09:28:30 +0000 |
147 | @@ -0,0 +1,30 @@ |
148 | +# -*- coding: utf-8 -*- |
149 | +############################################################################## |
150 | +# |
151 | +# OpenERP, Open Source Management Solution |
152 | +# This module copyright (C) 2014 Therp BV (<http://therp.nl>). |
153 | +# |
154 | +# This program is free software: you can redistribute it and/or modify |
155 | +# it under the terms of the GNU Affero General Public License as |
156 | +# published by the Free Software Foundation, either version 3 of the |
157 | +# License, or (at your option) any later version. |
158 | +# |
159 | +# This program is distributed in the hope that it will be useful, |
160 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
161 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
162 | +# GNU Affero General Public License for more details. |
163 | +# |
164 | +# You should have received a copy of the GNU Affero General Public License |
165 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
166 | +# |
167 | +############################################################################## |
168 | +from openerp.osv.orm import Model |
169 | +from openerp.osv import fields |
170 | + |
171 | +class FetchmailInbox(Model): |
172 | + _inherit = 'mail.thread' |
173 | + _name = 'fetchmail.inbox' |
174 | + _description= 'Fetchmail inbox' |
175 | + |
176 | + _columns = { |
177 | + } |
178 | |
179 | === added file 'fetchmail_inbox/model/mail_message.py' |
180 | --- fetchmail_inbox/model/mail_message.py 1970-01-01 00:00:00 +0000 |
181 | +++ fetchmail_inbox/model/mail_message.py 2014-01-15 09:28:30 +0000 |
182 | @@ -0,0 +1,127 @@ |
183 | +# -*- coding: utf-8 -*- |
184 | +############################################################################## |
185 | +# |
186 | +# OpenERP, Open Source Management Solution |
187 | +# This module copyright (C) 2014 Therp BV (<http://therp.nl>). |
188 | +# |
189 | +# This program is free software: you can redistribute it and/or modify |
190 | +# it under the terms of the GNU Affero General Public License as |
191 | +# published by the Free Software Foundation, either version 3 of the |
192 | +# License, or (at your option) any later version. |
193 | +# |
194 | +# This program is distributed in the hope that it will be useful, |
195 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
196 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
197 | +# GNU Affero General Public License for more details. |
198 | +# |
199 | +# You should have received a copy of the GNU Affero General Public License |
200 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
201 | +# |
202 | +############################################################################## |
203 | +import base64 |
204 | +from openerp.osv.orm import Model, browse_record |
205 | +from openerp.osv import fields |
206 | + |
207 | +class MailMessage(Model): |
208 | + _inherit = 'mail.message' |
209 | + |
210 | + def fetchmail_inbox_attach_existing(self, cr, uid, ids, context=None): |
211 | + return { |
212 | + 'type': 'ir.actions.act_window', |
213 | + 'view_mode': 'form', |
214 | + 'target': 'new', |
215 | + 'res_model': 'fetchmail.inbox.attach.existing.wizard', |
216 | + 'context': { |
217 | + 'default_mail_id': ids and ids[0], |
218 | + }, |
219 | + } |
220 | + |
221 | + def fetchmail_inbox_create(self, cr, uid, ids, context=None): |
222 | + if context and context.get('default_res_model'): |
223 | + model_id = self.pool.get('ir.model').search( |
224 | + cr, uid, [('model', '=', context['default_res_model'])], |
225 | + context=None) |
226 | + model_id = model_id and model_id[0] |
227 | + wizard_model = self.pool.get('fetchmail.inbox.create.wizard') |
228 | + return wizard_model.button_create( |
229 | + cr, uid, |
230 | + [wizard_model.create( |
231 | + cr, uid, |
232 | + { |
233 | + 'model_id': model_id, |
234 | + 'mail_id': ids and ids[0], |
235 | + }, |
236 | + context=context)], |
237 | + context=context) |
238 | + |
239 | + return { |
240 | + 'type': 'ir.actions.act_window', |
241 | + 'view_mode': 'form', |
242 | + 'target': 'new', |
243 | + 'res_model': 'fetchmail.inbox.create.wizard', |
244 | + 'context': { |
245 | + 'default_mail_id': ids and ids[0], |
246 | + }, |
247 | + } |
248 | + |
249 | + def fetchmail_inbox_to_msg_dict(self, cr, uid, ids, context=None): |
250 | + ''' |
251 | + return a dict to be consumed by mail_thread.message_{new,update} |
252 | + ideally, the original mail is attached, otherwise, try toyield a |
253 | + similar result to mail_thread.message_parse() |
254 | + ''' |
255 | + result = {} |
256 | + |
257 | + for this in self.browse(cr, uid, ids, context=None): |
258 | + msg = {'attachments': []} |
259 | + for attachment in this.attachment_ids: |
260 | + name_data = (attachment.datas_fname, |
261 | + base64.b64decode(attachment.datas)) |
262 | + #reparse original message if available |
263 | + if name_data[0] == 'original_email.eml': |
264 | + return self.pool.get('mail.thread').message_parse( |
265 | + cr, uid, name_data[1], |
266 | + save_original=False, context=context) |
267 | + msg['attachments'].append(name_data) |
268 | + for field in ['type', 'author_id', 'message_id', 'subject', |
269 | + 'email_from', 'date', 'parent_id', 'body']: |
270 | + if isinstance(this[field], browse_record): |
271 | + msg[field] = this[field].id |
272 | + else: |
273 | + msg[field] = this[field] or '' |
274 | + msg['from'] = this.author_id.email or '' |
275 | + msg['to'] = ','.join([p.email for p in this.partner_ids]) |
276 | + msg['partner_ids'] = [(4, p.id) for p in this.partner_ids] |
277 | + result[this.id] = msg |
278 | + |
279 | + return result if len(ids) > 1 else result[ids[0]] |
280 | + |
281 | + def fetchmail_inbox_move_to_record(self, cr, uid, ids, res_model, res_id, |
282 | + context=None): |
283 | + '''move message to object given by res_model and res_id''' |
284 | + for this in self.browse(cr, uid, ids, context=context): |
285 | + inbox_model = self.pool.get(this.model) |
286 | + inbox_ids = inbox_model.search( |
287 | + cr, uid, [('message_ids', 'in', ids)], context=context) |
288 | + this.write({ |
289 | + 'model': res_model, |
290 | + 'res_id': res_id, |
291 | + }) |
292 | + inbox_model.unlink(cr, uid, inbox_ids, context=context) |
293 | + |
294 | + for attachment in this.attachment_ids: |
295 | + if context.get('fetchmail_invoice_delete_original', True) and\ |
296 | + attachment.datas_fname == 'original_email.eml': |
297 | + attachment.unlink() |
298 | + continue |
299 | + if context.get('fetchmail_invoice_move_attachments', True): |
300 | + attachment.write({ |
301 | + 'res_model': res_model, |
302 | + 'res_id': res_id, |
303 | + }) |
304 | + |
305 | + def _needaction_count(self, cr, uid, dom, context=None): |
306 | + if dom == [('model', '=', 'fetchmail.inbox')]: |
307 | + return len(self.search(cr, uid, dom, context=context)) |
308 | + return super(MailMessage, self)._needaction_count( |
309 | + cr, uid, dom, context=context) |
310 | |
311 | === added directory 'fetchmail_inbox/security' |
312 | === added file 'fetchmail_inbox/security/ir.model.access.csv' |
313 | --- fetchmail_inbox/security/ir.model.access.csv 1970-01-01 00:00:00 +0000 |
314 | +++ fetchmail_inbox/security/ir.model.access.csv 2014-01-15 09:28:30 +0000 |
315 | @@ -0,0 +1,2 @@ |
316 | +"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" |
317 | +crud_fetchmail_inbox,CRUD fetchmail inbox,model_fetchmail_inbox,group_fetchmail_inbox_manager,1,1,1,1 |
318 | |
319 | === added file 'fetchmail_inbox/security/res_groups.xml' |
320 | --- fetchmail_inbox/security/res_groups.xml 1970-01-01 00:00:00 +0000 |
321 | +++ fetchmail_inbox/security/res_groups.xml 2014-01-15 09:28:30 +0000 |
322 | @@ -0,0 +1,8 @@ |
323 | +<?xml version="1.0" encoding="UTF-8"?> |
324 | +<openerp> |
325 | + <data> |
326 | + <record id="group_fetchmail_inbox_manager" model="res.groups"> |
327 | + <field name="name">Fetchmail Inbox Manager</field> |
328 | + </record> |
329 | + </data> |
330 | +</openerp> |
331 | |
332 | === added directory 'fetchmail_inbox/static' |
333 | === added directory 'fetchmail_inbox/static/src' |
334 | === added directory 'fetchmail_inbox/static/src/img' |
335 | === added file 'fetchmail_inbox/static/src/img/icon.png' |
336 | Binary files fetchmail_inbox/static/src/img/icon.png 1970-01-01 00:00:00 +0000 and fetchmail_inbox/static/src/img/icon.png 2014-01-15 09:28:30 +0000 differ |
337 | === added directory 'fetchmail_inbox/view' |
338 | === added file 'fetchmail_inbox/view/mail_message.xml' |
339 | --- fetchmail_inbox/view/mail_message.xml 1970-01-01 00:00:00 +0000 |
340 | +++ fetchmail_inbox/view/mail_message.xml 2014-01-15 09:28:30 +0000 |
341 | @@ -0,0 +1,33 @@ |
342 | +<?xml version="1.0" encoding="UTF-8"?> |
343 | +<openerp> |
344 | + <data> |
345 | + <record id="view_message_form" model="ir.ui.view"> |
346 | + <field name="model">mail.message</field> |
347 | + <field name="inherit_id" ref="mail.view_message_form"/> |
348 | + <field name="arch" type="xml"> |
349 | + <sheet position="before"> |
350 | + <header attrs="{'invisible': [('model', '!=', 'fetchmail.inbox')]}"> |
351 | + <button string="Attach to existing object" type="object" name="fetchmail_inbox_attach_existing" class="oe_highlight" /> |
352 | + <button string="Create object" type="object" name="fetchmail_inbox_create" /> |
353 | + </header> |
354 | + </sheet> |
355 | + <xpath expr="//sheet/group" position="after"> |
356 | + <group attrs="{'invisible': [('attachment_ids', '=', [[6, False, []]])]}" string="Attachments"> |
357 | + <field name="attachment_ids" nolabel="1" /> |
358 | + </group> |
359 | + </xpath> |
360 | + </field> |
361 | + </record> |
362 | + <record id="tree_mail_message_fetchmail_inbox" model="ir.ui.view"> |
363 | + <field name="model">mail.message</field> |
364 | + <field name="type">tree</field> |
365 | + <field name="arch" type="xml"> |
366 | + <tree string="Fetchmail inbox" create="false"> |
367 | + <field name="date" /> |
368 | + <field name="subject" /> |
369 | + <field name="email_from" /> |
370 | + </tree> |
371 | + </field> |
372 | + </record> |
373 | + </data> |
374 | +</openerp> |
375 | |
376 | === added file 'fetchmail_inbox/view/menu.xml' |
377 | --- fetchmail_inbox/view/menu.xml 1970-01-01 00:00:00 +0000 |
378 | +++ fetchmail_inbox/view/menu.xml 2014-01-15 09:28:30 +0000 |
379 | @@ -0,0 +1,21 @@ |
380 | +<?xml version="1.0" encoding="UTF-8"?> |
381 | +<openerp> |
382 | + <data> |
383 | + <act_window id="action_inbox" |
384 | + res_model="mail.message" |
385 | + view_mode="tree,form" |
386 | + domain="[('model', '=', 'fetchmail.inbox')]" |
387 | + name="Fetchmail inbox" |
388 | + view_id="tree_mail_message_fetchmail_inbox" |
389 | + /> |
390 | + <menuitem id="menu_inbox" |
391 | + action="action_inbox" |
392 | + parent="base.menu_email" |
393 | + /> |
394 | + <menuitem id="menu_inbox_mail_feeds" |
395 | + action="action_inbox" |
396 | + parent="mail.mail_feeds" |
397 | + groups="group_fetchmail_inbox_manager" |
398 | + /> |
399 | + </data> |
400 | +</openerp> |
401 | |
402 | === added directory 'fetchmail_inbox/wizard' |
403 | === added file 'fetchmail_inbox/wizard/__init__.py' |
404 | --- fetchmail_inbox/wizard/__init__.py 1970-01-01 00:00:00 +0000 |
405 | +++ fetchmail_inbox/wizard/__init__.py 2014-01-15 09:28:30 +0000 |
406 | @@ -0,0 +1,22 @@ |
407 | +# -*- coding: utf-8 -*- |
408 | +############################################################################## |
409 | +# |
410 | +# OpenERP, Open Source Management Solution |
411 | +# This module copyright (C) 2014 Therp BV (<http://therp.nl>). |
412 | +# |
413 | +# This program is free software: you can redistribute it and/or modify |
414 | +# it under the terms of the GNU Affero General Public License as |
415 | +# published by the Free Software Foundation, either version 3 of the |
416 | +# License, or (at your option) any later version. |
417 | +# |
418 | +# This program is distributed in the hope that it will be useful, |
419 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
420 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
421 | +# GNU Affero General Public License for more details. |
422 | +# |
423 | +# You should have received a copy of the GNU Affero General Public License |
424 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
425 | +# |
426 | +############################################################################## |
427 | +import fetchmail_inbox_attach_existing_wizard |
428 | +import fetchmail_inbox_create_wizard |
429 | |
430 | === added file 'fetchmail_inbox/wizard/fetchmail_inbox_attach_existing_wizard.py' |
431 | --- fetchmail_inbox/wizard/fetchmail_inbox_attach_existing_wizard.py 1970-01-01 00:00:00 +0000 |
432 | +++ fetchmail_inbox/wizard/fetchmail_inbox_attach_existing_wizard.py 2014-01-15 09:28:30 +0000 |
433 | @@ -0,0 +1,84 @@ |
434 | +# -*- coding: utf-8 -*- |
435 | +############################################################################## |
436 | +# |
437 | +# OpenERP, Open Source Management Solution |
438 | +# This module copyright (C) 2014 Therp BV (<http://therp.nl>). |
439 | +# |
440 | +# This program is free software: you can redistribute it and/or modify |
441 | +# it under the terms of the GNU Affero General Public License as |
442 | +# published by the Free Software Foundation, either version 3 of the |
443 | +# License, or (at your option) any later version. |
444 | +# |
445 | +# This program is distributed in the hope that it will be useful, |
446 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
447 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
448 | +# GNU Affero General Public License for more details. |
449 | +# |
450 | +# You should have received a copy of the GNU Affero General Public License |
451 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
452 | +# |
453 | +############################################################################## |
454 | +from openerp.osv.orm import TransientModel, except_orm |
455 | +from openerp.osv import fields |
456 | +from openerp.tools.translate import _ |
457 | + |
458 | +class FetchmailInboxAttachExistingWizard(TransientModel): |
459 | + _name = 'fetchmail.inbox.attach.existing.wizard' |
460 | + _description= 'Attach mail to existing object' |
461 | + |
462 | + _columns = { |
463 | + 'res_model': fields.char('Model', size=128), |
464 | + 'res_id': fields.integer('Object', required=True), |
465 | + 'res_reference': fields.reference( |
466 | + 'Reference', |
467 | + lambda self, cr, uid, context: [(m.model, m.name) for m in |
468 | + self.pool.get('ir.model').browse( |
469 | + cr, uid, |
470 | + self.pool.get('ir.model').search( |
471 | + cr, uid, [], context=context), |
472 | + context)], |
473 | + None), |
474 | + 'mail_id': fields.many2one('mail.message', 'Email', required=True), |
475 | + } |
476 | + |
477 | + def fields_view_get(self, cr, user, view_id=None, view_type='form', |
478 | + context=None, toolbar=False, submenu=False): |
479 | + result = super(FetchmailInboxAttachExistingWizard, self)\ |
480 | + .fields_view_get( |
481 | + cr, user, view_id=view_id, view_type=view_type, |
482 | + context=context, toolbar=toolbar, submenu=submenu) |
483 | + if context and context.get('default_res_model'): |
484 | + result['fields']['res_id']['type'] = 'many2one' |
485 | + result['fields']['res_id']['relation'] = \ |
486 | + context['default_res_model'] |
487 | + result['fields']['res_id']['context'] = {} |
488 | + return result |
489 | + |
490 | + def button_attach(self, cr, uid, ids, context=None): |
491 | + for this in self.browse(cr, uid, ids, context=context): |
492 | + if this.res_model and this.res_id: |
493 | + res_model = this.res_model |
494 | + res_id = this.res_id |
495 | + elif this.res_reference: |
496 | + res_model = this.res_reference._model._name |
497 | + res_id = this.res_reference.id |
498 | + else: |
499 | + raise except_orm( |
500 | + _('Error'), _('You have to select an object!')) |
501 | + |
502 | + model = self.pool.get(res_model) |
503 | + if hasattr(model, 'message_update'): |
504 | + model.message_update( |
505 | + cr, uid, [res_id], |
506 | + this.mail_id.fetchmail_inbox_to_msg_dict(), |
507 | + context=dict(context, from_fetchmail_inbox=True)) |
508 | + |
509 | + this.mail_id.fetchmail_inbox_move_to_record(res_model, res_id) |
510 | + |
511 | + return { |
512 | + 'type': 'ir.actions.act_window', |
513 | + 'view_mode': 'form', |
514 | + 'res_model': |
515 | + this.res_model or this.res_reference._model._name, |
516 | + 'res_id': this.res_id or this.res_reference.id, |
517 | + } |
518 | |
519 | === added file 'fetchmail_inbox/wizard/fetchmail_inbox_attach_existing_wizard.xml' |
520 | --- fetchmail_inbox/wizard/fetchmail_inbox_attach_existing_wizard.xml 1970-01-01 00:00:00 +0000 |
521 | +++ fetchmail_inbox/wizard/fetchmail_inbox_attach_existing_wizard.xml 2014-01-15 09:28:30 +0000 |
522 | @@ -0,0 +1,23 @@ |
523 | +<?xml version="1.0" encoding="UTF-8"?> |
524 | +<openerp> |
525 | + <data> |
526 | + <record id="form_fetchmail_inbox_attach_existing_wizard" model="ir.ui.view"> |
527 | + <field name="model">fetchmail.inbox.attach.existing.wizard</field> |
528 | + <field name="type">form</field> |
529 | + <field name="arch" type="xml"> |
530 | + <form version="7.0" string="Attach email to existing object"> |
531 | + <group> |
532 | + <field name="mail_id" invisible="True" /> |
533 | + <field name="res_model" invisible="True" /> |
534 | + <field name="res_id" attrs="{'invisible': [('res_model', '=', False)], 'required': [('res_model', '!=', False)]}" /> |
535 | + <field name="res_reference" attrs="{'invisible': [('res_model', '!=', False)], 'required': [('res_model', '=', False)]}" /> |
536 | + </group> |
537 | + <footer> |
538 | + <button type="object" string="Attach to this object" name="button_attach" class="oe_highlight" /> |
539 | + <button special="cancel" string="Cancel" /> |
540 | + </footer> |
541 | + </form> |
542 | + </field> |
543 | + </record> |
544 | + </data> |
545 | +</openerp> |
546 | |
547 | === added file 'fetchmail_inbox/wizard/fetchmail_inbox_create_wizard.py' |
548 | --- fetchmail_inbox/wizard/fetchmail_inbox_create_wizard.py 1970-01-01 00:00:00 +0000 |
549 | +++ fetchmail_inbox/wizard/fetchmail_inbox_create_wizard.py 2014-01-15 09:28:30 +0000 |
550 | @@ -0,0 +1,54 @@ |
551 | +# -*- coding: utf-8 -*- |
552 | +############################################################################## |
553 | +# |
554 | +# OpenERP, Open Source Management Solution |
555 | +# This module copyright (C) 2014 Therp BV (<http://therp.nl>). |
556 | +# |
557 | +# This program is free software: you can redistribute it and/or modify |
558 | +# it under the terms of the GNU Affero General Public License as |
559 | +# published by the Free Software Foundation, either version 3 of the |
560 | +# License, or (at your option) any later version. |
561 | +# |
562 | +# This program is distributed in the hope that it will be useful, |
563 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
564 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
565 | +# GNU Affero General Public License for more details. |
566 | +# |
567 | +# You should have received a copy of the GNU Affero General Public License |
568 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
569 | +# |
570 | +############################################################################## |
571 | +from openerp.osv.orm import TransientModel, except_orm |
572 | +from openerp.osv import fields |
573 | +from openerp.tools.translate import _ |
574 | + |
575 | +class FetchmailInboxCreateWizard(TransientModel): |
576 | + _name = 'fetchmail.inbox.create.wizard' |
577 | + _description = 'Create object from mail' |
578 | + |
579 | + _columns = { |
580 | + 'model_id': fields.many2one('ir.model', 'Model', required=True), |
581 | + 'mail_id': fields.many2one('mail.message', 'Email', required=True), |
582 | + } |
583 | + |
584 | + def button_create(self, cr, uid, ids, context=None): |
585 | + for this in self.browse(cr, uid, ids, context=context): |
586 | + model = self.pool.get(this.model_id.model) |
587 | + |
588 | + if hasattr(model, 'message_new'): |
589 | + object_id = model.message_new( |
590 | + cr, uid, |
591 | + this.mail_id.fetchmail_inbox_to_msg_dict(), |
592 | + context=dict(context, from_fetchmail_inbox=True)) |
593 | + else: |
594 | + object_id = model.create(cr, uid, {}, context=context) |
595 | + |
596 | + this.mail_id.fetchmail_inbox_move_to_record( |
597 | + this.model_id.model, object_id) |
598 | + |
599 | + return { |
600 | + 'type': 'ir.actions.act_window', |
601 | + 'view_mode': 'form', |
602 | + 'res_model': this.model_id.model, |
603 | + 'res_id': object_id, |
604 | + } |
605 | |
606 | === added file 'fetchmail_inbox/wizard/fetchmail_inbox_create_wizard.xml' |
607 | --- fetchmail_inbox/wizard/fetchmail_inbox_create_wizard.xml 1970-01-01 00:00:00 +0000 |
608 | +++ fetchmail_inbox/wizard/fetchmail_inbox_create_wizard.xml 2014-01-15 09:28:30 +0000 |
609 | @@ -0,0 +1,21 @@ |
610 | +<?xml version="1.0" encoding="UTF-8"?> |
611 | +<openerp> |
612 | + <data> |
613 | + <record id="form_fetchmail_inbox_create_wizard" model="ir.ui.view"> |
614 | + <field name="model">fetchmail.inbox.create.wizard</field> |
615 | + <field name="type">form</field> |
616 | + <field name="arch" type="xml"> |
617 | + <form version="7.0" string="Create object from email"> |
618 | + <group> |
619 | + <field name="mail_id" invisible="True" /> |
620 | + <field name="model_id" /> |
621 | + </group> |
622 | + <footer> |
623 | + <button type="object" string="Create object" name="button_create" class="oe_highlight" /> |
624 | + <button special="cancel" string="Cancel" /> |
625 | + </footer> |
626 | + </form> |
627 | + </field> |
628 | + </record> |
629 | + </data> |
630 | +</openerp> |
631 | |
632 | === added directory 'fetchmail_inbox_invoice' |
633 | === added file 'fetchmail_inbox_invoice/__init__.py' |
634 | --- fetchmail_inbox_invoice/__init__.py 1970-01-01 00:00:00 +0000 |
635 | +++ fetchmail_inbox_invoice/__init__.py 2014-01-15 09:28:30 +0000 |
636 | @@ -0,0 +1,22 @@ |
637 | +# -*- coding: utf-8 -*- |
638 | +############################################################################## |
639 | +# |
640 | +# OpenERP, Open Source Management Solution |
641 | +# This module copyright (C) 2014 Therp BV (<http://therp.nl>). |
642 | +# |
643 | +# This program is free software: you can redistribute it and/or modify |
644 | +# it under the terms of the GNU Affero General Public License as |
645 | +# published by the Free Software Foundation, either version 3 of the |
646 | +# License, or (at your option) any later version. |
647 | +# |
648 | +# This program is distributed in the hope that it will be useful, |
649 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
650 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
651 | +# GNU Affero General Public License for more details. |
652 | +# |
653 | +# You should have received a copy of the GNU Affero General Public License |
654 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
655 | +# |
656 | +############################################################################## |
657 | +import model |
658 | +import wizard |
659 | |
660 | === added file 'fetchmail_inbox_invoice/__openerp__.py' |
661 | --- fetchmail_inbox_invoice/__openerp__.py 1970-01-01 00:00:00 +0000 |
662 | +++ fetchmail_inbox_invoice/__openerp__.py 2014-01-15 09:28:30 +0000 |
663 | @@ -0,0 +1,60 @@ |
664 | +# -*- coding: utf-8 -*- |
665 | +############################################################################## |
666 | +# |
667 | +# OpenERP, Open Source Management Solution |
668 | +# This module copyright (C) 2014 Therp BV (<http://therp.nl>). |
669 | +# |
670 | +# This program is free software: you can redistribute it and/or modify |
671 | +# it under the terms of the GNU Affero General Public License as |
672 | +# published by the Free Software Foundation, either version 3 of the |
673 | +# License, or (at your option) any later version. |
674 | +# |
675 | +# This program is distributed in the hope that it will be useful, |
676 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
677 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
678 | +# GNU Affero General Public License for more details. |
679 | +# |
680 | +# You should have received a copy of the GNU Affero General Public License |
681 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
682 | +# |
683 | +############################################################################## |
684 | +{ |
685 | + "name" : "Fetch mail into inbox (invoice specific)", |
686 | + "version" : "1.0", |
687 | + "author" : "Therp BV", |
688 | + "complexity": "normal", |
689 | + "description": """ |
690 | +Fetch emails from a mail server in order to create invoices from them, |
691 | +but leave them in the inbox for an user to review those mails manually, |
692 | +attach them to existing invoices or create new ones. |
693 | + |
694 | +Usage |
695 | +===== |
696 | + |
697 | +Create a fetchmail configuration for the model "Fetchmail inbox for |
698 | +invoices". The mails fetched from this server will be put into |
699 | +Invoicing / Customers / Fetchmail inbox for further processing. |
700 | + """, |
701 | + "category" : "Accounting & Finance", |
702 | + "depends" : [ |
703 | + 'account', |
704 | + 'fetchmail_inbox', |
705 | + 'fetchmail_invoice', |
706 | + ], |
707 | + "data" : [ |
708 | + 'view/mail_message.xml', |
709 | + 'view/menu.xml', |
710 | + 'security/ir.model.access.csv', |
711 | + ], |
712 | + "js": [ |
713 | + ], |
714 | + "css": [ |
715 | + ], |
716 | + "qweb": [ |
717 | + ], |
718 | + "auto_install": False, |
719 | + "installable": True, |
720 | + "external_dependencies" : { |
721 | + 'python' : [], |
722 | + }, |
723 | +} |
724 | |
725 | === added directory 'fetchmail_inbox_invoice/model' |
726 | === added file 'fetchmail_inbox_invoice/model/__init__.py' |
727 | --- fetchmail_inbox_invoice/model/__init__.py 1970-01-01 00:00:00 +0000 |
728 | +++ fetchmail_inbox_invoice/model/__init__.py 2014-01-15 09:28:30 +0000 |
729 | @@ -0,0 +1,22 @@ |
730 | +# -*- coding: utf-8 -*- |
731 | +############################################################################## |
732 | +# |
733 | +# OpenERP, Open Source Management Solution |
734 | +# This module copyright (C) 2014 Therp BV (<http://therp.nl>). |
735 | +# |
736 | +# This program is free software: you can redistribute it and/or modify |
737 | +# it under the terms of the GNU Affero General Public License as |
738 | +# published by the Free Software Foundation, either version 3 of the |
739 | +# License, or (at your option) any later version. |
740 | +# |
741 | +# This program is distributed in the hope that it will be useful, |
742 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
743 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
744 | +# GNU Affero General Public License for more details. |
745 | +# |
746 | +# You should have received a copy of the GNU Affero General Public License |
747 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
748 | +# |
749 | +############################################################################## |
750 | +import fetchmail_inbox_invoice |
751 | +import mail_message |
752 | |
753 | === added file 'fetchmail_inbox_invoice/model/fetchmail_inbox_invoice.py' |
754 | --- fetchmail_inbox_invoice/model/fetchmail_inbox_invoice.py 1970-01-01 00:00:00 +0000 |
755 | +++ fetchmail_inbox_invoice/model/fetchmail_inbox_invoice.py 2014-01-15 09:28:30 +0000 |
756 | @@ -0,0 +1,28 @@ |
757 | +# -*- coding: utf-8 -*- |
758 | +############################################################################## |
759 | +# |
760 | +# OpenERP, Open Source Management Solution |
761 | +# This module copyright (C) 2014 Therp BV (<http://therp.nl>). |
762 | +# |
763 | +# This program is free software: you can redistribute it and/or modify |
764 | +# it under the terms of the GNU Affero General Public License as |
765 | +# published by the Free Software Foundation, either version 3 of the |
766 | +# License, or (at your option) any later version. |
767 | +# |
768 | +# This program is distributed in the hope that it will be useful, |
769 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
770 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
771 | +# GNU Affero General Public License for more details. |
772 | +# |
773 | +# You should have received a copy of the GNU Affero General Public License |
774 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
775 | +# |
776 | +############################################################################## |
777 | +from openerp.osv.orm import Model |
778 | +from openerp.osv import fields |
779 | + |
780 | +class FetchmailInboxInvoice(Model): |
781 | + _inherit = 'fetchmail.inbox' |
782 | + _name = 'fetchmail.inbox.invoice' |
783 | + _table = 'fetchmail_inbox' |
784 | + _description = 'Fetchmail inbox for invoices' |
785 | |
786 | === added file 'fetchmail_inbox_invoice/model/mail_message.py' |
787 | --- fetchmail_inbox_invoice/model/mail_message.py 1970-01-01 00:00:00 +0000 |
788 | +++ fetchmail_inbox_invoice/model/mail_message.py 2014-01-15 09:28:30 +0000 |
789 | @@ -0,0 +1,32 @@ |
790 | +# -*- coding: utf-8 -*- |
791 | +############################################################################## |
792 | +# |
793 | +# OpenERP, Open Source Management Solution |
794 | +# This module copyright (C) 2014 Therp BV (<http://therp.nl>). |
795 | +# |
796 | +# This program is free software: you can redistribute it and/or modify |
797 | +# it under the terms of the GNU Affero General Public License as |
798 | +# published by the Free Software Foundation, either version 3 of the |
799 | +# License, or (at your option) any later version. |
800 | +# |
801 | +# This program is distributed in the hope that it will be useful, |
802 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
803 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
804 | +# GNU Affero General Public License for more details. |
805 | +# |
806 | +# You should have received a copy of the GNU Affero General Public License |
807 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
808 | +# |
809 | +############################################################################## |
810 | +import base64 |
811 | +from openerp.osv.orm import Model, browse_record |
812 | +from openerp.osv import fields |
813 | + |
814 | +class MailMessage(Model): |
815 | + _inherit = 'mail.message' |
816 | + |
817 | + def _needaction_count(self, cr, uid, dom, context=None): |
818 | + if dom == [('model', '=', 'fetchmail.inbox.invoice')]: |
819 | + return len(self.search(cr, uid, dom, context=context)) |
820 | + return super(MailMessage, self)._needaction_count( |
821 | + cr, uid, dom, context=context) |
822 | |
823 | === added directory 'fetchmail_inbox_invoice/security' |
824 | === added file 'fetchmail_inbox_invoice/security/ir.model.access.csv' |
825 | --- fetchmail_inbox_invoice/security/ir.model.access.csv 1970-01-01 00:00:00 +0000 |
826 | +++ fetchmail_inbox_invoice/security/ir.model.access.csv 2014-01-15 09:28:30 +0000 |
827 | @@ -0,0 +1,2 @@ |
828 | +"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" |
829 | +crud_fetchmail_inbox_invoice,CRUD fetchmail inbox invoice,model_fetchmail_inbox_invoice,account.group_account_user,1,1,1,1 |
830 | |
831 | === added directory 'fetchmail_inbox_invoice/static' |
832 | === added directory 'fetchmail_inbox_invoice/static/src' |
833 | === added directory 'fetchmail_inbox_invoice/static/src/img' |
834 | === added file 'fetchmail_inbox_invoice/static/src/img/icon.png' |
835 | Binary files fetchmail_inbox_invoice/static/src/img/icon.png 1970-01-01 00:00:00 +0000 and fetchmail_inbox_invoice/static/src/img/icon.png 2014-01-15 09:28:30 +0000 differ |
836 | === added directory 'fetchmail_inbox_invoice/view' |
837 | === added file 'fetchmail_inbox_invoice/view/mail_message.xml' |
838 | --- fetchmail_inbox_invoice/view/mail_message.xml 1970-01-01 00:00:00 +0000 |
839 | +++ fetchmail_inbox_invoice/view/mail_message.xml 2014-01-15 09:28:30 +0000 |
840 | @@ -0,0 +1,17 @@ |
841 | +<?xml version="1.0" encoding="UTF-8"?> |
842 | +<openerp> |
843 | + <data> |
844 | + <record id="view_message_form" model="ir.ui.view"> |
845 | + <field name="model">mail.message</field> |
846 | + <field name="inherit_id" ref="mail.view_message_form"/> |
847 | + <field name="arch" type="xml"> |
848 | + <sheet position="before"> |
849 | + <header attrs="{'invisible': [('model', '!=', 'fetchmail.inbox.invoice')]}"> |
850 | + <button string="Attach to existing invoice" type="object" name="fetchmail_inbox_attach_existing" class="oe_highlight" /> |
851 | + <button string="Create invoice" type="object" name="fetchmail_inbox_create" /> |
852 | + </header> |
853 | + </sheet> |
854 | + </field> |
855 | + </record> |
856 | + </data> |
857 | +</openerp> |
858 | |
859 | === added file 'fetchmail_inbox_invoice/view/menu.xml' |
860 | --- fetchmail_inbox_invoice/view/menu.xml 1970-01-01 00:00:00 +0000 |
861 | +++ fetchmail_inbox_invoice/view/menu.xml 2014-01-15 09:28:30 +0000 |
862 | @@ -0,0 +1,18 @@ |
863 | +<?xml version="1.0" encoding="UTF-8"?> |
864 | +<openerp> |
865 | + <data> |
866 | + <act_window id="action_inbox" |
867 | + res_model="mail.message" |
868 | + view_mode="tree,form" |
869 | + domain="[('model', '=', 'fetchmail.inbox.invoice')]" |
870 | + context="{'default_res_model': 'account.invoice'}" |
871 | + name="Invoices per mail" |
872 | + view_id="fetchmail_inbox.tree_mail_message_fetchmail_inbox" |
873 | + /> |
874 | + <menuitem id="menu_inbox" |
875 | + action="action_inbox" |
876 | + parent="account.menu_finance_payables" |
877 | + groups="account.group_account_user" |
878 | + /> |
879 | + </data> |
880 | +</openerp> |
881 | |
882 | === added directory 'fetchmail_inbox_invoice/wizard' |
883 | === added file 'fetchmail_inbox_invoice/wizard/__init__.py' |
884 | --- fetchmail_inbox_invoice/wizard/__init__.py 1970-01-01 00:00:00 +0000 |
885 | +++ fetchmail_inbox_invoice/wizard/__init__.py 2014-01-15 09:28:30 +0000 |
886 | @@ -0,0 +1,21 @@ |
887 | +# -*- coding: utf-8 -*- |
888 | +############################################################################## |
889 | +# |
890 | +# OpenERP, Open Source Management Solution |
891 | +# This module copyright (C) 2014 Therp BV (<http://therp.nl>). |
892 | +# |
893 | +# This program is free software: you can redistribute it and/or modify |
894 | +# it under the terms of the GNU Affero General Public License as |
895 | +# published by the Free Software Foundation, either version 3 of the |
896 | +# License, or (at your option) any later version. |
897 | +# |
898 | +# This program is distributed in the hope that it will be useful, |
899 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
900 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
901 | +# GNU Affero General Public License for more details. |
902 | +# |
903 | +# You should have received a copy of the GNU Affero General Public License |
904 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
905 | +# |
906 | +############################################################################## |
907 | +import fetchmail_inbox_attach_existing_wizard |
908 | |
909 | === added file 'fetchmail_inbox_invoice/wizard/fetchmail_inbox_attach_existing_wizard.py' |
910 | --- fetchmail_inbox_invoice/wizard/fetchmail_inbox_attach_existing_wizard.py 1970-01-01 00:00:00 +0000 |
911 | +++ fetchmail_inbox_invoice/wizard/fetchmail_inbox_attach_existing_wizard.py 2014-01-15 09:28:30 +0000 |
912 | @@ -0,0 +1,42 @@ |
913 | +# -*- coding: utf-8 -*- |
914 | +############################################################################## |
915 | +# |
916 | +# OpenERP, Open Source Management Solution |
917 | +# This module copyright (C) 2014 Therp BV (<http://therp.nl>). |
918 | +# |
919 | +# This program is free software: you can redistribute it and/or modify |
920 | +# it under the terms of the GNU Affero General Public License as |
921 | +# published by the Free Software Foundation, either version 3 of the |
922 | +# License, or (at your option) any later version. |
923 | +# |
924 | +# This program is distributed in the hope that it will be useful, |
925 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
926 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
927 | +# GNU Affero General Public License for more details. |
928 | +# |
929 | +# You should have received a copy of the GNU Affero General Public License |
930 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
931 | +# |
932 | +############################################################################## |
933 | +from openerp.osv.orm import TransientModel |
934 | + |
935 | +class FetchmailInboxAttachExistingWizard(TransientModel): |
936 | + _inherit = 'fetchmail.inbox.attach.existing.wizard' |
937 | + |
938 | + def fields_view_get(self, cr, user, view_id=None, view_type='form', |
939 | + context=None, toolbar=False, submenu=False): |
940 | + result = super(FetchmailInboxAttachExistingWizard, self)\ |
941 | + .fields_view_get( |
942 | + cr, user, view_id=view_id, view_type=view_type, |
943 | + context=context, toolbar=toolbar, submenu=submenu) |
944 | + if context and context.get('default_mail_id') and\ |
945 | + context.get('default_res_model') == 'account.invoice': |
946 | + mail = self.pool.get('mail.message').browse( |
947 | + cr, user, context.get('default_mail_id'), context=context) |
948 | + result['fields']['res_id']['domain'] = [ |
949 | + ('type', 'in', ('in_invoice', 'in_refund'))] |
950 | + if mail.author_id: |
951 | + result['fields']['res_id']['context'].update( |
952 | + search_default_partner_id=\ |
953 | + mail.author_id.commercial_partner_id.id) |
954 | + return result |
Thanks! I tested this, and it works great at first sight. A couple of remarks:
- Can permissions be succesfully applied to the inherited model fetchmail. inbox.invoice? I would rather make the processing of incoming invoices available to 'Account users', and I made the menu item available to them as well as added permissions on this model. But I still run into trouble when as an account user, I try processing the emails under the menu item. partner_ id of the recognized author partner of the email, if any (I think this only works in the full search view when the user clicks on 'Search more...', but that is OK).
- I appreciate the generic setup, but it poses the following challenge: in the case of invoices, when selecting an existing resource, I would like there to be a default filter on the partner_id to be the commercial_
If this is at all possible to add, it would be great.