Merge lp:~elbati/report-print-send/adding_base_report_to_printer into lp:~report-print-send-core-editors/report-print-send/6.1

Proposed by Lorenzo Battistini
Status: Merged
Approved by: Nicolas Bessi - Camptocamp
Approved revision: 11
Merge reported by: Nicolas Bessi - Camptocamp
Merged at revision: not available
Proposed branch: lp:~elbati/report-print-send/adding_base_report_to_printer
Merge into: lp:~report-print-send-core-editors/report-print-send/6.1
Diff against target: 1318 lines (+1255/-0)
12 files modified
base_report_to_printer/AUTHORS.txt (+4/-0)
base_report_to_printer/__init__.py (+25/-0)
base_report_to_printer/__openerp__.py (+45/-0)
base_report_to_printer/i18n/base_report_to_printer.pot (+246/-0)
base_report_to_printer/i18n/it.po (+246/-0)
base_report_to_printer/printing.py (+379/-0)
base_report_to_printer/printing_data.xml (+20/-0)
base_report_to_printer/printing_view.xml (+113/-0)
base_report_to_printer/security/security.xml (+52/-0)
base_report_to_printer/wizard/__init__.py (+23/-0)
base_report_to_printer/wizard/update_printers.py (+76/-0)
base_report_to_printer/wizard/update_printers.xml (+26/-0)
To merge this branch: bzr merge lp:~elbati/report-print-send/adding_base_report_to_printer
Reviewer Review Type Date Requested Status
Nicolas Bessi - Camptocamp (community) Approve
Lorenzo Battistini (community) Needs Resubmitting
Review via email: mp+135780@code.launchpad.net

Description of the change

