Greek fiscal printing code: bind to CUPS, print.
This code now works. It still doesn't get the fiscal hash back from the job. It may also have some issues when real localized reports are used. bzr revid: p_christ@hol.gr-20101028122409-tjre1fmptnw0711q
This commit is contained in:
parent
69e0367ceb
commit
c470520c29
|
@ -56,11 +56,10 @@ class account_invoice(osv.osv):
|
|||
raise osv.except_osv(_('Invalid action !'), _('Cannot cancel invoice(s) which are already printed !'))
|
||||
return super(account_invoice,self).action_cancel(cr,uid,ids,args)
|
||||
|
||||
def action_fiscalgr_print(self, cr, uid, ids, *args):
|
||||
def action_fiscalgr_print(self, cr, uid, ids, context, *args):
|
||||
fiscalgr_obj = self.pool.get('account.fiscalgr.print')
|
||||
logger = netsvc.Logger()
|
||||
invoices = self.read(cr, uid, ids, ['id','number','state','type',
|
||||
'fiscalgr_print','property_fiscalgr_invoice_report'])
|
||||
invoices = self.read(cr, uid, ids, [])
|
||||
# First, iterate once to check if the invoices are valid for printing.
|
||||
for i in invoices:
|
||||
if not i['number']:
|
||||
|
@ -77,7 +76,7 @@ class account_invoice(osv.osv):
|
|||
|
||||
#Then, iterate again, and issue those invoices for printing
|
||||
for i in invoices:
|
||||
if fiscalgr_obj.print_invoice(cr,uid,i,self._name, i['property_fiscalgr_invoice_report']):
|
||||
if fiscalgr_obj.print_invoice(cr,uid,i,self._name,i['number'], i['property_fiscalgr_invoice_report'][0],context):
|
||||
self.write(cr,uid,i['id'],{'state':'printed'})
|
||||
logger.notifyChannel("fiscalgr", netsvc.LOG_INFO, 'printed invoice %s'%i['number'])
|
||||
|
||||
|
|
|
@ -38,9 +38,69 @@ class fiscal_print(osv.osv):
|
|||
}
|
||||
_defaults = {
|
||||
}
|
||||
def print_invoice(self,cr,uid,inv_data,inv_model, inv_report):
|
||||
|
||||
def _print_fiscal(self,cr,uid,report_id,title,format,content,context=None):
|
||||
import tempfile
|
||||
import os
|
||||
(fileno, fp_name) = tempfile.mkstemp('.'+format, 'openerp_')
|
||||
fp = file(fp_name, 'wb+')
|
||||
fp.write(content.encode('iso8859-7'))
|
||||
fp.close()
|
||||
os.close(fileno)
|
||||
PRINTER='Forol2'
|
||||
try:
|
||||
import cups
|
||||
except:
|
||||
common.message(_('Cannot talk to cups, please install pycups'))
|
||||
return False
|
||||
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,{})
|
||||
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)
|
||||
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)))
|
||||
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'):
|
||||
raise osv.except_osv(_('Cannot print!'), _('The set invoice at %d is not valid for this object.')%inv_report)
|
||||
try:
|
||||
obj = netsvc.LocalService('report.'+rep['report_name'])
|
||||
if not obj:
|
||||
raise Exception('cannot get object report.%s'% rep['report_name'])
|
||||
data = { 'model' : inv_model, 'id':inv_data['id'], 'report_type': rep['report_type']}
|
||||
(result, format) = obj.create(cr, uid, [inv_data['id'],], data, context=context)
|
||||
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)
|
||||
|
||||
#self._reports[id]['result'] = result
|
||||
#self._reports[id]['format'] = format
|
||||
#self._reports[id]['state'] = True
|
||||
except Exception, exception:
|
||||
import traceback
|
||||
import sys
|
||||
tb_s = reduce(lambda x, y: x+y, traceback.format_exception(
|
||||
sys.exc_type, sys.exc_value, sys.exc_traceback))
|
||||
logger = netsvc.Logger()
|
||||
logger.notifyChannel('web-services', netsvc.LOG_ERROR,
|
||||
'Exception: %s\n%s' % (str(exception), tb_s))
|
||||
#self._reports[id]['exception'] = exception
|
||||
#self._reports[id]['state'] = True
|
||||
raise
|
||||
#return False
|
||||
return False
|
||||
|
||||
fiscal_print()
|
||||
|
||||
|
|
Loading…
Reference in New Issue