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.

76 lines
4.7 KiB

  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('ir.actions.act_window', string="Dashboard", required=True,
  29. domain="[('res_model', '=', 'board.board')]"),
  30. }
  31. def default_get(self, cr, uid, fields, context=None):
  32. if context is None:
  33. context = {}
  34. if context.get('active_id'):
  35. res = super(add_mis_report_instance_dashboard, self).default_get(cr, uid, fields, context=context)
  36. # get report instance name
  37. res['name'] = self.pool['mis.report.instance'].read(cr, uid, context['active_id'], ['name'])['name']
  38. return res
  39. def action_add_to_dashboard(self, cr, uid, ids, context=None):
  40. if context is None:
  41. context = {}
  42. assert 'active_id' in context, "active_id missing in context"
  43. wizard_data = self.browse(cr, uid, ids, context=context)[0]
  44. # create the act_window corresponding to this report
  45. view_id = self.pool['ir.model.data'].get_object_reference(cr, uid, 'mis_builder', 'mis_report_instance_result_view_form')[1]
  46. report_result = self.pool['ir.actions.act_window'].create(cr, uid, {'name': 'mis.report.instance.result.view.action.%d' % context['active_id'],
  47. 'res_model': 'mis.report.instance',
  48. 'res_id': context['active_id'],
  49. 'target': 'current',
  50. 'view_mode': 'form',
  51. 'view_id': view_id})
  52. # add this result in the selected dashboard
  53. last_customization = self.pool['ir.ui.view.custom'].search(cr, uid, [('user_id', '=', uid),
  54. ('ref_id', '=', wizard_data.dashboard_id.view_id.id)], limit=1)
  55. arch = wizard_data.dashboard_id.view_id.arch
  56. if last_customization:
  57. arch = self.pool['ir.ui.view.custom'].read(cr, uid, last_customization[0], ['arch'])['arch']
  58. new_arch = etree.fromstring(arch)
  59. column = new_arch.xpath("//column")[0]
  60. column.append(etree.Element('action', {'context': str(context),
  61. 'name': str(report_result),
  62. 'string': wizard_data.name,
  63. 'view_mode': 'form'}))
  64. self.pool['ir.ui.view.custom'].create(cr, uid, {'user_id': uid,
  65. 'ref_id': wizard_data.dashboard_id.view_id.id,
  66. 'arch': etree.tostring(new_arch, pretty_print=True)})
  67. return {'type': 'ir.actions.act_window_close', }
  68. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: