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