From c65d70e1680127417c21245c07ccfb87af74c549 Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Thu, 4 Sep 2008 02:22:48 +0200 Subject: [PATCH] Better Security Rules bzr revid: fp@tinyerp.com-20080904002248-vh8kpyyckkdszttn --- bin/addons/base/ir/ir.xml | 3 +++ bin/addons/base/ir/ir_actions.py | 9 +++------ bin/addons/base/ir/ir_model.py | 2 +- bin/import_xml.rng | 1 + bin/osv/orm.py | 2 ++ bin/report/report_sxw.py | 24 ++++++++++++++++++------ bin/tools/convert.py | 2 +- 7 files changed, 29 insertions(+), 14 deletions(-) diff --git a/bin/addons/base/ir/ir.xml b/bin/addons/base/ir/ir.xml index 9c1108de916..56a2fd085f4 100755 --- a/bin/addons/base/ir/ir.xml +++ b/bin/addons/base/ir/ir.xml @@ -211,6 +211,7 @@ + @@ -224,6 +225,8 @@ + + diff --git a/bin/addons/base/ir/ir_actions.py b/bin/addons/base/ir/ir_actions.py index 78abfa54ed0..3977e11f35c 100755 --- a/bin/addons/base/ir/ir_actions.py +++ b/bin/addons/base/ir/ir_actions.py @@ -128,8 +128,8 @@ class report_xml(osv.osv): ('raw', 'raw'), ('sxw', 'sxw'), ], string='Type', required=True), - 'groups_id': fields.many2many('res.groups', 'res_groups_report_rel', 'uid', 'gid', 'Groups') - + 'groups_id': fields.many2many('res.groups', 'res_groups_report_rel', 'uid', 'gid', 'Groups'), + 'attachment': fields.char('Save As Attachment Prefix', size=32, help='This is the prefix of the file name the print will be saved as attachement. Keep empty to not save the printed reports') } _defaults = { 'type': lambda *a: 'ir.actions.report.xml', @@ -138,6 +138,7 @@ class report_xml(osv.osv): 'header': lambda *a: True, 'report_sxw_content': lambda *a: False, 'report_type': lambda *a: 'pdf', + 'attachment': lambda *a: False, } report_xml() @@ -560,7 +561,3 @@ class act_window_close(osv.osv): 'type': lambda *a: 'ir.actions.act_window_close', } act_window_close() - - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: - diff --git a/bin/addons/base/ir/ir_model.py b/bin/addons/base/ir/ir_model.py index e6ec03288b3..aba96787c3a 100644 --- a/bin/addons/base/ir/ir_model.py +++ b/bin/addons/base/ir/ir_model.py @@ -365,7 +365,7 @@ class ir_model_data(osv.osv): def _get_id(self,cr, uid, module, xml_id): ids = self.search(cr, uid, [('module','=',module),('name','=', xml_id)]) - assert len(ids)==1, '%d reference(s) to %s. You should have only one !' % (len(ids),xml_id) + assert len(ids)==1, '%d reference(s) to %s. You should have one and only one !' % (len(ids),xml_id) return ids[0] _get_id = tools.cache()(_get_id) diff --git a/bin/import_xml.rng b/bin/import_xml.rng index a9d85df9917..241bb57d4d2 100644 --- a/bin/import_xml.rng +++ b/bin/import_xml.rng @@ -103,6 +103,7 @@ + diff --git a/bin/osv/orm.py b/bin/osv/orm.py index c02f0b8064f..0178c2d078a 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -493,6 +493,8 @@ class orm_template(object): (prefix == field[0:len(prefix)]): if fields_def[field[len(prefix)]]['type'] == 'integer': res = line[i] and int(line[i]) + elif fields_def[field[len(prefix)]]['type'] == 'boolean': + res = line[i] and eval(line[i]) elif fields_def[field[len(prefix)]]['type'] == 'float': res = line[i] and float(line[i]) elif fields_def[field[len(prefix)]]['type'] == 'selection': diff --git a/bin/report/report_sxw.py b/bin/report/report_sxw.py index fb9e083e85b..e54fabded1b 100644 --- a/bin/report/report_sxw.py +++ b/bin/report/report_sxw.py @@ -550,11 +550,12 @@ class rml_parse(object): return res class report_sxw(report_rml): - def __init__(self, name, table, rml, parser=rml_parse, header=True): + def __init__(self, name, table, rml, parser=rml_parse, header=True, store=False): report_rml.__init__(self, name, table, rml, '') self.name = name self.parser = parser self.header = header + self.store = store def getObjects(self, cr, uid, ids, context): table_obj = pooler.get_pool(cr.dbname).get(self.table) @@ -572,10 +573,12 @@ class report_sxw(report_rml): report_type = 'pdf' report_xml = None title='' + attach = False if report_xml_ids: - title = ir_actions_report_xml_obj.browse(cr,uid,report_xml_ids)[0].name report_xml = ir_actions_report_xml_obj.browse(cr, uid, report_xml_ids[0], context=context) + title = report_xml.name + attach = report_xml.attachment rml = report_xml.report_rml_content report_type = report_xml.report_type else: @@ -654,15 +657,24 @@ class report_sxw(report_rml): rml_parser.preprocess(objs, data, ids) rml_dom = xml.dom.minidom.parseString(rml) rml2 = rml_parser._parse(rml_dom, objs, data, header=self.header) - #if os.name != "nt": - # f = file("/tmp/debug.rml", "w") - # f.write(rml2) - # f.close() if rml_parser.logo: logo = base64.decodestring(rml_parser.logo) create_doc = self.generators[report_type] pdf = create_doc(rml2, logo,title) + + if attach: + # TODO: save multiple print with symbolic links in attach + pool.get('ir.attachment').create(cr, uid, { + 'name': title or _('print'), + 'datas': pdf, + 'datas_fname': attach+time.strftime('%Y-%m-%d')+'.'+report_type, + 'res_model': self.table, + 'res_id': ids[0] + }, context=context + ) + cr.commit() + return (pdf, report_type) diff --git a/bin/tools/convert.py b/bin/tools/convert.py index d62648f4830..427467b909d 100644 --- a/bin/tools/convert.py +++ b/bin/tools/convert.py @@ -256,7 +256,7 @@ form: module.record_id""" % (xml_id,) for dest,f in (('name','string'),('model','model'),('report_name','name')): res[dest] = rec.getAttribute(f).encode('utf8') assert res[dest], "Attribute %s of report is empty !" % (f,) - for field,dest in (('rml','report_rml'),('xml','report_xml'),('xsl','report_xsl')): + for field,dest in (('rml','report_rml'),('xml','report_xml'),('xsl','report_xsl'),('attachment','attachment')): if rec.hasAttribute(field): res[dest] = rec.getAttribute(field).encode('utf8') if rec.hasAttribute('auto'):