Houzefa Abbasbhay
11 years ago
5 changed files with 86 additions and 10 deletions
-
1__init__.py
-
1__openerp__.py
-
46ir_report.py
-
26ir_report.xml
-
22py3o_report.py
@ -1 +1,2 @@ |
|||
import ir_report |
|||
import py3o_report |
@ -0,0 +1,46 @@ |
|||
from base64 import b64encode |
|||
|
|||
from openerp import addons |
|||
from openerp.osv import fields, osv |
|||
from openerp.tools.translate import _ |
|||
|
|||
|
|||
class report_xml(osv.osv): |
|||
''' Inherit from ir.actions.report.xml to allow customizing the template |
|||
file. By default, the file defined when registering the report is used; |
|||
but the user can download / upload a new one. ''' |
|||
|
|||
_inherit = 'ir.actions.report.xml' |
|||
|
|||
def _get_filename(self, cr, uid, ids, field_name, arg, context): |
|||
return { |
|||
br.id: br.name + '.odt' |
|||
for br in self.browse(cr, uid, ids, context=context) |
|||
if br.report_type == 'py3o' |
|||
} |
|||
|
|||
def _get_template_data(self, cr, uid, ids, field_name, arg, context): |
|||
''' Just return the data stored in the binary field, unless it is |
|||
empty; in that case, read the template file. ''' |
|||
|
|||
return { |
|||
br.id: (br.py3o_template_data if br.py3o_template_data |
|||
else b64encode(file(addons.get_module_resource( |
|||
*br.report_file.split('/')), 'rb').read())) |
|||
for br in self.browse(cr, uid, ids, context=context) |
|||
if br.report_type == 'py3o' |
|||
} |
|||
|
|||
_columns = { |
|||
'py3o_filename': fields.function(_get_filename, |
|||
type='char', |
|||
method=True, |
|||
readonly=True), |
|||
|
|||
'py3o_template': fields.function(_get_template_data, |
|||
type='binary', |
|||
method=True, |
|||
readonly=True), |
|||
|
|||
'py3o_template_data': fields.binary(_('LibreOffice template')), |
|||
} |
@ -0,0 +1,26 @@ |
|||
<openerp> |
|||
<data> |
|||
|
|||
<!-- Inherit from base.act_report_xml_view to add py3o-related settings. --> |
|||
|
|||
<record id="py3o_report_view" model="ir.ui.view"> |
|||
<field name="name">py3o_report_view</field> |
|||
<field name="model">ir.actions.report.xml</field> |
|||
<field name="inherit_id" ref="base.act_report_xml_view" /> |
|||
<field name="arch" type="xml"> |
|||
|
|||
<xpath expr="//page[@string='Security']" position="before"> |
|||
<page string="LibreOffice template" |
|||
attrs="{'invisible': [('report_type', '!=', 'py3o')]}"> |
|||
|
|||
<field name="py3o_filename" invisible="1" /> |
|||
<field name="py3o_template" filename="py3o_filename" /> |
|||
<field name="py3o_template_data" filename="py3o_filename" /> |
|||
|
|||
</page> |
|||
</xpath> |
|||
|
|||
</field> |
|||
</record> |
|||
</data> |
|||
</openerp> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue