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.

109 lines
4.0 KiB

9 years ago
11 years ago
11 years ago
9 years ago
11 years ago
9 years ago
11 years ago
11 years ago
11 years ago
9 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(
  45. "SELECT * FROM ir_act_report_xml WHERE report_type = 'assemblage'")
  46. records = cursor.dictfetchall()
  47. for record in records:
  48. register_report(record['report_name'], record['model'])
  49. return value
  50. def unlink(self, cursor, user, ids, context=None):
  51. """ Delete report and unregister it """
  52. trans_obj = self.pool.get('ir.translation')
  53. trans_ids = trans_obj.search(
  54. cursor,
  55. user,
  56. [('type', '=', 'report'), ('res_id', 'in', ids)]
  57. )
  58. trans_obj.unlink(cursor, user, trans_ids)
  59. # Warning: we cannot unregister the services at the moment
  60. # because they are shared across databases. Calling a deleted
  61. # report will fail so it's ok.
  62. res = super(ReportAssembleXML, self).unlink(
  63. cursor,
  64. user,
  65. ids,
  66. context)
  67. return res
  68. def create(self, cursor, user, vals, context=None):
  69. """ Create report and register it """
  70. res = super(ReportAssembleXML, self).create(
  71. cursor, user, vals, context)
  72. if vals.get('report_type', '') == 'assemblage':
  73. # I really look forward to virtual functions :S
  74. register_report(
  75. vals['report_name'],
  76. vals['model'])
  77. return res
  78. def write(self, cr, uid, ids, vals, context=None):
  79. """ Edit report and manage its registration """
  80. if isinstance(ids, (int, long)):
  81. ids = [ids]
  82. for rep in self.browse(cr, uid, ids, context=context):
  83. if rep.report_type != 'assemblage':
  84. continue
  85. if (vals.get('report_name', False)
  86. and vals['report_name'] != rep.report_name):
  87. report_name = vals['report_name']
  88. else:
  89. report_name = rep.report_name
  90. register_report(
  91. report_name,
  92. vals.get('model', rep.model),
  93. False
  94. )
  95. res = super(ReportAssembleXML, self).write(cr, uid, ids, vals, context)
  96. return res