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.

66 lines
2.7 KiB

11 years ago
11 years ago
11 years ago
  1. # -*- coding: utf-8 -*-
  2. # © 2014-2015 ACSONE SA/NV (<http://acsone.eu>)
  3. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  4. from openerp import api, fields, models
  5. from lxml import etree
  6. class AddMisReportInstanceDashboard(models.TransientModel):
  7. _name = "add.mis.report.instance.dashboard.wizard"
  8. name = fields.Char('Name', size=32, required=True)
  9. dashboard_id = fields.Many2one('ir.actions.act_window',
  10. string="Dashboard", required=True,
  11. domain="[('res_model', '=', "
  12. "'board.board')]")
  13. @api.model
  14. def default_get(self, fields):
  15. res = {}
  16. if self.env.context.get('active_id', False):
  17. res = super(AddMisReportInstanceDashboard, self).default_get(
  18. fields)
  19. # get report instance name
  20. res['name'] = self.env['mis.report.instance'].browse(
  21. self.env.context['active_id']).name
  22. return res
  23. @api.multi
  24. def action_add_to_dashboard(self):
  25. assert self.env.context.get('active_id', False), \
  26. "active_id missing in context"
  27. # create the act_window corresponding to this report
  28. self.env.ref('mis_builder.mis_report_instance_result_view_form')
  29. view = self.env.ref(
  30. 'mis_builder.mis_report_instance_result_view_form')
  31. report_result = self.env['ir.actions.act_window'].create(
  32. {'name': 'mis.report.instance.result.view.action.%d'
  33. % self.env.context['active_id'],
  34. 'res_model': 'mis.report.instance',
  35. 'res_id': self.env.context['active_id'],
  36. 'target': 'current',
  37. 'view_mode': 'form',
  38. 'view_id': view.id})
  39. # add this result in the selected dashboard
  40. last_customization = self.env['ir.ui.view.custom'].search(
  41. [('user_id', '=', self.env.uid),
  42. ('ref_id', '=', self.dashboard_id.view_id.id)], limit=1)
  43. arch = self.dashboard_id.view_id.arch
  44. if last_customization:
  45. arch = self.env['ir.ui.view.custom'].browse(
  46. last_customization[0].id).arch
  47. new_arch = etree.fromstring(arch)
  48. column = new_arch.xpath("//column")[0]
  49. column.append(etree.Element('action', {'context': str(
  50. self.env.context),
  51. 'name': str(report_result.id),
  52. 'string': self.name,
  53. 'view_mode': 'form'}))
  54. self.env['ir.ui.view.custom'].create(
  55. {'user_id': self.env.uid,
  56. 'ref_id': self.dashboard_id.view_id.id,
  57. 'arch': etree.tostring(new_arch, pretty_print=True)})
  58. return {'type': 'ir.actions.act_window_close', }