Extracted from printjob ( http://apps.openerp.com/addon/1727 ), this module allows to send reports to a printer attached to the server. Settings can be configured globaly, per user, per report and per user and report.

    For more info: http://planet.domsense.com/en/2011/10/linking-openerp-to-cups-printers-base_report_to_printer/

To post a comment you must log in.
Revision history for this message
Joël Grand-Guillaume @ camptocamp (jgrandguillaume-c2c) wrote :

Hi,

Just had a look on the doc. I think it'll be good to have this doc :

http://planet.domsense.com/en/2011/10/linking-openerp-to-cups-printers-base_report_to_printer/

in the __openerp__ description file. This way we have all necessary infos in the module doc directly.

Though ?

Regards,

Joël

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Hi,

Maybe some nitpicking but the first point could lead to postgresql connections leaks.

675+ cr = db.cursor()
[...]
713+ cr.close()
The close should be done in the finally: clause of a try: except: because if an exception occurs between the lines 675 and 713, a postgresql transaction will be leaked.
The except clause should properly rollback the cr.
Same on lines 936..953

714+ self.lock.acquire()
[...]
717+ self.lock.release()
We better have to use the "with" syntax, no?
with self.lock:
    [...]

730+ def update(self, cr, uid, context=None):
This method is accessible from XML/RPC and should return something else than None which is forbidden,
or be changed to a "private to OpenERP" method prefixing it by _.
Same for methods on line 825

774+ return None
It should probably return False, for the same reason as the previous point.

784+def _available_action_types(self, cr, uid, context={}):
the context keyword argument should have a None default value instead of a mutable.
Same for lines 809,861,915

826+ logger = netsvc.Logger()
Should now use the logging module because netsvc.Logger is deprecated and throws annoying warnings.

834+ if isinstance(printer, (str,unicode)):
could be replaced by isinstance(printer, basestring) ?

Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote :

Hello,

Thanks for your proposal.

You will find my comments below, only "Blocking" points need to be fixed before merging existing modules. But fixing the other point will allow the module to be merged for V7.0

[Blockin]
- Guewen is right in as you create your own cursor it must be ensured that they are closed especially in threaded task

[Medium]
- You use the lpr command without exception management it will be also nice to use subprocess module to manage timeout
- Some public functions does not match signatures, and/or return none
- It will be nice to put in doc page or in __openerp__.py dependencies CUPS, lpr and python pycups and for pip user on libcups2-dev
- Context in named args must be None
- The update printer wizard should raise an except_osv if cups raise an exception. It is not intuitive for end user.

[Nice to have]
- Maybe link access ir_model_access_printingprinterall0 to employee group
- There are unused import and some unused variable, coding standard problem. A simple cleanup with pylint, pyflakes would be nice
- Imports should be done form opener namespace from openerp.addons.xx import yy from openerp.tools import xxx
- Absolute import are nice from . import xxx
- Model/TransientModel class should be used instead of osv.osv/osv.osv_memory

review: Needs Fixing
2. By Lorenzo Battistini

[IMP] base_report_to_printer - module description

3. By Lorenzo Battistini

[imp] description with images

4. By Lorenzo Battistini

[FIX] The close should be done in the finally: clause of a try: except: because if an exception occurs,
a postgresql transaction will be leaked.
The except clause should properly rollback the cr

5. By Lorenzo Battistini

[FIX] We better have to use the "with" syntax

6. By Lorenzo Battistini

[FIX] update method is accessible from XML/RPC and should return something else than None which is forbidden

7. By Lorenzo Battistini

[FIX] print_direct return value

8. By Lorenzo Battistini

[fix] get_default return value

9. By Lorenzo Battistini

[FIX] context=None

10. By Lorenzo Battistini

[FIX] using logging

11. By Lorenzo Battistini

[FIX] isinstance(printer, (str,unicode)):
replaced by isinstance(printer, basestring)

Revision history for this message
Lorenzo Battistini (elbati) wrote :

Hello, thanks for your remarks.
I just updated the code fixing some of your points.
Others, like handling exceptions related to lpr command, still have to be added.

review: Needs Resubmitting
Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote :

Hello,

It is ok for me blocking point are fixed.
Ideally in your except :
714 + except:
715 + cr.rollback()
716 + raise
717 + finally:
718 + cr.close()

you should log the exception and return a user friendly except osv like : Can not update printer status please check ….

Nicolas

> Hello, thanks for your remarks.
> I just updated the code fixing some of your points.
> Others, like handling exceptions related to lpr command, still have to be
> added.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'base_report_to_printer'
2=== added file 'base_report_to_printer/AUTHORS.txt'
3--- base_report_to_printer/AUTHORS.txt 1970-01-01 00:00:00 +0000
4+++ base_report_to_printer/AUTHORS.txt 2012-12-06 15:11:20 +0000
5@@ -0,0 +1,4 @@
6+Ferran Pegueroles <ferran@pegueroles.com>
7+Albert Cervera i Areny <albert@nan-tic.com>
8+Davide Corio <davide.corio@agilebg.com>
9+Lorenzo Battistini <lorenzo.battistini@agilebg.com>
10
11=== added file 'base_report_to_printer/__init__.py'
12--- base_report_to_printer/__init__.py 1970-01-01 00:00:00 +0000
13+++ base_report_to_printer/__init__.py 2012-12-06 15:11:20 +0000
14@@ -0,0 +1,25 @@
15+# -*- coding: utf-8 -*-
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+# All Rights Reserved
23+#
24+# This program is free software: you can redistribute it and/or modify
25+# it under the terms of the GNU Affero General Public License as published
26+# by the Free Software Foundation, either version 3 of the License, or
27+# (at your option) any later version.
28+#
29+# This program is distributed in the hope that it will be useful,
30+# but WITHOUT ANY WARRANTY; without even the implied warranty of
31+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32+# GNU General Public License for more details.
33+#
34+# You should have received a copy of the GNU Affero General Public License
35+# along with this program. If not, see <http://www.gnu.org/licenses/>.
36+#
37+##############################################################################
38+import printing
39+import wizard
40
41=== added file 'base_report_to_printer/__openerp__.py'
42--- base_report_to_printer/__openerp__.py 1970-01-01 00:00:00 +0000
43+++ base_report_to_printer/__openerp__.py 2012-12-06 15:11:20 +0000
44@@ -0,0 +1,45 @@
45+# -*- coding: utf-8 -*-
46+##############################################################################
47+#
48+# Copyright (c) 2007 Ferran Pegueroles <ferran@pegueroles.com>
49+# Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com>
50+# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
51+# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
52+# All Rights Reserved
53+#
54+# This program is free software: you can redistribute it and/or modify
55+# it under the terms of the GNU Affero General Public License as published
56+# by the Free Software Foundation, either version 3 of the License, or
57+# (at your option) any later version.
58+#
59+# This program is distributed in the hope that it will be useful,
60+# but WITHOUT ANY WARRANTY; without even the implied warranty of
61+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
62+# GNU General Public License for more details.
63+#
64+# You should have received a copy of the GNU Affero General Public License
65+# along with this program. If not, see <http://www.gnu.org/licenses/>.
66+#
67+##############################################################################
68+{
69+ 'name': "Report to printer",
70+ 'version': '0.1',
71+ 'category': 'Generic Modules/Base',
72+ 'description': """Extracted from printjob ( http://apps.openerp.com/addon/1727 ), this module allows to send reports to a printer attached to the server. Settings can be configured globaly, per user, per report and per user and report.
73+
74+ For more info: http://planet.domsense.com/en/2011/10/linking-openerp-to-cups-printers-base_report_to_printer/""",
75+ 'author': 'Agile Business Group & Domsense, Pegueroles SCP, NaN',
76+ 'website': 'http://www.agilebg.com',
77+ 'license': 'AGPL-3',
78+ "depends" : ['base', 'base_calendar'],
79+ "init_xml" : [],
80+ "update_xml" : [
81+ 'printing_data.xml',
82+ 'printing_view.xml',
83+ 'wizard/update_printers.xml',
84+ 'security/security.xml',
85+ ],
86+ "demo_xml" : [],
87+ "active": False,
88+ "installable": True
89+}
90
91=== added directory 'base_report_to_printer/i18n'
92=== added file 'base_report_to_printer/i18n/base_report_to_printer.pot'
93--- base_report_to_printer/i18n/base_report_to_printer.pot 1970-01-01 00:00:00 +0000
94+++ base_report_to_printer/i18n/base_report_to_printer.pot 2012-12-06 15:11:20 +0000
95@@ -0,0 +1,246 @@
96+# Translation of OpenERP Server.
97+# This file contains the translation of the following modules:
98+# * base_report_to_printer
99+#
100+msgid ""
101+msgstr ""
102+"Project-Id-Version: OpenERP Server 6.0.3\n"
103+"Report-Msgid-Bugs-To: support@openerp.com\n"
104+"POT-Creation-Date: 2011-09-26 09:06+0000\n"
105+"PO-Revision-Date: 2011-09-26 09:06+0000\n"
106+"Last-Translator: <>\n"
107+"Language-Team: \n"
108+"MIME-Version: 1.0\n"
109+"Content-Type: text/plain; charset=UTF-8\n"
110+"Content-Transfer-Encoding: \n"
111+"Plural-Forms: \n"
112+
113+#. module: base_report_to_printer
114+#: sql_constraint:res.users:0
115+msgid "You can not have two users with the same login !"
116+msgstr ""
117+
118+#. module: base_report_to_printer
119+#: selection:printing.printer,status:0
120+msgid "Unavailable"
121+msgstr ""
122+
123+#. module: base_report_to_printer
124+#: view:printing.printer.update.wizard:0
125+msgid "This process will create all missing printers from the current CUPS server."
126+msgstr ""
127+
128+#. module: base_report_to_printer
129+#: selection:printing.printer,status:0
130+msgid "Unknown"
131+msgstr ""
132+
133+#. module: base_report_to_printer
134+#: field:printing.printer,status:0
135+msgid "Status"
136+msgstr ""
137+
138+#. module: base_report_to_printer
139+#: field:printing.printer,system_name:0
140+msgid "System Name"
141+msgstr ""
142+
143+#. module: base_report_to_printer
144+#: constraint:res.users:0
145+msgid "The chosen company is not in the allowed companies for this user"
146+msgstr ""
147+
148+#. module: base_report_to_printer
149+#: field:printing.printer,location:0
150+msgid "Location"
151+msgstr ""
152+
153+#. module: base_report_to_printer
154+#: model:ir.actions.act_window,name:base_report_to_printer.action_printing_printer_form
155+#: model:ir.ui.menu,name:base_report_to_printer.menu_printing_printer_form
156+#: view:printing.printer:0
157+msgid "Printers"
158+msgstr ""
159+
160+#. module: base_report_to_printer
161+#: field:res.users,printing_action:0
162+msgid "Printing Action"
163+msgstr ""
164+
165+#. module: base_report_to_printer
166+#: model:ir.module.module,description:base_report_to_printer.module_meta_information
167+msgid "Extracted from printjob ( http://apps.openerp.com/addon/1727 ), this module allows to send reports to a printer attached to the server. Settings can be configured globaly, per user, per report and per user and report."
168+msgstr ""
169+
170+#. module: base_report_to_printer
171+#: field:printing.action,type:0
172+msgid "Type"
173+msgstr ""
174+
175+#. module: base_report_to_printer
176+#: selection:printing.printer,status:0
177+msgid "Available"
178+msgstr ""
179+
180+#. module: base_report_to_printer
181+#: field:ir.actions.report.xml,printing_printer_id:0
182+#: model:ir.model,name:base_report_to_printer.model_printing_printer
183+#: field:printing.report.xml.action,printer_id:0
184+msgid "Printer"
185+msgstr ""
186+
187+#. module: base_report_to_printer
188+#: model:ir.model,name:base_report_to_printer.model_printing_report_xml_action
189+#: view:printing.report.xml.action:0
190+msgid "Report Printing Actions"
191+msgstr ""
192+
193+#. module: base_report_to_printer
194+#: model:ir.model,name:base_report_to_printer.model_printing_action
195+msgid "Print Job Action"
196+msgstr ""
197+
198+#. module: base_report_to_printer
199+#: field:printing.report.xml.action,user_id:0
200+msgid "User"
201+msgstr ""
202+
203+#. module: base_report_to_printer
204+#: field:printing.report.xml.action,report_id:0
205+msgid "Report"
206+msgstr ""
207+
208+#. module: base_report_to_printer
209+#: model:ir.ui.menu,name:base_report_to_printer.menu_printing_config
210+msgid "Configuration"
211+msgstr ""
212+
213+#. module: base_report_to_printer
214+#: model:ir.module.module,shortdesc:base_report_to_printer.module_meta_information
215+msgid "Report to printer"
216+msgstr ""
217+
218+#. module: base_report_to_printer
219+#: model:ir.model,name:base_report_to_printer.model_printjob_printer_update_wizard
220+msgid "printjob.printer.update.wizard"
221+msgstr ""
222+
223+#. module: base_report_to_printer
224+#: view:printing.printer.update.wizard:0
225+msgid "Ok"
226+msgstr ""
227+
228+#. module: base_report_to_printer
229+#: field:printing.action,name:0
230+#: field:printing.printer,name:0
231+msgid "Name"
232+msgstr ""
233+
234+#. module: base_report_to_printer
235+#: view:printing.printer:0
236+msgid "Set Default"
237+msgstr ""
238+
239+#. module: base_report_to_printer
240+#: field:printing.printer,default:0
241+#: field:res.users,printing_printer_id:0
242+msgid "Default Printer"
243+msgstr ""
244+
245+#. module: base_report_to_printer
246+#: code:addons/base_report_to_printer/printing.py:189
247+#, python-format
248+msgid "Send to Client"
249+msgstr ""
250+
251+#. module: base_report_to_printer
252+#: field:printing.printer,uri:0
253+msgid "URI"
254+msgstr ""
255+
256+#. module: base_report_to_printer
257+#: model:ir.model,name:base_report_to_printer.model_printing_printer_update_wizard
258+msgid "printing.printer.update.wizard"
259+msgstr ""
260+
261+#. module: base_report_to_printer
262+#: model:ir.actions.act_window,name:base_report_to_printer.action_printer_update_wizard
263+#: model:ir.ui.menu,name:base_report_to_printer.menu_printer_update_wizard
264+#: view:printing.printer.update.wizard:0
265+msgid "Update Printers from CUPS"
266+msgstr ""
267+
268+#. module: base_report_to_printer
269+#: code:addons/base_report_to_printer/printing.py:188
270+#, python-format
271+msgid "Send to Printer"
272+msgstr ""
273+
274+#. module: base_report_to_printer
275+#: model:ir.ui.menu,name:base_report_to_printer.menu_printing_main
276+#: selection:printing.printer,status:0
277+msgid "Printing"
278+msgstr ""
279+
280+#. module: base_report_to_printer
281+#: selection:printing.printer,status:0
282+msgid "Error"
283+msgstr ""
284+
285+#. module: base_report_to_printer
286+#: field:ir.actions.report.xml,property_printing_action:0
287+#: field:printing.report.xml.action,action:0
288+msgid "Action"
289+msgstr ""
290+
291+#. module: base_report_to_printer
292+#: field:printing.printer,model:0
293+msgid "Model"
294+msgstr ""
295+
296+#. module: base_report_to_printer
297+#: field:printing.printer,status_message:0
298+msgid "Status Message"
299+msgstr ""
300+
301+#. module: base_report_to_printer
302+#: help:ir.actions.report.xml,printing_action_ids:0
303+msgid "This field allows configuring action and printer on a per user basis"
304+msgstr ""
305+
306+#. module: base_report_to_printer
307+#: selection:printing.printer,status:0
308+msgid "Server Error"
309+msgstr ""
310+
311+#. module: base_report_to_printer
312+#: field:ir.actions.report.xml,printing_action_ids:0
313+msgid "Actions"
314+msgstr ""
315+
316+#. module: base_report_to_printer
317+#: view:printing.job:0
318+msgid "Print Jobs"
319+msgstr ""
320+
321+#. module: base_report_to_printer
322+#: view:printing.printer.update.wizard:0
323+msgid "Cancel"
324+msgstr ""
325+
326+#. module: base_report_to_printer
327+#: model:ir.model,name:base_report_to_printer.model_res_users
328+msgid "res.users"
329+msgstr ""
330+
331+#. module: base_report_to_printer
332+#: code:addons/base_report_to_printer/printing.py:190
333+#, python-format
334+msgid "Use user's defaults"
335+msgstr ""
336+
337+#. module: base_report_to_printer
338+#: model:ir.model,name:base_report_to_printer.model_ir_actions_report_xml
339+msgid "ir.actions.report.xml"
340+msgstr ""
341+
342
343=== added file 'base_report_to_printer/i18n/it.po'
344--- base_report_to_printer/i18n/it.po 1970-01-01 00:00:00 +0000
345+++ base_report_to_printer/i18n/it.po 2012-12-06 15:11:20 +0000
346@@ -0,0 +1,246 @@
347+# Translation of OpenERP Server.
348+# This file contains the translation of the following modules:
349+# * base_report_to_printer
350+#
351+msgid ""
352+msgstr ""
353+"Project-Id-Version: OpenERP Server 6.0.3\n"
354+"Report-Msgid-Bugs-To: support@openerp.com\n"
355+"POT-Creation-Date: 2011-09-26 09:06+0000\n"
356+"PO-Revision-Date: 2011-09-26 11:14+0100\n"
357+"Last-Translator: Lorenzo Battistini <lorenzo.battistini@agilebg.com>\n"
358+"Language-Team: \n"
359+"MIME-Version: 1.0\n"
360+"Content-Type: text/plain; charset=UTF-8\n"
361+"Content-Transfer-Encoding: 8bit\n"
362+"Plural-Forms: \n"
363+
364+#. module: base_report_to_printer
365+#: sql_constraint:res.users:0
366+msgid "You can not have two users with the same login !"
367+msgstr "Non è possibile inserire due utenti con lo stesso nome di login!"
368+
369+#. module: base_report_to_printer
370+#: selection:printing.printer,status:0
371+msgid "Unavailable"
372+msgstr "Non disponibile"
373+
374+#. module: base_report_to_printer
375+#: view:printing.printer.update.wizard:0
376+msgid "This process will create all missing printers from the current CUPS server."
377+msgstr "Questo processo creerà tutte le stampante mancanti dal server CUPS corrente"
378+
379+#. module: base_report_to_printer
380+#: selection:printing.printer,status:0
381+msgid "Unknown"
382+msgstr "Sconosciuto"
383+
384+#. module: base_report_to_printer
385+#: field:printing.printer,status:0
386+msgid "Status"
387+msgstr "Stato"
388+
389+#. module: base_report_to_printer
390+#: field:printing.printer,system_name:0
391+msgid "System Name"
392+msgstr "Nome di sistema"
393+
394+#. module: base_report_to_printer
395+#: constraint:res.users:0
396+msgid "The chosen company is not in the allowed companies for this user"
397+msgstr "L'azienda selezionata non è tra quelle a cui è permesso l'accesso a questo utente"
398+
399+#. module: base_report_to_printer
400+#: field:printing.printer,location:0
401+msgid "Location"
402+msgstr "Locazione"
403+
404+#. module: base_report_to_printer
405+#: model:ir.actions.act_window,name:base_report_to_printer.action_printing_printer_form
406+#: model:ir.ui.menu,name:base_report_to_printer.menu_printing_printer_form
407+#: view:printing.printer:0
408+msgid "Printers"
409+msgstr "Stampanti"
410+
411+#. module: base_report_to_printer
412+#: field:res.users,printing_action:0
413+msgid "Printing Action"
414+msgstr "Azione di stampa"
415+
416+#. module: base_report_to_printer
417+#: model:ir.module.module,description:base_report_to_printer.module_meta_information
418+msgid "Extracted from printjob ( http://apps.openerp.com/addon/1727 ), this module allows to send reports to a printer attached to the server. Settings can be configured globaly, per user, per report and per user and report."
419+msgstr "Estratto da printjob ( http://apps.openerp.com/addon/1727 ), questo modulo permetto di inviare i report alle stampanti collegate al server. Le impostazioni possono essere configurate globalmente, per utente, per report e per utente e report."
420+
421+#. module: base_report_to_printer
422+#: field:printing.action,type:0
423+msgid "Type"
424+msgstr "Tipo"
425+
426+#. module: base_report_to_printer
427+#: selection:printing.printer,status:0
428+msgid "Available"
429+msgstr "Disponibile"
430+
431+#. module: base_report_to_printer
432+#: field:ir.actions.report.xml,printing_printer_id:0
433+#: model:ir.model,name:base_report_to_printer.model_printing_printer
434+#: field:printing.report.xml.action,printer_id:0
435+msgid "Printer"
436+msgstr "Stampante"
437+
438+#. module: base_report_to_printer
439+#: model:ir.model,name:base_report_to_printer.model_printing_report_xml_action
440+#: view:printing.report.xml.action:0
441+msgid "Report Printing Actions"
442+msgstr "Azioni di stampa report"
443+
444+#. module: base_report_to_printer
445+#: model:ir.model,name:base_report_to_printer.model_printing_action
446+msgid "Print Job Action"
447+msgstr "Azione di stampa"
448+
449+#. module: base_report_to_printer
450+#: field:printing.report.xml.action,user_id:0
451+msgid "User"
452+msgstr "Utente"
453+
454+#. module: base_report_to_printer
455+#: field:printing.report.xml.action,report_id:0
456+msgid "Report"
457+msgstr "Report"
458+
459+#. module: base_report_to_printer
460+#: model:ir.ui.menu,name:base_report_to_printer.menu_printing_config
461+msgid "Configuration"
462+msgstr "Configurazione"
463+
464+#. module: base_report_to_printer
465+#: model:ir.module.module,shortdesc:base_report_to_printer.module_meta_information
466+msgid "Report to printer"
467+msgstr "Report alla stampante"
468+
469+#. module: base_report_to_printer
470+#: model:ir.model,name:base_report_to_printer.model_printjob_printer_update_wizard
471+msgid "printjob.printer.update.wizard"
472+msgstr "printjob.printer.update.wizard"
473+
474+#. module: base_report_to_printer
475+#: view:printing.printer.update.wizard:0
476+msgid "Ok"
477+msgstr "Ok"
478+
479+#. module: base_report_to_printer
480+#: field:printing.action,name:0
481+#: field:printing.printer,name:0
482+msgid "Name"
483+msgstr "Nome"
484+
485+#. module: base_report_to_printer
486+#: view:printing.printer:0
487+msgid "Set Default"
488+msgstr "Imposta default"
489+
490+#. module: base_report_to_printer
491+#: field:printing.printer,default:0
492+#: field:res.users,printing_printer_id:0
493+msgid "Default Printer"
494+msgstr "Stampante di default"
495+
496+#. module: base_report_to_printer
497+#: code:addons/base_report_to_printer/printing.py:189
498+#, python-format
499+msgid "Send to Client"
500+msgstr "Invia al client"
501+
502+#. module: base_report_to_printer
503+#: field:printing.printer,uri:0
504+msgid "URI"
505+msgstr "URI"
506+
507+#. module: base_report_to_printer
508+#: model:ir.model,name:base_report_to_printer.model_printing_printer_update_wizard
509+msgid "printing.printer.update.wizard"
510+msgstr "printing.printer.update.wizard"
511+
512+#. module: base_report_to_printer
513+#: model:ir.actions.act_window,name:base_report_to_printer.action_printer_update_wizard
514+#: model:ir.ui.menu,name:base_report_to_printer.menu_printer_update_wizard
515+#: view:printing.printer.update.wizard:0
516+msgid "Update Printers from CUPS"
517+msgstr "Aggiorna stampanti da CUPS"
518+
519+#. module: base_report_to_printer
520+#: code:addons/base_report_to_printer/printing.py:188
521+#, python-format
522+msgid "Send to Printer"
523+msgstr "Invia alla stampante"
524+
525+#. module: base_report_to_printer
526+#: model:ir.ui.menu,name:base_report_to_printer.menu_printing_main
527+#: selection:printing.printer,status:0
528+msgid "Printing"
529+msgstr "Stampa"
530+
531+#. module: base_report_to_printer
532+#: selection:printing.printer,status:0
533+msgid "Error"
534+msgstr "Errore"
535+
536+#. module: base_report_to_printer
537+#: field:ir.actions.report.xml,property_printing_action:0
538+#: field:printing.report.xml.action,action:0
539+msgid "Action"
540+msgstr "Azione"
541+
542+#. module: base_report_to_printer
543+#: field:printing.printer,model:0
544+msgid "Model"
545+msgstr "Model"
546+
547+#. module: base_report_to_printer
548+#: field:printing.printer,status_message:0
549+msgid "Status Message"
550+msgstr "Messaggio di stato"
551+
552+#. module: base_report_to_printer
553+#: help:ir.actions.report.xml,printing_action_ids:0
554+msgid "This field allows configuring action and printer on a per user basis"
555+msgstr "Questo campo permette di configurare azioni e stampanti sulla base degli utenti"
556+
557+#. module: base_report_to_printer
558+#: selection:printing.printer,status:0
559+msgid "Server Error"
560+msgstr "Errore server"
561+
562+#. module: base_report_to_printer
563+#: field:ir.actions.report.xml,printing_action_ids:0
564+msgid "Actions"
565+msgstr "Azioni"
566+
567+#. module: base_report_to_printer
568+#: view:printing.job:0
569+msgid "Print Jobs"
570+msgstr "Stampe"
571+
572+#. module: base_report_to_printer
573+#: view:printing.printer.update.wizard:0
574+msgid "Cancel"
575+msgstr "Annulla"
576+
577+#. module: base_report_to_printer
578+#: model:ir.model,name:base_report_to_printer.model_res_users
579+msgid "res.users"
580+msgstr "res.users"
581+
582+#. module: base_report_to_printer
583+#: code:addons/base_report_to_printer/printing.py:190
584+#, python-format
585+msgid "Use user's defaults"
586+msgstr "Utilizza i default dell'utente"
587+
588+#. module: base_report_to_printer
589+#: model:ir.model,name:base_report_to_printer.model_ir_actions_report_xml
590+msgid "ir.actions.report.xml"
591+msgstr "ir.actions.report.xml"
592+
593
594=== added file 'base_report_to_printer/printing.py'
595--- base_report_to_printer/printing.py 1970-01-01 00:00:00 +0000
596+++ base_report_to_printer/printing.py 2012-12-06 15:11:20 +0000
597@@ -0,0 +1,379 @@
598+# -*- coding: utf-8 -*-
599+##############################################################################
600+#
601+# Copyright (c) 2007 Ferran Pegueroles <ferran@pegueroles.com>
602+# Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com>
603+# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
604+# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
605+# All Rights Reserved
606+#
607+# This program is free software: you can redistribute it and/or modify
608+# it under the terms of the GNU Affero General Public License as published
609+# by the Free Software Foundation, either version 3 of the License, or
610+# (at your option) any later version.
611+#
612+# This program is distributed in the hope that it will be useful,
613+# but WITHOUT ANY WARRANTY; without even the implied warranty of
614+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
615+# GNU General Public License for more details.
616+#
617+# You should have received a copy of the GNU Affero General Public License
618+# along with this program. If not, see <http://www.gnu.org/licenses/>.
619+#
620+##############################################################################
621+
622+import os
623+import base64
624+import threading
625+from tempfile import mkstemp
626+
627+import cups
628+import thread
629+from threading import Thread
630+from threading import Lock
631+
632+import netsvc
633+import tools
634+import time
635+from osv import fields
636+from osv import osv
637+import pooler
638+import tools
639+from tools.translate import _
640+from base_calendar import base_calendar
641+import logging
642+
643+
644+#
645+# Printers
646+#
647+class printing_printer(osv.osv):
648+ _name = "printing.printer"
649+ _description = "Printer"
650+
651+ _columns = {
652+ 'name' : fields.char('Name',size=64,required=True,select="1"),
653+ 'system_name': fields.char('System Name',size=64,required=True,select="1"),
654+ 'default':fields.boolean('Default Printer',required=True,readonly=True),
655+ 'status': fields.selection([('unavailable','Unavailable'),('printing','Printing'),('unknown','Unknown'),('available','Available'),('error','Error'),('server-error','Server Error')], 'Status', required=True, readonly=True),
656+ 'status_message': fields.char('Status Message', size=500, readonly=True),
657+ 'model': fields.char('Model', size=500, readonly=True),
658+ 'location': fields.char('Location', size=500, readonly=True),
659+ 'uri': fields.char('URI', size=500, readonly=True),
660+ }
661+ _order = "name"
662+
663+ _defaults = {
664+ 'default': lambda *a: False,
665+ 'status': lambda *a: 'unknown',
666+ }
667+
668+ def __init__(self, pool, cr):
669+ super(printing_printer, self).__init__(pool, cr)
670+ self.lock = Lock()
671+ self.last_update = None
672+ self.updating = False
673+
674+ def update_printers_status(self, db_name, uid, context):
675+ db, pool = pooler.get_db_and_pool(db_name)
676+ cr = db.cursor()
677+
678+ try:
679+ connection = cups.Connection()
680+ printers = connection.getPrinters()
681+ server_error = False
682+ except:
683+ server_error = True
684+
685+ mapping = {
686+ 3 : 'available',
687+ 4 : 'printing',
688+ 5 : 'error'
689+ }
690+
691+ try:
692+ # Skip update to avoid the thread being created again
693+ ctx = context.copy()
694+ ctx['skip_update'] = True
695+ ids = self.pool.get('printing.printer').search(cr, uid, [], context=ctx)
696+ for printer in self.pool.get('printing.printer').browse(cr, uid, ids, context=ctx):
697+ vals = {}
698+ if server_error:
699+ status = 'server-error'
700+ elif printer.system_name in printers:
701+ info = printers[printer.system_name]
702+ status = mapping.get( info['printer-state'], 'unknown' )
703+ vals = {
704+ 'model': info.get('printer-make-and-model', False),
705+ 'location': info.get('printer-location', False),
706+ 'uri': info.get('device-uri', False),
707+ }
708+ else:
709+ status = 'unavailable'
710+
711+ vals['status'] = status
712+ self.pool.get('printing.printer').write(cr, uid, [printer.id], vals, context)
713+ cr.commit()
714+ except:
715+ cr.rollback()
716+ raise
717+ finally:
718+ cr.close()
719+ with self.lock:
720+ self.updating = False
721+ self.last_update = time.time()
722+
723+
724+ def start_printer_update(self, cr, uid, context):
725+ self.lock.acquire()
726+ if self.updating:
727+ self.lock.release()
728+ return
729+ self.updating = True
730+ self.lock.release()
731+ thread = Thread(target=self.update_printers_status, args=(cr.dbname, uid, context.copy()))
732+ thread.start()
733+
734+ def update(self, cr, uid, context=None):
735+ if not context or context.get('skip_update'):
736+ return
737+ self.lock.acquire()
738+ last_update = self.last_update
739+ updating = self.updating
740+ self.lock.release()
741+ now = time.time()
742+ # Only update printer status if current status is more than 10 seconds old.
743+ if not last_update or now - last_update > 10:
744+ self.start_printer_update(cr, uid, context)
745+ # Wait up to five seconds for printer status update
746+ for x in range(0,5):
747+ time.sleep(1)
748+ self.lock.acquire()
749+ updating = self.updating
750+ self.lock.release()
751+ if not updating:
752+ break
753+ return True
754+
755+ def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
756+ self.update(cr, uid, context)
757+ return super(printing_printer,self).search(cr, uid, args, offset, limit, order, context, count)
758+
759+ def read(self, cr, uid, ids, fields=None, context=None, load='_classic_read'):
760+ self.update(cr, uid, context)
761+ return super(printing_printer,self).read(cr, uid, ids, fields, context, load)
762+
763+ def browse(self, cr, uid, ids, context=None):
764+ self.update(cr, uid, context)
765+ return super(printing_printer,self).browse(cr, uid, ids, context)
766+
767+ def set_default(self, cr, uid, ids, context):
768+ if not ids:
769+ return
770+ default_ids= self.search(cr, uid,[('default','=',True)])
771+ self.write(cr, uid, default_ids, {'default':False}, context)
772+ self.write(cr, uid, ids[0], {'default':True}, context)
773+ return True
774+
775+ def get_default(self,cr,uid,context):
776+ printer_ids = self.search(cr, uid,[('default','=',True)])
777+ if printer_ids:
778+ return printer_ids[0]
779+ return False
780+
781+printing_printer()
782+
783+
784+
785+#
786+# Actions
787+#
788+
789+def _available_action_types(self, cr, uid, context=None):
790+ return [
791+ ('server',_('Send to Printer')),
792+ ('client',_('Send to Client')),
793+ ('user_default',_("Use user's defaults")),
794+ ]
795+
796+class printing_action(osv.osv):
797+ _name = 'printing.action'
798+ _description = 'Print Job Action'
799+
800+ _columns = {
801+ 'name': fields.char('Name', size=256, required=True),
802+ 'type': fields.selection(_available_action_types, 'Type', required=True),
803+ }
804+printing_action()
805+
806+#
807+# Users
808+#
809+
810+class res_users(osv.osv):
811+ _name = "res.users"
812+ _inherit = "res.users"
813+
814+ def _user_available_action_types(self, cr, uid, context=None):
815+ if context is None:
816+ context={}
817+ return [x for x in _available_action_types(self, cr, uid, context) if x[0] != 'user_default']
818+
819+ _columns = {
820+ 'printing_action': fields.selection(_user_available_action_types, 'Printing Action'),
821+ 'printing_printer_id': fields.many2one('printing.printer', 'Default Printer'),
822+ }
823+
824+res_users()
825+
826+#
827+# Reports
828+#
829+
830+class report_xml(osv.osv):
831+
832+ def print_direct(self, cr, uid, result, format, printer):
833+ fd, file_name = mkstemp()
834+ try:
835+ os.write(fd, base64.decodestring(result))
836+ finally:
837+ os.close(fd)
838+ printer_system_name = ''
839+ if printer:
840+ if isinstance(printer, (basestring)):
841+ printer_system_name = printer
842+ else:
843+ printer_system_name = printer.system_name
844+ if format == 'raw':
845+ # -l is the same as -o raw
846+ cmd = "lpr -l -P %s %s" % (printer_system_name,file_name)
847+ else:
848+ cmd = "lpr -P %s %s" % (printer_system_name,file_name)
849+ logger = logging.getLogger('base_report_to_printer')
850+ logger.info("Printing job : '%s'" % cmd)
851+ os.system(cmd)
852+ return True
853+
854+ _inherit = 'ir.actions.report.xml'
855+ _columns = {
856+ 'property_printing_action': fields.property(
857+ #'ir.actions.report.xml',
858+ 'printing.action',
859+ type='many2one',
860+ relation='printing.action',
861+ string='Action',
862+ view_load=True,
863+ method=True,
864+ ),
865+ 'printing_printer_id': fields.many2one('printing.printer', 'Printer'),
866+ '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'),
867+ }
868+
869+ def behaviour(self, cr, uid, ids, context=None):
870+ if context is None:
871+ context={}
872+ result = {}
873+
874+ # Set hardcoded default action
875+ default_action = 'client'
876+ # Retrieve system wide printer
877+ default_printer = self.pool.get('printing.printer').get_default(cr,uid,context)
878+ if default_printer:
879+ default_printer = self.pool.get('printing.printer').browse(cr,uid,default_printer,context).system_name
880+
881+
882+ # Retrieve user default values
883+ user = self.pool.get('res.users').browse(cr, uid, context)
884+ if user.printing_action:
885+ default_action = user.printing_action
886+ if user.printing_printer_id:
887+ default_printer = user.printing_printer_id.system_name
888+
889+ for report in self.browse(cr, uid, ids, context):
890+ action = default_action
891+ printer = default_printer
892+
893+ # Retrieve report default values
894+ if report.property_printing_action and report.property_printing_action.type != 'user_default':
895+ action = report.property_printing_action.type
896+ if report.printing_printer_id:
897+ printer = report.printing_printer_id
898+
899+ # Retrieve report-user specific values
900+ user_action = self.pool.get('printing.report.xml.action').behaviour(cr, uid, report.id, context)
901+ if user_action and user_action['action'] != 'user_default':
902+ action = user_action['action']
903+ if user_action['printer']:
904+ printer = user_action['printer']
905+
906+ result[report.id] = {
907+ 'action': action,
908+ 'printer': printer,
909+ }
910+ return result
911+
912+
913+report_xml()
914+
915+class report_xml_action(osv.osv):
916+ _name = 'printing.report.xml.action'
917+ _description = 'Report Printing Actions'
918+ _columns = {
919+ 'report_id': fields.many2one('ir.actions.report.xml', 'Report', required=True, ondelete='cascade'),
920+ 'user_id': fields.many2one('res.users', 'User', required=True, ondelete='cascade'),
921+ 'action': fields.selection(_available_action_types, 'Action', required=True),
922+ 'printer_id': fields.many2one('printing.printer', 'Printer'),
923+ }
924+
925+ def behaviour(self, cr, uid, report_id, context=None):
926+ if context is None:
927+ context={}
928+ result = {}
929+ ids = self.search(cr, uid, [('report_id','=',report_id),('user_id','=',uid)], context=context)
930+ if not ids:
931+ return False
932+ action = self.browse(cr, uid, ids[0], context)
933+ return {
934+ 'action': action.action,
935+ 'printer': action.printer_id.system_name,
936+ }
937+report_xml_action()
938+
939+class virtual_report_spool(base_calendar.virtual_report_spool):
940+
941+ def exp_report(self, db, uid, object, ids, datas=None, context=None):
942+ res = super(virtual_report_spool, self).exp_report(db, uid, object, ids, datas, context)
943+ self._reports[res]['report_name'] = object
944+ return res
945+
946+ def exp_report_get(self, db, uid, report_id):
947+
948+ cr = pooler.get_db(db).cursor()
949+ try:
950+ pool = pooler.get_pool(cr.dbname)
951+ # First of all load report defaults: name, action and printer
952+ report_obj = pool.get('ir.actions.report.xml')
953+ report = report_obj.search(cr,uid,[('report_name','=',self._reports[report_id]['report_name'])])
954+ if report:
955+ report = report_obj.browse(cr,uid,report[0])
956+ name = report.name
957+ data = report.behaviour()[report.id]
958+ action = data['action']
959+ printer = data['printer']
960+ if action != 'client':
961+ if (self._reports and self._reports.get(report_id, False) and self._reports[report_id].get('result', False)
962+ and self._reports[report_id].get('format', False)):
963+ report_obj.print_direct(cr, uid, base64.encodestring(self._reports[report_id]['result']),
964+ self._reports[report_id]['format'], printer)
965+ except:
966+ cr.rollback()
967+ raise
968+ finally:
969+ cr.close()
970+
971+ res = super(virtual_report_spool, self).exp_report_get(db, uid, report_id)
972+ return res
973+
974+virtual_report_spool()
975+
976+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
977
978=== added file 'base_report_to_printer/printing_data.xml'
979--- base_report_to_printer/printing_data.xml 1970-01-01 00:00:00 +0000
980+++ base_report_to_printer/printing_data.xml 2012-12-06 15:11:20 +0000
981@@ -0,0 +1,20 @@
982+<?xml version="1.0"?>
983+<openerp>
984+<data>
985+ <!-- printing.action -->
986+ <record model="printing.action" id="printing_action_1">
987+ <field name="name">Send to Printer</field>
988+ <field name="type">server</field>
989+ </record>
990+ <record model="printing.action" id="printing_action_2">
991+ <field name="name">Send to Client</field>
992+ <field name="type">client</field>
993+ </record>
994+ <!-- properties -->
995+ <record forcecreate="True" id="property_printing_action" model="ir.property">
996+ <field name="name">property_printing_action</field>
997+ <field name="fields_id" search="[('model','=','ir.actions.report.xml'),('name','=','property_printing_action')]"/>
998+ <field name="value" eval="'printing.action,'+str(printing_action_2)"/>
999+ </record>
1000+</data>
1001+</openerp>
1002
1003=== added file 'base_report_to_printer/printing_view.xml'
1004--- base_report_to_printer/printing_view.xml 1970-01-01 00:00:00 +0000
1005+++ base_report_to_printer/printing_view.xml 2012-12-06 15:11:20 +0000
1006@@ -0,0 +1,113 @@
1007+<?xml version="1.0"?>
1008+<openerp>
1009+<data>
1010+
1011+ <menuitem name="Printing" id="menu_printing_main" icon="STOCK_PRINT" parent="base.menu_custom"/>
1012+
1013+ <menuitem name="Configuration" id="menu_printing_config" parent="menu_printing_main" />
1014+
1015+ <record model="ir.ui.view" id="view_printing_printer_form">
1016+ <field name="name">printing.printer.form</field>
1017+ <field name="model">printing.printer</field>
1018+ <field name="type">form</field>
1019+ <field name="arch" type="xml">
1020+ <form string="Printers">
1021+ <field name="name" select="1"/>
1022+ <field name="system_name" select="1"/>
1023+ <group col="3" colspan="2">
1024+ <field name="default" select="1"/>
1025+ <button name="set_default" string="Set Default" type="object"/>
1026+ </group>
1027+ <field name="uri" select="2"/>
1028+ <field name="model" select="2"/>
1029+ <field name="location" select="2"/>
1030+ <field name="status" select="1"/>
1031+ <field name="status_message" select="2"/>
1032+ </form>
1033+ </field>
1034+ </record>
1035+
1036+ <record model="ir.ui.view" id="view_printing_printer_tree">
1037+ <field name="name">printing.printer.tree</field>
1038+ <field name="model">printing.printer</field>
1039+ <field name="type">tree</field>
1040+ <field name="arch" type="xml">
1041+ <tree string="Printers" colors="green:status=='available'; orange:status=='printing'; red:1;">
1042+ <field name="default"/>
1043+ <field name="name"/>
1044+ <field name="system_name"/>
1045+ <field name="status"/>
1046+ </tree>
1047+ </field>
1048+ </record>
1049+
1050+ <record model="ir.actions.act_window" id="action_printing_printer_form">
1051+ <field name="name">Printers</field>
1052+ <field name="res_model">printing.printer</field>
1053+ <field name="view_type">form</field>
1054+ <field name="view_mode">tree,form</field>
1055+ <field name="auto_refresh">20</field>
1056+ </record>
1057+
1058+ <menuitem name="Printers"
1059+ id="menu_printing_printer_form"
1060+ parent="menu_printing_config"
1061+ icon="STOCK_PRINT"
1062+ action="action_printing_printer_form"/>
1063+
1064+ <record model="ir.ui.view" id="action_report_xml_form">
1065+ <field name="name">ir.actions.report.xml.printing</field>
1066+ <field name="model">ir.actions.report.xml</field>
1067+ <field name="type">form</field>
1068+ <field name="inherit_id" ref="base.act_report_xml_view" />
1069+ <field name="arch" type="xml">
1070+ <field name="groups_id" position="before">
1071+ <field name="property_printing_action"/>
1072+ <field name="printing_printer_id"/>
1073+ <field name="printing_action_ids" colspan="4"/>
1074+ </field>
1075+ </field>
1076+ </record>
1077+
1078+ <!-- res.users -->
1079+ <record model="ir.ui.view" id="view_printing_users_form">
1080+ <field name="name">res.users.form.printing</field>
1081+ <field name="type">form</field>
1082+ <field name="model">res.users</field>
1083+ <field name="inherit_id" ref="base.view_users_form" />
1084+ <field name="arch" type="xml">
1085+ <field name="context_tz" position="after">
1086+ <field name="printing_action" />
1087+ <field name="printing_printer_id" />
1088+ </field>
1089+ </field>
1090+ </record>
1091+
1092+ <!-- printing.report.xml.action -->
1093+ <record model="ir.ui.view" id="printing_report_xml_action_form">
1094+ <field name="name">printing.report.xml.action.form</field>
1095+ <field name="model">printing.report.xml.action</field>
1096+ <field name="type">form</field>
1097+ <field name="arch" type="xml">
1098+ <form string="Report Printing Actions">
1099+ <field name="user_id"/>
1100+ <label string=""/>
1101+ <field name="action"/>
1102+ <field name="printer_id" select="1"/>
1103+ </form>
1104+ </field>
1105+ </record>
1106+ <record model="ir.ui.view" id="printing_report_xml_action_tree">
1107+ <field name="name">printing.report.xml.action.tree</field>
1108+ <field name="model">printing.report.xml.action</field>
1109+ <field name="type">tree</field>
1110+ <field name="arch" type="xml">
1111+ <tree string="Report Printing Actions">
1112+ <field name="user_id"/>
1113+ <field name="action" />
1114+ <field name="printer_id" />
1115+ </tree>
1116+ </field>
1117+ </record>
1118+</data>
1119+</openerp>
1120
1121=== added directory 'base_report_to_printer/security'
1122=== added file 'base_report_to_printer/security/security.xml'
1123--- base_report_to_printer/security/security.xml 1970-01-01 00:00:00 +0000
1124+++ base_report_to_printer/security/security.xml 2012-12-06 15:11:20 +0000
1125@@ -0,0 +1,52 @@
1126+<?xml version="1.0" ?>
1127+<openerp>
1128+ <data noupdate="1">
1129+ <record id="res_groups_printingprintoperator0" model="res.groups">
1130+ <field eval="&quot;&quot;&quot;Printing / Print Operator&quot;&quot;&quot;" name="name"/>
1131+ </record>
1132+ <record id="ir_model_access_printingprintergroup1" model="ir.model.access">
1133+ <field name="model_id" ref="model_printing_printer"/>
1134+ <field eval="1" name="perm_read"/>
1135+ <field eval="&quot;&quot;&quot;printing_printer group&quot;&quot;&quot;" name="name"/>
1136+ <field eval="1" name="perm_unlink"/>
1137+ <field eval="1" name="perm_write"/>
1138+ <field eval="1" name="perm_create"/>
1139+ <field name="group_id" ref="res_groups_printingprintoperator0"/>
1140+ </record>
1141+ <record id="ir_model_access_printing_action" model="ir.model.access">
1142+ <field name="model_id" ref="model_printing_action"/>
1143+ <field eval="1" name="perm_read"/>
1144+ <field eval="&quot;&quot;&quot;printing_printer group&quot;&quot;&quot;" name="name"/>
1145+ <field eval="1" name="perm_unlink"/>
1146+ <field eval="1" name="perm_write"/>
1147+ <field eval="1" name="perm_create"/>
1148+ <field name="group_id" ref="res_groups_printingprintoperator0"/>
1149+ </record>
1150+ <record id="ir_model_access_printingreportxmlaction" model="ir.model.access">
1151+ <field name="model_id" ref="model_printing_report_xml_action"/>
1152+ <field eval="1" name="perm_read"/>
1153+ <field eval="&quot;&quot;&quot;printing_printer group&quot;&quot;&quot;" name="name"/>
1154+ <field eval="1" name="perm_unlink"/>
1155+ <field eval="1" name="perm_write"/>
1156+ <field eval="1" name="perm_create"/>
1157+ <field name="group_id" ref="res_groups_printingprintoperator0"/>
1158+ </record>
1159+ <record id="menu_printing_printer_form" model="ir.ui.menu">
1160+ <field eval="[(6,0,[ref('res_groups_printingprintoperator0')])]" name="groups_id"/>
1161+ <field eval="&quot;&quot;&quot;Printers&quot;&quot;&quot;" name="name"/>
1162+ <field eval="10" name="sequence"/>
1163+ <field name="parent_id" ref="menu_printing_config"/>
1164+ <field eval="&quot;&quot;&quot;STOCK_PRINT&quot;&quot;&quot;" name="icon"/>
1165+ </record>
1166+ </data>
1167+ <data>
1168+ <record id="ir_model_access_printingprinterall0" model="ir.model.access">
1169+ <field name="model_id" ref="model_printing_printer"/>
1170+ <field eval="1" name="perm_read"/>
1171+ <field eval="&quot;&quot;&quot;printing_printer all&quot;&quot;&quot;" name="name"/>
1172+ <field eval="0" name="perm_unlink"/>
1173+ <field eval="0" name="perm_write"/>
1174+ <field eval="0" name="perm_create"/>
1175+ </record>
1176+ </data>
1177+</openerp>
1178
1179=== added directory 'base_report_to_printer/wizard'
1180=== added file 'base_report_to_printer/wizard/__init__.py'
1181--- base_report_to_printer/wizard/__init__.py 1970-01-01 00:00:00 +0000
1182+++ base_report_to_printer/wizard/__init__.py 2012-12-06 15:11:20 +0000
1183@@ -0,0 +1,23 @@
1184+# -*- coding: utf-8 -*-
1185+##############################################################################
1186+#
1187+# Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com>
1188+# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
1189+# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
1190+# All Rights Reserved
1191+#
1192+# This program is free software: you can redistribute it and/or modify
1193+# it under the terms of the GNU Affero General Public License as published
1194+# by the Free Software Foundation, either version 3 of the License, or
1195+# (at your option) any later version.
1196+#
1197+# This program is distributed in the hope that it will be useful,
1198+# but WITHOUT ANY WARRANTY; without even the implied warranty of
1199+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1200+# GNU General Public License for more details.
1201+#
1202+# You should have received a copy of the GNU Affero General Public License
1203+# along with this program. If not, see <http://www.gnu.org/licenses/>.
1204+#
1205+##############################################################################
1206+import update_printers
1207
1208=== added file 'base_report_to_printer/wizard/update_printers.py'
1209--- base_report_to_printer/wizard/update_printers.py 1970-01-01 00:00:00 +0000
1210+++ base_report_to_printer/wizard/update_printers.py 2012-12-06 15:11:20 +0000
1211@@ -0,0 +1,76 @@
1212+# -*- coding: utf-8 -*-
1213+##############################################################################
1214+#
1215+# Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com>
1216+# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
1217+# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
1218+# All Rights Reserved
1219+#
1220+# This program is free software: you can redistribute it and/or modify
1221+# it under the terms of the GNU Affero General Public License as published
1222+# by the Free Software Foundation, either version 3 of the License, or
1223+# (at your option) any later version.
1224+#
1225+# This program is distributed in the hope that it will be useful,
1226+# but WITHOUT ANY WARRANTY; without even the implied warranty of
1227+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1228+# GNU General Public License for more details.
1229+#
1230+# You should have received a copy of the GNU Affero General Public License
1231+# along with this program. If not, see <http://www.gnu.org/licenses/>.
1232+#
1233+##############################################################################
1234+
1235+import time
1236+import subprocess
1237+import cups
1238+
1239+import netsvc
1240+from osv import fields
1241+from osv import osv
1242+from tools.translate import _
1243+
1244+
1245+class printing_printer_update_wizard(osv.osv_memory):
1246+ _name = "printing.printer.update.wizard"
1247+
1248+ _columns = {
1249+ }
1250+
1251+ def action_cancel(self, cr, uid, ids, context=None):
1252+ return {}
1253+
1254+ def action_ok(self, cr, uid, ids, context=None):
1255+ # Update Printers
1256+ try:
1257+ connection = cups.Connection()
1258+ printers = connection.getPrinters()
1259+ except:
1260+ return {}
1261+
1262+ ids = self.pool.get('printing.printer').search(cr, uid, [('system_name','in',printers.keys())], context=context)
1263+ for printer in self.pool.get('printing.printer').browse(cr, uid, ids, context):
1264+ del printers[printer.system_name]
1265+
1266+ for name in printers:
1267+ printer = printers[name]
1268+ self.pool.get('printing.printer').create(cr, uid, {
1269+ 'name': printer['printer-info'],
1270+ 'system_name': name,
1271+ 'model': printer.get('printer-make-and-model', False),
1272+ 'location': printer.get('printer-location', False),
1273+ 'uri': printer.get('device-uri', False),
1274+ }, context)
1275+
1276+ return {
1277+ 'name': 'Printers',
1278+ 'view_type': 'form',
1279+ 'view_mode': 'tree,form',
1280+ 'res_model': 'printing.printer',
1281+ 'type': 'ir.actions.act_window',
1282+ 'target': 'current',
1283+ }
1284+
1285+printing_printer_update_wizard()
1286+
1287+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
1288
1289=== added file 'base_report_to_printer/wizard/update_printers.xml'
1290--- base_report_to_printer/wizard/update_printers.xml 1970-01-01 00:00:00 +0000
1291+++ base_report_to_printer/wizard/update_printers.xml 2012-12-06 15:11:20 +0000
1292@@ -0,0 +1,26 @@
1293+<openerp>
1294+<data>
1295+ <record id="printer_update_wizard" model="ir.ui.view">
1296+ <field name="name">printing.printer.update.wizard</field>
1297+ <field name="model">printing.printer.update.wizard</field>
1298+ <field name="type">form</field>
1299+ <field name="arch" type="xml">
1300+ <form string="Update Printers from CUPS" col="2">
1301+ <label string="This process will create all missing printers from the current CUPS server." colspan="2"/>
1302+ <separator string="" colspan="2"/>
1303+ <button name="action_cancel" icon="gtk-cancel" string="Cancel" special="cancel"/>
1304+ <button name="action_ok" type="object" icon="gtk-ok" string="Ok"/>
1305+ </form>
1306+ </field>
1307+ </record>
1308+ <record id="action_printer_update_wizard" model="ir.actions.act_window">
1309+ <field name="name">Update Printers from CUPS</field>
1310+ <field name="type">ir.actions.act_window</field>
1311+ <field name="res_model">printing.printer.update.wizard</field>
1312+ <field name="view_type">form</field>
1313+ <field name="view_mode">form</field>
1314+ <field name="target">new</field>
1315+ </record>
1316+ <menuitem action="action_printer_update_wizard" id="menu_printer_update_wizard" parent="menu_printing_config"/>
1317+</data>
1318+</openerp>

Subscribers

People subscribed via source and target branches