_defaults = {
}
- def _print_fiscal(self,cr,uid,report_id,title,format,content,context=None):
+ def _print_fiscal(self,cr,uid,report_id,title,format,content,printer='Forol',copies=1,context=None):
import tempfile
import os
+ if not printer:
+ raise Exception(_('No printer specified for report'))
+ if not copies:
+ copies=1
(fileno, fp_name) = tempfile.mkstemp('.'+format, 'openerp_')
fp = file(fp_name, 'wb+')
fp.write(content.encode('iso8859-7'))
try:
import cups
except:
- common.message(_('Cannot talk to cups, please install pycups'))
- return False
+ raise Exception(_('Cannot talk to cups, please install pycups'))
ccon = cups.Connection()
#attrs=ccon.getPrinterAttributes(name=PRINTER)
#print "Located \"%s\" at a v%s CUPS server" %(attrs['printer-make-and-model'],attrs['cups-version'])
- print 'Trying to print %s at %s'%(fp_name,PRINTER)
- job = ccon.printFile(PRINTER,fp_name,title,{})
+ #print 'Trying to print %s at %s'%(fp_name,PRINTER)
+ job = ccon.printFile(printer,fp_name,title,{'copies': str(copies)})
os.unlink(fp_name)
if job:
print 'Created job %d'% job
fprn=self.create(cr,uid,{'cups_jobid':job,'name':title,'report':report_id},context)
return True
else:
- common.message(_('Cannot print at printer %s')%PRINTER)
+ raise Exception(_('Cannot print at printer %s')%printer)
return False
def print_invoice(self,cr,uid,inv_data,inv_model,inv_title, inv_report, context):
logger=netsvc.Logger()
- logger.notifyChannel("fiscalgr", netsvc.LOG_INFO, 'printing one %s invoice '%(type(inv_report)))
+ logger.notifyChannel("fiscalgr", netsvc.LOG_DEBUG, 'printing one %s invoice '%(inv_report))
report_obj=self.pool.get('ir.actions.report.xml')
rep= report_obj.read(cr,uid,inv_report,[])
if (rep['model']!=inv_model or rep['report_type'] != 'txt'):
if (format != 'txt'):
raise Exception("Invoice format is not txt, strange")
# print result
- return self._print_fiscal(cr,uid,inv_report,inv_title,format,result.decode('utf-8'),context)
+ return self._print_fiscal(cr,uid,inv_report,title=inv_title,format=format,
+ content=result.decode('utf-8'),printer=rep['printer'],
+ copies=rep['copies'],context=context)
#self._reports[id]['result'] = result
#self._reports[id]['format'] = format
--- /dev/null
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
+# $Id$
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+from osv import fields, osv
+# import netsvc
+
+class report_xml(osv.osv):
+ _inherit = "ir.actions.report.xml"
+ _columns = {
+ # states={'open':[('readonly',False)]}
+ 'printer': fields.char('Printer', size=50, help="Preferred printer for this report. Useful for server-side printing."),
+ 'copies': fields.integer('Copies', help="Default number of copies."),
+ }
+
+report_xml()
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
\ No newline at end of file