Skip to content

Commit

Permalink
[ADD] module base_report_assembler
Browse files Browse the repository at this point in the history
  • Loading branch information
yvaucher committed Nov 7, 2013
1 parent a1cde42 commit bfb191e
Show file tree
Hide file tree
Showing 7 changed files with 421 additions and 0 deletions.
24 changes: 24 additions & 0 deletions base_report_assembler/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Yannick Vaucher
# Copyright 2013 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import report_assembler
from . import assembled_report
from . import ir_report

34 changes: 34 additions & 0 deletions base_report_assembler/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Yannick Vaucher
# Copyright 2013 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{'name' : 'Base Report Assembler',
'version' : '1.0',
'category': 'Report',
'description': """Defines a new type of report which is an assemblage of multiple other reports""",
'author' : 'Camptocamp',
'maintainer': 'Camptocamp',
'website': 'http://www.camptocamp.com/',
'depends' : ['base'],
'data': [],
'test': [],
'installable': True,
'auto_install': False,
'application': False,
}
40 changes: 40 additions & 0 deletions base_report_assembler/assembled_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Yannick Vaucher
# Copyright 2013 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import orm, fields

class AssembledReport(orm.Model):
_name = 'assembled.report'

_order = 'sequence'

_columns = {
'report_id': fields.many2one('ir.actions.report.xml', 'Report',
domain="[('model', '=', model),"
"('report_type', '!=', 'assemblage')]", required=True),
'model': fields.char('Object model'),
'sequence': fields.integer('Sequence', required=True),
'company_id': fields.many2one('res.company', 'Company', required=True),
}

_defaults = {
'sequence': 1,
'company_id': lambda s,cr,uid,c: s.pool.get('res.company')._company_default_get(cr, uid, 'assembled.report', context=c)
}
36 changes: 36 additions & 0 deletions base_report_assembler/i18n/base_report_assembler.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Translation of OpenERP Server.
# This file contains the translation of the following modules:
# * base_report_assembler
#
msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 7.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-11-05 14:55+0000\n"
"PO-Revision-Date: 2013-11-05 14:55+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: base_report_assembler
#: field:assembled.report,model:0
msgid "Object model"
msgstr ""

#. module: base_report_assembler
#: field:assembled.report,sequence:0
msgid "Sequence"
msgstr ""

#. module: base_report_assembler
#: field:assembled.report,company_id:0
msgid "Company"
msgstr ""

#. module: base_report_assembler
#: field:assembled.report,report_id:0
msgid "Report"
msgstr ""
37 changes: 37 additions & 0 deletions base_report_assembler/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Translation of OpenERP Server.
# This file contains the translation of the following modules:
# * base_report_assembler
#
msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 7.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-11-05 14:55+0000\n"
"PO-Revision-Date: 2013-11-05 14:55+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: base_report_assembler
#: field:assembled.report,model:0
msgid "Object model"
msgstr "Modèle d'object"

#. module: base_report_assembler
#: field:assembled.report,sequence:0
msgid "Sequence"
msgstr "Séquence"

#. module: base_report_assembler
#: field:assembled.report,company_id:0
msgid "Company"
msgstr "Companie"

#. module: base_report_assembler
#: field:assembled.report,report_id:0
msgid "Report"
msgstr "Rapport"

112 changes: 112 additions & 0 deletions base_report_assembler/ir_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Yannick Vaucher
# Copyright 2013 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from openerp.osv import orm
from openerp import netsvc
from openerp.report.report_sxw import rml_parse
from report_assembler import PDFReportAssembler

def register_report(name, model, parser=rml_parse):
"""Register the report into the services"""
name = 'report.%s' % name
if netsvc.Service._services.get(name, False):
service = netsvc.Service._services[name]
if isinstance(service, PDFReportAssembler):
#already instantiated properly, skip it
return
if hasattr(service, 'parser'):
parser = service.parser
del netsvc.Service._services[name]
PDFReportAssembler(name, model, parser=parser)


class ReportAssembleXML(orm.Model):

_name = 'ir.actions.report.xml'
_inherit = 'ir.actions.report.xml'

def __init__(self, pool, cr):
super(ReportAssembleXML, self).__init__(pool, cr)

def register_all(self,cursor):
value = super(ReportAssembleXML, self).register_all(cursor)
cursor.execute("SELECT * FROM ir_act_report_xml WHERE report_type = 'assemblage'")
records = cursor.dictfetchall()
for record in records:
register_report(record['report_name'], record['model'])
return value

def unlink(self, cursor, user, ids, context=None):
"""Delete report and unregister it"""
trans_obj = self.pool.get('ir.translation')
trans_ids = trans_obj.search(
cursor,
user,
[('type', '=', 'report'), ('res_id', 'in', ids)]
)
trans_obj.unlink(cursor, user, trans_ids)

# Warning: we cannot unregister the services at the moment
# because they are shared across databases. Calling a deleted
# report will fail so it's ok.

res = super(ReportAssembleXML, self).unlink(
cursor,
user,
ids,
context
)
return res

def create(self, cursor, user, vals, context=None):
"Create report and register it"
res = super(ReportAssembleXML, self).create(cursor, user, vals, context)
if vals.get('report_type','') == 'assemblage':
# I really look forward to virtual functions :S
register_report(
vals['report_name'],
vals['model'],
)
return res

def write(self, cr, uid, ids, vals, context=None):
"Edit report and manage its registration"
if isinstance(ids, (int, long)):
ids = [ids,]
for rep in self.browse(cr, uid, ids, context=context):
if rep.report_type != 'assemblage':
continue
if vals.get('report_name', False) and \
vals['report_name'] != rep.report_name:
report_name = vals['report_name']
else:
report_name = rep.report_name

register_report(
report_name,
vals.get('model', rep.model),
False
)
res = super(ReportAssembleXML, self).write(cr, uid, ids, vals, context)
return res


# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
Loading

0 comments on commit bfb191e

Please sign in to comment.