base_report_to_printer V7 upgrade

This commit is contained in:
Andrew Schrafel
2013-03-14 22:30:25 -04:00
parent 458972b852
commit 56a5655680
7 changed files with 68 additions and 91 deletions

View File

@@ -25,45 +25,26 @@
'name': "Report to printer", 'name': "Report to printer",
'version': '0.1', 'version': '0.1',
'category': 'Generic Modules/Base', 'category': 'Generic Modules/Base',
'description': """ 'description': """This module allows users to send reports to a printer attached to the server. Settings can be configured globaly, per user, per report and per user and report.
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. Before you can use this module:
You must have lpr installed for this module to work as-is.
To install lpr on ubuntu enter this command at the CLI - sudo apt-get install cups-bsd
type ls | lpr at the command prompt to confirm your server can print
Configuration After installing enable the "Printing / Print Operator" option under access rights to give users the ability to view the print menu.
============= Then goto the user profile and set the users printing action and default printer.
""",
.. image:: http://planet.domsense.com/wp-content/uploads/2011/09/printing-menu.png 'author': 'Agile Business Group & Domsense, Pegueroles SCP, NaN',
:width: 400 px
First of all, you have to load CUPS printers in OpenERP. You can use a wizard that retrieves them automatically. You just have to click on Update Printers from CUPS and printers will appear within the available printers list.
In the next step you will configure the reports to send to the printers.
.. image:: http://planet.domsense.com/wp-content/uploads/2011/09/reports.png
:width: 400 px
Through the report form you can define the systems behaviour while producing the report.
.. image:: http://planet.domsense.com/wp-content/uploads/2011/09/report-configuration.png
:width: 400 px
You can set a global behaviour, or differentiate it according to the user whos printing. In the example, the global behaviour defines to send the report to client directly (Send to Client), therefore without sending it to the printer. But if user elbati is printing, the report will be sent to the selected printer (Send to Printer).
You can also define a default behaviour associated to the user, in order to establish whether a certain user, when not differently set, wants to send the reports always to a specific printer or not.
After finishing the configuration, you will just have to click on printing button associated to the report (or launch the report by a wizard or whatever) and the system will automatically send the report to the previously set printer
""",
'author': ['Agile Business Group', 'Pegueroles SCP', 'NaN'],
'website': 'http://www.agilebg.com', 'website': 'http://www.agilebg.com',
'license': 'AGPL-3', 'license': 'AGPL-3',
"depends" : ['base', 'base_calendar'], "depends" : ['base', 'base_calendar'],
"init_xml" : [], 'data': [
"update_xml" : [
'printing_data.xml', 'printing_data.xml',
'printing_view.xml', 'printing_view.xml',
'wizard/update_printers.xml', 'wizard/update_printers.xml',
'security/security.xml', 'security/security.xml',
], ],
"demo_xml" : [], 'installable': True,
"active": False, 'auto_install': False,
"installable": False 'application': True,
} }

4
base_report_to_printer/printing.py Executable file → Normal file
View File

@@ -247,8 +247,10 @@ class report_xml(osv.osv):
if format == 'raw': if format == 'raw':
# -l is the same as -o raw # -l is the same as -o raw
cmd = "lpr -l -P %s %s" % (printer_system_name,file_name) cmd = "lpr -l -P %s %s" % (printer_system_name,file_name)
#cmd = "lp -d %s %s" % (printer_system_name,file_name)
else: else:
cmd = "lpr -P %s %s" % (printer_system_name,file_name) cmd = "lpr -P %s %s" % (printer_system_name,file_name)
#cmd = "lp -d %s %s" % (printer_system_name,file_name)
logger = logging.getLogger('base_report_to_printer') logger = logging.getLogger('base_report_to_printer')
logger.info("Printing job : '%s'" % cmd) logger.info("Printing job : '%s'" % cmd)
os.system(cmd) os.system(cmd)
@@ -365,6 +367,8 @@ class virtual_report_spool(base_calendar.virtual_report_spool):
and self._reports[report_id].get('format', False)): and self._reports[report_id].get('format', False)):
report_obj.print_direct(cr, uid, base64.encodestring(self._reports[report_id]['result']), report_obj.print_direct(cr, uid, base64.encodestring(self._reports[report_id]['result']),
self._reports[report_id]['format'], printer) self._reports[report_id]['format'], printer)
raise osv.except_osv(_('Printing...'), _('Document sent to printer %s') % (printer,))
except: except:
cr.rollback() cr.rollback()
raise raise

0
base_report_to_printer/printing_data.xml Executable file → Normal file
View File

12
base_report_to_printer/printing_view.xml Executable file → Normal file
View File

@@ -2,9 +2,7 @@
<openerp> <openerp>
<data> <data>
<menuitem name="Printing" id="menu_printing_main" icon="STOCK_PRINT" parent="base.menu_custom"/> <menuitem name="Printing" id="menu_printing_main" parent="base.menu_config" groups="res_groups_printingprintoperator0"/>
<menuitem name="Configuration" id="menu_printing_config" parent="menu_printing_main" />
<record model="ir.ui.view" id="view_printing_printer_form"> <record model="ir.ui.view" id="view_printing_printer_form">
<field name="name">printing.printer.form</field> <field name="name">printing.printer.form</field>
@@ -42,7 +40,8 @@
</record> </record>
<record model="ir.actions.act_window" id="action_printing_printer_form"> <record model="ir.actions.act_window" id="action_printing_printer_form">
<field name="name">Printers</field> <field name="name">Show Printers</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">printing.printer</field> <field name="res_model">printing.printer</field>
<field name="view_type">form</field> <field name="view_type">form</field>
<field name="view_mode">tree,form</field> <field name="view_mode">tree,form</field>
@@ -51,8 +50,7 @@
<menuitem name="Printers" <menuitem name="Printers"
id="menu_printing_printer_form" id="menu_printing_printer_form"
parent="menu_printing_config" parent="menu_printing_main"
icon="STOCK_PRINT"
action="action_printing_printer_form"/> action="action_printing_printer_form"/>
<record model="ir.ui.view" id="action_report_xml_form"> <record model="ir.ui.view" id="action_report_xml_form">
@@ -76,7 +74,7 @@
<field name="model">res.users</field> <field name="model">res.users</field>
<field name="inherit_id" ref="base.view_users_form" /> <field name="inherit_id" ref="base.view_users_form" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<field name="context_tz" position="after"> <field name="lang" position="after">
<field name="printing_action" /> <field name="printing_action" />
<field name="printing_printer_id" /> <field name="printing_printer_id" />
</field> </field>

8
base_report_to_printer/security/security.xml Executable file → Normal file
View File

@@ -31,13 +31,7 @@
<field eval="1" name="perm_create"/> <field eval="1" name="perm_create"/>
<field name="group_id" ref="res_groups_printingprintoperator0"/> <field name="group_id" ref="res_groups_printingprintoperator0"/>
</record> </record>
<record id="menu_printing_printer_form" model="ir.ui.menu">
<field eval="[(6,0,[ref('res_groups_printingprintoperator0')])]" name="groups_id"/>
<field eval="&quot;&quot;&quot;Printers&quot;&quot;&quot;" name="name"/>
<field eval="10" name="sequence"/>
<field name="parent_id" ref="menu_printing_config"/>
<field eval="&quot;&quot;&quot;STOCK_PRINT&quot;&quot;&quot;" name="icon"/>
</record>
</data> </data>
<data> <data>
<record id="ir_model_access_printingprinterall0" model="ir.model.access"> <record id="ir_model_access_printingprinterall0" model="ir.model.access">

0
base_report_to_printer/wizard/update_printers.py Executable file → Normal file
View File

View File

@@ -21,6 +21,6 @@
<field name="view_mode">form</field> <field name="view_mode">form</field>
<field name="target">new</field> <field name="target">new</field>
</record> </record>
<menuitem action="action_printer_update_wizard" id="menu_printer_update_wizard" parent="menu_printing_config"/> <menuitem action="action_printer_update_wizard" id="menu_printer_update_wizard" parent="menu_printing_main"/>
</data> </data>
</openerp> </openerp>