Greek fiscal: add options to ir.actions.report.xml for printing.
Now, the printer name and num. of copies is stored within the report object. Note that the report object will have to be duplicated, in case of a second company or fiscal printer. bzr revid: p_christ@hol.gr-20101028122409-7fx6qe73dszs76lj
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
|
||||
import fiscal_prints
|
||||
import account_invoice_print
|
||||
import ir_actions_report
|
||||
import wizard
|
||||
import report
|
||||
|
||||
|
||||
@@ -41,5 +41,18 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="view_report_fiscalgr_inherit_1">
|
||||
<field name="name">ir.actions.report.xml.fiscalgr_1</field>
|
||||
<field name="model">ir.actions.report.xml</field>
|
||||
<field name="inherit_id" ref="base.act_report_xml_view"/>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="/form/field[@name='attachment']" position="after">
|
||||
<field name="printer"/>
|
||||
<field name="copies"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
@@ -78,7 +78,7 @@ class account_invoice(osv.osv):
|
||||
for i in invoices:
|
||||
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'])
|
||||
logger.notifyChannel("fiscalgr", netsvc.LOG_INFO, 'printed invoice ref. %s'%i['number'])
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@@ -39,9 +39,13 @@ class fiscal_print(osv.osv):
|
||||
_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'))
|
||||
@@ -51,25 +55,24 @@ class fiscal_print(osv.osv):
|
||||
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'):
|
||||
@@ -83,7 +86,9 @@ class fiscal_print(osv.osv):
|
||||
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
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
# -*- 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:
|
||||
Reference in New Issue
Block a user