OCA reporting engine fork for dev and update.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
4.0 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Author: Yannick Vaucher
  5. # Copyright 2013 Camptocamp SA
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. from openerp.osv import orm
  22. from openerp import netsvc
  23. from openerp.report.report_sxw import rml_parse
  24. from report_assembler import PDFReportAssembler
  25. def register_report(name, model, parser=rml_parse):
  26. """Register the report into the services"""
  27. name = 'report.%s' % name
  28. if netsvc.Service._services.get(name, False):
  29. service = netsvc.Service._services[name]
  30. if isinstance(service, PDFReportAssembler):
  31. #already instantiated properly, skip it
  32. return
  33. if hasattr(service, 'parser'):
  34. parser = service.parser
  35. del netsvc.Service._services[name]
  36. PDFReportAssembler(name, model, parser=parser)
  37. class ReportAssembleXML(orm.Model):
  38. _name = 'ir.actions.report.xml'
  39. _inherit = 'ir.actions.report.xml'
  40. def __init__(self, pool, cr):
  41. super(ReportAssembleXML, self).__init__(pool, cr)
  42. def register_all(self, cursor):
  43. value = super(ReportAssembleXML, self).register_all(cursor)
  44. cursor.execute("SELECT * FROM ir_act_report_xml WHERE report_type = 'assemblage'")
  45. records = cursor.dictfetchall()
  46. for record in records:
  47. register_report(record['report_name'], record['model'])
  48. return value
  49. def unlink(self, cursor, user, ids, context=None):
  50. """Delete report and unregister it"""
  51. trans_obj = self.pool.get('ir.translation')
  52. trans_ids = trans_obj.search(
  53. cursor,
  54. user,
  55. [('type', '=', 'report'), ('res_id', 'in', ids)]
  56. )
  57. trans_obj.unlink(cursor, user, trans_ids)
  58. # Warning: we cannot unregister the services at the moment
  59. # because they are shared across databases. Calling a deleted
  60. # report will fail so it's ok.
  61. res = super(ReportAssembleXML, self).unlink(
  62. cursor,
  63. user,
  64. ids,
  65. context)
  66. return res
  67. def create(self, cursor, user, vals, context=None):
  68. "Create report and register it"
  69. res = super(ReportAssembleXML, self).create(cursor, user, vals, context)
  70. if vals.get('report_type', '') == 'assemblage':
  71. # I really look forward to virtual functions :S
  72. register_report(
  73. vals['report_name'],
  74. vals['model'])
  75. return res
  76. def write(self, cr, uid, ids, vals, context=None):
  77. "Edit report and manage its registration"
  78. if isinstance(ids, (int, long)):
  79. ids = [ids]
  80. for rep in self.browse(cr, uid, ids, context=context):
  81. if rep.report_type != 'assemblage':
  82. continue
  83. if (vals.get('report_name', False)
  84. and vals['report_name'] != rep.report_name):
  85. report_name = vals['report_name']
  86. else:
  87. report_name = rep.report_name
  88. register_report(
  89. report_name,
  90. vals.get('model', rep.model),
  91. False
  92. )
  93. res = super(ReportAssembleXML, self).write(cr, uid, ids, vals, context)
  94. return res
  95. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: