[PEP8]
parent
1a80ccd022
commit
eae4fbbb75
|
@ -20,15 +20,17 @@
|
||||||
##############################################################################
|
##############################################################################
|
||||||
from openerp.osv import orm, fields
|
from openerp.osv import orm, fields
|
||||||
|
|
||||||
|
|
||||||
class AssembledReport(orm.Model):
|
class AssembledReport(orm.Model):
|
||||||
_name = 'assembled.report'
|
_name = 'assembled.report'
|
||||||
|
|
||||||
_order = 'sequence'
|
_order = 'sequence'
|
||||||
|
|
||||||
_columns = {
|
_columns = {
|
||||||
'report_id': fields.many2one('ir.actions.report.xml', 'Report',
|
'report_id': fields.many2one(
|
||||||
|
'ir.actions.report.xml', 'Report',
|
||||||
domain="[('model', '=', model),"
|
domain="[('model', '=', model),"
|
||||||
"('report_type', '!=', 'assemblage')]", required=True),
|
"('report_type', '!=', 'assemblage')]", required=True),
|
||||||
'model': fields.char('Object model'),
|
'model': fields.char('Object model'),
|
||||||
'sequence': fields.integer('Sequence', required=True),
|
'sequence': fields.integer('Sequence', required=True),
|
||||||
'company_id': fields.many2one('res.company', 'Company', required=True),
|
'company_id': fields.many2one('res.company', 'Company', required=True),
|
||||||
|
@ -36,5 +38,5 @@ class AssembledReport(orm.Model):
|
||||||
|
|
||||||
_defaults = {
|
_defaults = {
|
||||||
'sequence': 1,
|
'sequence': 1,
|
||||||
'company_id': lambda s,cr,uid,c: s.pool.get('res.company')._company_default_get(cr, uid, 'assembled.report', context=c)
|
'company_id': lambda s, cr, uid, c: s.pool.get('res.company')._company_default_get(cr, uid, 'assembled.report', context=c)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,12 +18,12 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
from openerp.osv import orm
|
from openerp.osv import orm
|
||||||
from openerp import netsvc
|
from openerp import netsvc
|
||||||
from openerp.report.report_sxw import rml_parse
|
from openerp.report.report_sxw import rml_parse
|
||||||
from report_assembler import PDFReportAssembler
|
from report_assembler import PDFReportAssembler
|
||||||
|
|
||||||
|
|
||||||
def register_report(name, model, parser=rml_parse):
|
def register_report(name, model, parser=rml_parse):
|
||||||
"""Register the report into the services"""
|
"""Register the report into the services"""
|
||||||
name = 'report.%s' % name
|
name = 'report.%s' % name
|
||||||
|
@ -46,7 +46,7 @@ class ReportAssembleXML(orm.Model):
|
||||||
def __init__(self, pool, cr):
|
def __init__(self, pool, cr):
|
||||||
super(ReportAssembleXML, self).__init__(pool, cr)
|
super(ReportAssembleXML, self).__init__(pool, cr)
|
||||||
|
|
||||||
def register_all(self,cursor):
|
def register_all(self, cursor):
|
||||||
value = super(ReportAssembleXML, self).register_all(cursor)
|
value = super(ReportAssembleXML, self).register_all(cursor)
|
||||||
cursor.execute("SELECT * FROM ir_act_report_xml WHERE report_type = 'assemblage'")
|
cursor.execute("SELECT * FROM ir_act_report_xml WHERE report_type = 'assemblage'")
|
||||||
records = cursor.dictfetchall()
|
records = cursor.dictfetchall()
|
||||||
|
@ -69,42 +69,40 @@ class ReportAssembleXML(orm.Model):
|
||||||
# report will fail so it's ok.
|
# report will fail so it's ok.
|
||||||
|
|
||||||
res = super(ReportAssembleXML, self).unlink(
|
res = super(ReportAssembleXML, self).unlink(
|
||||||
cursor,
|
cursor,
|
||||||
user,
|
user,
|
||||||
ids,
|
ids,
|
||||||
context
|
context)
|
||||||
)
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def create(self, cursor, user, vals, context=None):
|
def create(self, cursor, user, vals, context=None):
|
||||||
"Create report and register it"
|
"Create report and register it"
|
||||||
res = super(ReportAssembleXML, self).create(cursor, user, vals, context)
|
res = super(ReportAssembleXML, self).create(cursor, user, vals, context)
|
||||||
if vals.get('report_type','') == 'assemblage':
|
if vals.get('report_type', '') == 'assemblage':
|
||||||
# I really look forward to virtual functions :S
|
# I really look forward to virtual functions :S
|
||||||
register_report(
|
register_report(
|
||||||
vals['report_name'],
|
vals['report_name'],
|
||||||
vals['model'],
|
vals['model'])
|
||||||
)
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def write(self, cr, uid, ids, vals, context=None):
|
def write(self, cr, uid, ids, vals, context=None):
|
||||||
"Edit report and manage its registration"
|
"Edit report and manage its registration"
|
||||||
if isinstance(ids, (int, long)):
|
if isinstance(ids, (int, long)):
|
||||||
ids = [ids,]
|
ids = [ids]
|
||||||
for rep in self.browse(cr, uid, ids, context=context):
|
for rep in self.browse(cr, uid, ids, context=context):
|
||||||
if rep.report_type != 'assemblage':
|
if rep.report_type != 'assemblage':
|
||||||
continue
|
continue
|
||||||
if vals.get('report_name', False) and \
|
if (vals.get('report_name', False)
|
||||||
vals['report_name'] != rep.report_name:
|
and vals['report_name'] != rep.report_name):
|
||||||
report_name = vals['report_name']
|
report_name = vals['report_name']
|
||||||
else:
|
else:
|
||||||
report_name = rep.report_name
|
report_name = rep.report_name
|
||||||
|
|
||||||
register_report(
|
register_report(
|
||||||
report_name,
|
report_name,
|
||||||
vals.get('model', rep.model),
|
vals.get('model', rep.model),
|
||||||
False
|
False
|
||||||
)
|
)
|
||||||
res = super(ReportAssembleXML, self).write(cr, uid, ids, vals, context)
|
res = super(ReportAssembleXML, self).write(cr, uid, ids, vals, context)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
|
@ -25,10 +25,11 @@ from StringIO import StringIO
|
||||||
|
|
||||||
from openerp.netsvc import ExportService
|
from openerp.netsvc import ExportService
|
||||||
from openerp.report import report_sxw
|
from openerp.report import report_sxw
|
||||||
from openerp import pooler, sql_db
|
from openerp import pooler
|
||||||
|
|
||||||
_POLLING_DELAY = 0.25
|
_POLLING_DELAY = 0.25
|
||||||
|
|
||||||
|
|
||||||
def assemble_pdf(pdf_list):
|
def assemble_pdf(pdf_list):
|
||||||
"""
|
"""
|
||||||
Assemble a list of pdf
|
Assemble a list of pdf
|
||||||
|
@ -53,6 +54,7 @@ def assemble_pdf(pdf_list):
|
||||||
output.write(s)
|
output.write(s)
|
||||||
return s.getvalue()
|
return s.getvalue()
|
||||||
|
|
||||||
|
|
||||||
class PDFReportAssembler(report_sxw.report_sxw):
|
class PDFReportAssembler(report_sxw.report_sxw):
|
||||||
""" PDFReportAssembler allows to put 2 invoice reports in one single pdf"""
|
""" PDFReportAssembler allows to put 2 invoice reports in one single pdf"""
|
||||||
|
|
||||||
|
@ -61,7 +63,6 @@ class PDFReportAssembler(report_sxw.report_sxw):
|
||||||
Return a list of pdf encoded in base64
|
Return a list of pdf encoded in base64
|
||||||
"""
|
"""
|
||||||
pool = pooler.get_pool(cr.dbname)
|
pool = pooler.get_pool(cr.dbname)
|
||||||
db = sql_db.db_connect(cr.dbname)
|
|
||||||
report_obj = pool.get('ir.actions.report.xml')
|
report_obj = pool.get('ir.actions.report.xml')
|
||||||
|
|
||||||
spool = ExportService._services['report']
|
spool = ExportService._services['report']
|
||||||
|
@ -70,7 +71,8 @@ class PDFReportAssembler(report_sxw.report_sxw):
|
||||||
report_list = report_obj.browse(cr, uid, report_ids, context=context)
|
report_list = report_obj.browse(cr, uid, report_ids, context=context)
|
||||||
for report in report_list:
|
for report in report_list:
|
||||||
|
|
||||||
report_key = spool.exp_report(cr.dbname, uid, report.report_name, ids, datas=data, context=context)
|
report_key = spool.exp_report(cr.dbname, uid, report.report_name,
|
||||||
|
ids, datas=data, context=context)
|
||||||
while 1:
|
while 1:
|
||||||
res = spool.exp_report_get(cr.dbname, uid, report_key)
|
res = spool.exp_report_get(cr.dbname, uid, report_key)
|
||||||
if res.get('state'):
|
if res.get('state'):
|
||||||
|
@ -116,7 +118,7 @@ class PDFReportAssembler(report_sxw.report_sxw):
|
||||||
report_xml.report_sxw = None
|
report_xml.report_sxw = None
|
||||||
else:
|
else:
|
||||||
return super(PDFReportAssembler, self).create(cr, uid, ids, data, context)
|
return super(PDFReportAssembler, self).create(cr, uid, ids, data, context)
|
||||||
if report_xml.report_type != 'assemblage' :
|
if report_xml.report_type != 'assemblage':
|
||||||
return super(PDFReportAssembler, self).create(cr, uid, ids, data, context)
|
return super(PDFReportAssembler, self).create(cr, uid, ids, data, context)
|
||||||
result = self.create_source_pdf(cr, uid, ids, data, report_xml, context)
|
result = self.create_source_pdf(cr, uid, ids, data, report_xml, context)
|
||||||
if not result:
|
if not result:
|
||||||
|
|
Loading…
Reference in New Issue