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.

88 lines
4.4 KiB

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