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.

89 lines
4.0 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # mis_builder module for OpenERP, Management Information System Builder
  5. # Copyright (C) 2014 ACSONE SA/NV (<http://acsone.eu>)
  6. #
  7. # This file is a part of mis_builder
  8. #
  9. # mis_builder is free software: you can redistribute it and/or modify
  10. # it under the terms of the GNU Affero General Public License v3 or later
  11. # as published by the Free Software Foundation, either version 3 of the
  12. # License, or (at your option) any later version.
  13. #
  14. # mis_builder is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU Affero General Public License v3 or later for more details.
  18. #
  19. # You should have received a copy of the GNU Affero General Public License
  20. # v3 or later along with this program.
  21. # If not, see <http://www.gnu.org/licenses/>.
  22. #
  23. ##############################################################################
  24. from openerp.osv import orm, fields
  25. from lxml import etree
  26. class add_mis_report_instance_dashboard(orm.TransientModel):
  27. _name = "add.mis.report.instance.dashboard.wizard"
  28. _columns = {'name': fields.char('Name', size=32, required=True),
  29. 'dashboard_id': fields.many2one(
  30. 'ir.actions.act_window',
  31. string="Dashboard", required=True,
  32. domain="[('res_model', '=', 'board.board')]"),
  33. }
  34. def default_get(self, cr, uid, fields, context=None):
  35. if context is None:
  36. context = {}
  37. if context.get('active_id'):
  38. res = super(add_mis_report_instance_dashboard, self).default_get(
  39. cr, uid, fields, context=context)
  40. # get report instance name
  41. res['name'] = self.pool['mis.report.instance'].read(
  42. cr, uid, context['active_id'], ['name'])['name']
  43. return res
  44. def action_add_to_dashboard(self, cr, uid, ids, context=None):
  45. if context is None:
  46. context = {}
  47. assert 'active_id' in context, "active_id missing in context"
  48. wizard_data = self.browse(cr, uid, ids, context=context)[0]
  49. # create the act_window corresponding to this report
  50. view_id = self.pool['ir.model.data'].get_object_reference(
  51. cr, uid, 'mis_builder', 'mis_report_instance_result_view_form')[1]
  52. report_result = self.pool['ir.actions.act_window'].create(
  53. cr, uid,
  54. {'name': 'mis.report.instance.result.view.action.%d'
  55. % context['active_id'],
  56. 'res_model': 'mis.report.instance',
  57. 'res_id': context['active_id'],
  58. 'target': 'current',
  59. 'view_mode': 'form',
  60. 'view_id': view_id})
  61. # add this result in the selected dashboard
  62. last_customization = self.pool['ir.ui.view.custom'].search(
  63. cr, uid,
  64. [('user_id', '=', uid),
  65. ('ref_id', '=', wizard_data.dashboard_id.view_id.id)], limit=1)
  66. arch = wizard_data.dashboard_id.view_id.arch
  67. if last_customization:
  68. arch = self.pool['ir.ui.view.custom'].read(
  69. cr, uid, last_customization[0], ['arch'])['arch']
  70. new_arch = etree.fromstring(arch)
  71. column = new_arch.xpath("//column")[0]
  72. column.append(etree.Element('action', {'context': str(context),
  73. 'name': str(report_result),
  74. 'string': wizard_data.name,
  75. 'view_mode': 'form'}))
  76. self.pool['ir.ui.view.custom'].create(
  77. cr, uid, {'user_id': uid,
  78. 'ref_id': wizard_data.dashboard_id.view_id.id,
  79. 'arch': etree.tostring(new_arch, pretty_print=True)})
  80. return {'type': 'ir.actions.act_window_close', }
  81. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: