Merge lp:~camptocamp/report-print-send/7.0-base_report_to_printer_port-imp-yvr-2 into lp:~report-print-send-core-editors/report-print-send/7.0
- 7.0-base_report_to_printer_port-imp-yvr-2
- Merge into 7.0
Proposed by
Yannick Vaucher @ Camptocamp
Status: | Merged |
---|---|
Merged at revision: | 10 |
Proposed branch: | lp:~camptocamp/report-print-send/7.0-base_report_to_printer_port-imp-yvr-2 |
Merge into: | lp:~report-print-send-core-editors/report-print-send/7.0 |
Prerequisite: | lp:~camptocamp/report-print-send/7.0-base_report_to_printer_port-imp-yvr |
Diff against target: |
563 lines (+306/-186) 7 files modified
base_report_to_printer/AUTHORS.txt (+1/-0) base_report_to_printer/__init__.py (+6/-1) base_report_to_printer/ir_report.py (+130/-0) base_report_to_printer/printing.py (+1/-185) base_report_to_printer/report_service.py (+72/-0) base_report_to_printer/report_xml_action.py (+50/-0) base_report_to_printer/users.py (+46/-0) |
To merge this branch: | bzr merge lp:~camptocamp/report-print-send/7.0-base_report_to_printer_port-imp-yvr-2 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Maxime Chambreuil (http://www.savoirfairelinux.com) | code review | Approve | |
Omar (Pexego) | code review | Approve | |
Guewen Baconnier @ Camptocamp | code review | Approve | |
Review via email: mp+188825@code.launchpad.net |
Commit message
Description of the change
Simple split of code which was in a single file
New proposal for conveniance for reviewers
To post a comment you must log in.
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote : | # |
review:
Approve
(code review)
Revision history for this message
Omar (Pexego) (omar7r) wrote : | # |
LGTM
review:
Approve
(code review)
Revision history for this message
Maxime Chambreuil (http://www.savoirfairelinux.com) (max3903) : | # |
review:
Approve
(code review)
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'base_report_to_printer/AUTHORS.txt' |
2 | --- base_report_to_printer/AUTHORS.txt 2012-11-22 21:22:52 +0000 |
3 | +++ base_report_to_printer/AUTHORS.txt 2013-10-02 12:33:29 +0000 |
4 | @@ -2,3 +2,4 @@ |
5 | Albert Cervera i Areny <albert@nan-tic.com> |
6 | Davide Corio <davide.corio@agilebg.com> |
7 | Lorenzo Battistini <lorenzo.battistini@agilebg.com> |
8 | +Yannick Vaucher <yannick.vaucher@camptocamp.com> |
9 | |
10 | === modified file 'base_report_to_printer/__init__.py' |
11 | --- base_report_to_printer/__init__.py 2013-10-02 12:33:29 +0000 |
12 | +++ base_report_to_printer/__init__.py 2013-10-02 12:33:29 +0000 |
13 | @@ -1,10 +1,11 @@ |
14 | # -*- coding: utf-8 -*- |
15 | ############################################################################## |
16 | -# |
17 | +# |
18 | # Copyright (c) 2007 Ferran Pegueroles <ferran@pegueroles.com> |
19 | # Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com> |
20 | # Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>) |
21 | # Copyright (C) 2011 Domsense srl (<http://www.domsense.com>) |
22 | +# Copyright (C) 2013 Camptocamp (<http://www.camptocamp.com>) |
23 | # All Rights Reserved |
24 | # |
25 | # This program is free software: you can redistribute it and/or modify |
26 | @@ -22,4 +23,8 @@ |
27 | # |
28 | ############################################################################## |
29 | from . import printing |
30 | +from . import report_xml_action |
31 | +from . import report_service |
32 | +from . import users |
33 | +from . import ir_report |
34 | from . import wizard |
35 | |
36 | === added file 'base_report_to_printer/ir_report.py' |
37 | --- base_report_to_printer/ir_report.py 1970-01-01 00:00:00 +0000 |
38 | +++ base_report_to_printer/ir_report.py 2013-10-02 12:33:29 +0000 |
39 | @@ -0,0 +1,130 @@ |
40 | +# -*- coding: utf-8 -*- |
41 | +############################################################################## |
42 | +# |
43 | +# Copyright (c) 2007 Ferran Pegueroles <ferran@pegueroles.com> |
44 | +# Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com> |
45 | +# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>) |
46 | +# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>) |
47 | +# Copyright (C) 2013 Camptocamp (<http://www.camptocamp.com>) |
48 | +# All Rights Reserved |
49 | +# |
50 | +# This program is free software: you can redistribute it and/or modify |
51 | +# it under the terms of the GNU Affero General Public License as published |
52 | +# by the Free Software Foundation, either version 3 of the License, or |
53 | +# (at your option) any later version. |
54 | +# |
55 | +# This program is distributed in the hope that it will be useful, |
56 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
57 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
58 | +# GNU General Public License for more details. |
59 | +# |
60 | +# You should have received a copy of the GNU Affero General Public License |
61 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
62 | +# |
63 | +############################################################################## |
64 | +import os |
65 | +import base64 |
66 | +from tempfile import mkstemp |
67 | +import logging |
68 | +import cups |
69 | + |
70 | +from openerp.osv import orm, fields |
71 | + |
72 | +# |
73 | +# Reports |
74 | +# |
75 | + |
76 | +class report_xml(orm.Model): |
77 | + |
78 | + |
79 | + def set_print_options(self, cr, uid, report_id, format, context=None): |
80 | + """ |
81 | + Hook to set print options |
82 | + """ |
83 | + options = {} |
84 | + if format == 'raw': |
85 | + options['raw'] = True |
86 | + return options |
87 | + |
88 | + def print_direct(self, cr, uid, report_id, result, format, printer, context=None): |
89 | + user_obj = self.pool.get('res.users') |
90 | + fd, file_name = mkstemp() |
91 | + try: |
92 | + os.write(fd, base64.decodestring(result)) |
93 | + finally: |
94 | + os.close(fd) |
95 | + printer_system_name = '' |
96 | + if printer: |
97 | + if isinstance(printer, (basestring)): |
98 | + printer_system_name = printer |
99 | + else: |
100 | + printer_system_name = printer.system_name |
101 | + connection = cups.Connection() |
102 | + |
103 | + options = self.set_print_options(cr, uid, report_id, format, context=context) |
104 | + |
105 | + connection.printFile(printer_system_name, file_name, file_name, options=options) |
106 | + logger = logging.getLogger('base_report_to_printer') |
107 | + logger.info("Printing job : '%s'" % file_name) |
108 | + return True |
109 | + |
110 | + _inherit = 'ir.actions.report.xml' |
111 | + _columns = { |
112 | + 'property_printing_action': fields.property( |
113 | + #'ir.actions.report.xml', |
114 | + 'printing.action', |
115 | + type='many2one', |
116 | + relation='printing.action', |
117 | + string='Action', |
118 | + view_load=True, |
119 | + method=True, |
120 | + ), |
121 | + 'printing_printer_id': fields.many2one('printing.printer', 'Printer'), |
122 | + 'printing_action_ids': fields.one2many('printing.report.xml.action', 'report_id', 'Actions', help='This field allows configuring action and printer on a per user basis'), |
123 | + } |
124 | + |
125 | + def behaviour(self, cr, uid, ids, context=None): |
126 | + result = {} |
127 | + printer_obj = self.pool.get('printing.printer') |
128 | + printing_act_obj = self.pool.get('printing.report.xml.action') |
129 | + # Set hardcoded default action |
130 | + default_action = 'client' |
131 | + # Retrieve system wide printer |
132 | + default_printer = printer_obj.get_default(cr, uid, context=context) |
133 | + if default_printer: |
134 | + default_printer = printer_obj.browse(cr, uid, default_printer, context=context) |
135 | + |
136 | + |
137 | + # Retrieve user default values |
138 | + user = self.pool.get('res.users').browse(cr, uid, context) |
139 | + if user.printing_action: |
140 | + default_action = user.printing_action |
141 | + if user.printing_printer_id: |
142 | + default_printer = user.printing_printer_id |
143 | + |
144 | + for report in self.browse(cr, uid, ids, context): |
145 | + action = default_action |
146 | + printer = default_printer |
147 | + |
148 | + # Retrieve report default values |
149 | + if report.property_printing_action and report.property_printing_action.type != 'user_default': |
150 | + action = report.property_printing_action.type |
151 | + if report.printing_printer_id: |
152 | + printer = report.printing_printer_id |
153 | + |
154 | + # Retrieve report-user specific values |
155 | + act_ids = printing_act_obj.search(cr, uid, |
156 | + [('report_id', '=', report.id), |
157 | + ('user_id', '=', uid), |
158 | + ('action', '!=', 'user_default')], context=context) |
159 | + if act_ids: |
160 | + user_action = printing_act_obj.behaviour(cr, uid, act_ids[0], context) |
161 | + action = user_action['action'] |
162 | + if user_action['printer']: |
163 | + printer = user_action['printer'] |
164 | + |
165 | + result[report.id] = { |
166 | + 'action': action, |
167 | + 'printer': printer, |
168 | + } |
169 | + return result |
170 | |
171 | === modified file 'base_report_to_printer/printing.py' |
172 | --- base_report_to_printer/printing.py 2013-10-02 12:33:29 +0000 |
173 | +++ base_report_to_printer/printing.py 2013-10-02 12:33:29 +0000 |
174 | @@ -5,6 +5,7 @@ |
175 | # Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com> |
176 | # Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>) |
177 | # Copyright (C) 2011 Domsense srl (<http://www.domsense.com>) |
178 | +# Copyright (C) 2013 Camptocamp (<http://www.camptocamp.com>) |
179 | # All Rights Reserved |
180 | # |
181 | # This program is free software: you can redistribute it and/or modify |
182 | @@ -21,12 +22,8 @@ |
183 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
184 | # |
185 | ############################################################################## |
186 | - |
187 | -import os |
188 | import time |
189 | import base64 |
190 | -from tempfile import mkstemp |
191 | -import logging |
192 | |
193 | import cups |
194 | from threading import Thread |
195 | @@ -199,185 +196,4 @@ |
196 | 'type': fields.selection(_available_action_types, 'Type', required=True), |
197 | } |
198 | |
199 | -# |
200 | -# Users |
201 | -# |
202 | - |
203 | -class res_users(orm.Model): |
204 | - _name = "res.users" |
205 | - _inherit = "res.users" |
206 | - |
207 | - def _user_available_action_types(self, cr, uid, context=None): |
208 | - if context is None: |
209 | - context={} |
210 | - return [x for x in _available_action_types(self, cr, uid, context) if x[0] != 'user_default'] |
211 | - |
212 | - _columns = { |
213 | - 'printing_action': fields.selection(_user_available_action_types, 'Printing Action'), |
214 | - 'printing_printer_id': fields.many2one('printing.printer', 'Default Printer'), |
215 | - } |
216 | - |
217 | -# |
218 | -# Reports |
219 | -# |
220 | - |
221 | -class report_xml(orm.Model): |
222 | - |
223 | - |
224 | - def set_print_options(self, cr, uid, report_id, format, context=None): |
225 | - """ |
226 | - Hook to set print options |
227 | - """ |
228 | - options = {} |
229 | - if format == 'raw': |
230 | - options['raw'] = True |
231 | - return options |
232 | - |
233 | - def print_direct(self, cr, uid, report_id, result, format, printer, context=None): |
234 | - user_obj = self.pool.get('res.users') |
235 | - fd, file_name = mkstemp() |
236 | - try: |
237 | - os.write(fd, base64.decodestring(result)) |
238 | - finally: |
239 | - os.close(fd) |
240 | - printer_system_name = '' |
241 | - if printer: |
242 | - if isinstance(printer, (basestring)): |
243 | - printer_system_name = printer |
244 | - else: |
245 | - printer_system_name = printer.system_name |
246 | - connection = cups.Connection() |
247 | - |
248 | - options = self.set_print_options(cr, uid, report_id, format, context=context) |
249 | - |
250 | - connection.printFile(printer_system_name, file_name, file_name, options=options) |
251 | - logger = logging.getLogger('base_report_to_printer') |
252 | - logger.info("Printing job : '%s'" % file_name) |
253 | - return True |
254 | - |
255 | - _inherit = 'ir.actions.report.xml' |
256 | - _columns = { |
257 | - 'property_printing_action': fields.property( |
258 | - #'ir.actions.report.xml', |
259 | - 'printing.action', |
260 | - type='many2one', |
261 | - relation='printing.action', |
262 | - string='Action', |
263 | - view_load=True, |
264 | - method=True, |
265 | - ), |
266 | - 'printing_printer_id': fields.many2one('printing.printer', 'Printer'), |
267 | - 'printing_action_ids': fields.one2many('printing.report.xml.action', 'report_id', 'Actions', help='This field allows configuring action and printer on a per user basis'), |
268 | - } |
269 | - |
270 | - def behaviour(self, cr, uid, ids, context=None): |
271 | - result = {} |
272 | - printer_obj = self.pool.get('printing.printer') |
273 | - printing_act_obj = self.pool.get('printing.report.xml.action') |
274 | - # Set hardcoded default action |
275 | - default_action = 'client' |
276 | - # Retrieve system wide printer |
277 | - default_printer = printer_obj.get_default(cr, uid, context=context) |
278 | - if default_printer: |
279 | - default_printer = printer_obj.browse(cr, uid, default_printer, context=context) |
280 | - |
281 | - |
282 | - # Retrieve user default values |
283 | - user = self.pool.get('res.users').browse(cr, uid, context) |
284 | - if user.printing_action: |
285 | - default_action = user.printing_action |
286 | - if user.printing_printer_id: |
287 | - default_printer = user.printing_printer_id |
288 | - |
289 | - for report in self.browse(cr, uid, ids, context): |
290 | - action = default_action |
291 | - printer = default_printer |
292 | - |
293 | - # Retrieve report default values |
294 | - if report.property_printing_action and report.property_printing_action.type != 'user_default': |
295 | - action = report.property_printing_action.type |
296 | - if report.printing_printer_id: |
297 | - printer = report.printing_printer_id |
298 | - |
299 | - # Retrieve report-user specific values |
300 | - act_ids = printing_act_obj.search(cr, uid, |
301 | - [('report_id', '=', report.id), |
302 | - ('user_id', '=', uid), |
303 | - ('action', '!=', 'user_default')], context=context) |
304 | - if act_ids: |
305 | - user_action = printing_act_obj.behaviour(cr, uid, act_ids[0], context) |
306 | - action = user_action['action'] |
307 | - if user_action['printer']: |
308 | - printer = user_action['printer'] |
309 | - |
310 | - result[report.id] = { |
311 | - 'action': action, |
312 | - 'printer': printer, |
313 | - } |
314 | - return result |
315 | - |
316 | - |
317 | -class report_xml_action(orm.Model): |
318 | - _name = 'printing.report.xml.action' |
319 | - _description = 'Report Printing Actions' |
320 | - _columns = { |
321 | - 'report_id': fields.many2one('ir.actions.report.xml', 'Report', required=True, ondelete='cascade'), |
322 | - 'user_id': fields.many2one('res.users', 'User', required=True, ondelete='cascade'), |
323 | - 'action': fields.selection(_available_action_types, 'Action', required=True), |
324 | - 'printer_id': fields.many2one('printing.printer', 'Printer'), |
325 | - } |
326 | - |
327 | - |
328 | - def behaviour(self, cr, uid, act_id, context=None): |
329 | - result = {} |
330 | - if not act_id: |
331 | - return False |
332 | - action = self.browse(cr, uid, act_id, context=context) |
333 | - return { |
334 | - 'action': action.action, |
335 | - 'printer': action.printer_id, |
336 | - } |
337 | - |
338 | -class virtual_report_spool(base_calendar.virtual_report_spool): |
339 | - |
340 | - def exp_report(self, db, uid, object, ids, datas=None, context=None): |
341 | - res = super(virtual_report_spool, self).exp_report(db, uid, object, ids, datas, context) |
342 | - self._reports[res]['report_name'] = object |
343 | - return res |
344 | - |
345 | - def exp_report_get(self, db, uid, report_id): |
346 | - |
347 | - cr = pooler.get_db(db).cursor() |
348 | - try: |
349 | - pool = pooler.get_pool(cr.dbname) |
350 | - # First of all load report defaults: name, action and printer |
351 | - report_obj = pool.get('ir.actions.report.xml') |
352 | - report = report_obj.search(cr,uid,[('report_name','=',self._reports[report_id]['report_name'])]) |
353 | - if report: |
354 | - report = report_obj.browse(cr,uid,report[0]) |
355 | - name = report.name |
356 | - data = report.behaviour()[report.id] |
357 | - action = data['action'] |
358 | - printer = data['printer'] |
359 | - if action != 'client': |
360 | - if (self._reports and self._reports.get(report_id, False) and self._reports[report_id].get('result', False) |
361 | - and self._reports[report_id].get('format', False)): |
362 | - report_obj.print_direct(cr, uid, report.id, base64.encodestring(self._reports[report_id]['result']), |
363 | - self._reports[report_id]['format'], printer) |
364 | - # XXX "Warning" removed as it breaks the workflow |
365 | - # it would be interesting to have a dialog box to confirm if we really want to print |
366 | - # in this case it must be with a by pass parameter to allow massive impression |
367 | - #raise osv.except_osv(_('Printing...'), _('Document sent to printer %s') % (printer,)) |
368 | - |
369 | - except: |
370 | - cr.rollback() |
371 | - raise |
372 | - finally: |
373 | - cr.close() |
374 | - |
375 | - res = super(virtual_report_spool, self).exp_report_get(db, uid, report_id) |
376 | - return res |
377 | - |
378 | -virtual_report_spool() |
379 | - |
380 | # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
381 | |
382 | === added file 'base_report_to_printer/report_service.py' |
383 | --- base_report_to_printer/report_service.py 1970-01-01 00:00:00 +0000 |
384 | +++ base_report_to_printer/report_service.py 2013-10-02 12:33:29 +0000 |
385 | @@ -0,0 +1,72 @@ |
386 | +# -*- coding: utf-8 -*- |
387 | +############################################################################## |
388 | +# |
389 | +# Copyright (c) 2007 Ferran Pegueroles <ferran@pegueroles.com> |
390 | +# Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com> |
391 | +# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>) |
392 | +# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>) |
393 | +# Copyright (C) 2013 Camptocamp (<http://www.camptocamp.com>) |
394 | +# All Rights Reserved |
395 | +# |
396 | +# This program is free software: you can redistribute it and/or modify |
397 | +# it under the terms of the GNU Affero General Public License as published |
398 | +# by the Free Software Foundation, either version 3 of the License, or |
399 | +# (at your option) any later version. |
400 | +# |
401 | +# This program is distributed in the hope that it will be useful, |
402 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
403 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
404 | +# GNU General Public License for more details. |
405 | +# |
406 | +# You should have received a copy of the GNU Affero General Public License |
407 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
408 | +# |
409 | +############################################################################## |
410 | +import base64 |
411 | + |
412 | +from openerp import pooler |
413 | +from openerp.addons.base_calendar import base_calendar |
414 | + |
415 | +class virtual_report_spool(base_calendar.virtual_report_spool): |
416 | + |
417 | + def exp_report(self, db, uid, object, ids, datas=None, context=None): |
418 | + res = super(virtual_report_spool, self).exp_report(db, uid, object, ids, datas, context) |
419 | + self._reports[res]['report_name'] = object |
420 | + return res |
421 | + |
422 | + def exp_report_get(self, db, uid, report_id): |
423 | + |
424 | + cr = pooler.get_db(db).cursor() |
425 | + try: |
426 | + pool = pooler.get_pool(cr.dbname) |
427 | + # First of all load report defaults: name, action and printer |
428 | + report_obj = pool.get('ir.actions.report.xml') |
429 | + report = report_obj.search(cr,uid,[('report_name','=',self._reports[report_id]['report_name'])]) |
430 | + if report: |
431 | + report = report_obj.browse(cr,uid,report[0]) |
432 | + name = report.name |
433 | + data = report.behaviour()[report.id] |
434 | + action = data['action'] |
435 | + printer = data['printer'] |
436 | + if action != 'client': |
437 | + if (self._reports and self._reports.get(report_id, False) and self._reports[report_id].get('result', False) |
438 | + and self._reports[report_id].get('format', False)): |
439 | + report_obj.print_direct(cr, uid, report.id, base64.encodestring(self._reports[report_id]['result']), |
440 | + self._reports[report_id]['format'], printer) |
441 | + # XXX "Warning" removed as it breaks the workflow |
442 | + # it would be interesting to have a dialog box to confirm if we really want to print |
443 | + # in this case it must be with a by pass parameter to allow massive impression |
444 | + #raise osv.except_osv(_('Printing...'), _('Document sent to printer %s') % (printer,)) |
445 | + |
446 | + except: |
447 | + cr.rollback() |
448 | + raise |
449 | + finally: |
450 | + cr.close() |
451 | + |
452 | + res = super(virtual_report_spool, self).exp_report_get(db, uid, report_id) |
453 | + return res |
454 | + |
455 | +virtual_report_spool() |
456 | + |
457 | +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
458 | |
459 | === added file 'base_report_to_printer/report_xml_action.py' |
460 | --- base_report_to_printer/report_xml_action.py 1970-01-01 00:00:00 +0000 |
461 | +++ base_report_to_printer/report_xml_action.py 2013-10-02 12:33:29 +0000 |
462 | @@ -0,0 +1,50 @@ |
463 | +# -*- coding: utf-8 -*- |
464 | +############################################################################## |
465 | +# |
466 | +# Copyright (c) 2007 Ferran Pegueroles <ferran@pegueroles.com> |
467 | +# Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com> |
468 | +# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>) |
469 | +# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>) |
470 | +# Copyright (C) 2013 Camptocamp (<http://www.camptocamp.com>) |
471 | +# All Rights Reserved |
472 | +# |
473 | +# This program is free software: you can redistribute it and/or modify |
474 | +# it under the terms of the GNU Affero General Public License as published |
475 | +# by the Free Software Foundation, either version 3 of the License, or |
476 | +# (at your option) any later version. |
477 | +# |
478 | +# This program is distributed in the hope that it will be useful, |
479 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
480 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
481 | +# GNU General Public License for more details. |
482 | +# |
483 | +# You should have received a copy of the GNU Affero General Public License |
484 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
485 | +# |
486 | +############################################################################## |
487 | +from openerp.osv import orm, fields |
488 | + |
489 | +from printing import _available_action_types |
490 | + |
491 | +class report_xml_action(orm.Model): |
492 | + _name = 'printing.report.xml.action' |
493 | + _description = 'Report Printing Actions' |
494 | + _columns = { |
495 | + 'report_id': fields.many2one('ir.actions.report.xml', 'Report', required=True, ondelete='cascade'), |
496 | + 'user_id': fields.many2one('res.users', 'User', required=True, ondelete='cascade'), |
497 | + 'action': fields.selection(_available_action_types, 'Action', required=True), |
498 | + 'printer_id': fields.many2one('printing.printer', 'Printer'), |
499 | + } |
500 | + |
501 | + |
502 | + def behaviour(self, cr, uid, act_id, context=None): |
503 | + result = {} |
504 | + if not act_id: |
505 | + return False |
506 | + action = self.browse(cr, uid, act_id, context=context) |
507 | + return { |
508 | + 'action': action.action, |
509 | + 'printer': action.printer_id, |
510 | + } |
511 | + |
512 | +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
513 | |
514 | === added file 'base_report_to_printer/users.py' |
515 | --- base_report_to_printer/users.py 1970-01-01 00:00:00 +0000 |
516 | +++ base_report_to_printer/users.py 2013-10-02 12:33:29 +0000 |
517 | @@ -0,0 +1,46 @@ |
518 | +# -*- coding: utf-8 -*- |
519 | +############################################################################## |
520 | +# |
521 | +# Copyright (c) 2007 Ferran Pegueroles <ferran@pegueroles.com> |
522 | +# Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com> |
523 | +# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>) |
524 | +# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>) |
525 | +# Copyright (C) 2013 Camptocamp (<http://www.camptocamp.com>) |
526 | +# All Rights Reserved |
527 | +# |
528 | +# This program is free software: you can redistribute it and/or modify |
529 | +# it under the terms of the GNU Affero General Public License as published |
530 | +# by the Free Software Foundation, either version 3 of the License, or |
531 | +# (at your option) any later version. |
532 | +# |
533 | +# This program is distributed in the hope that it will be useful, |
534 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
535 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
536 | +# GNU General Public License for more details. |
537 | +# |
538 | +# You should have received a copy of the GNU Affero General Public License |
539 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
540 | +# |
541 | +############################################################################## |
542 | +from openerp.osv import orm, fields |
543 | + |
544 | +from printing import _available_action_types |
545 | + |
546 | +# |
547 | +# Users |
548 | +# |
549 | +class res_users(orm.Model): |
550 | + _name = "res.users" |
551 | + _inherit = "res.users" |
552 | + |
553 | + def _user_available_action_types(self, cr, uid, context=None): |
554 | + if context is None: |
555 | + context={} |
556 | + return [x for x in _available_action_types(self, cr, uid, context) if x[0] != 'user_default'] |
557 | + |
558 | + _columns = { |
559 | + 'printing_action': fields.selection(_user_available_action_types, 'Printing Action'), |
560 | + 'printing_printer_id': fields.many2one('printing.printer', 'Default Printer'), |
561 | + } |
562 | + |
563 | +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
As it is just a split of a python module, I'll grant it as: ok for the merge.