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.

97 lines
3.6 KiB

10 years ago
10 years ago
10 years ago
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # Copyright (C) 2010-2013 OpenERP s.a. (<http://openerp.com>).
  6. # Copyright (C) 2014 initOS GmbH & Co. KG (<http://www.initos.com>).
  7. # Author Markus Schneider <markus.schneider at initos.com>
  8. #
  9. # This program is free software: you can redistribute it and/or modify
  10. # it under the terms of the GNU Affero General Public License as
  11. # published by the Free Software Foundation, either version 3 of the
  12. # License, or (at your option) any later version.
  13. #
  14. # This program 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 for more details.
  18. #
  19. # You should have received a copy of the GNU Affero General Public License
  20. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. #
  22. ##############################################################################
  23. from openerp.osv import orm, fields
  24. import random
  25. class tile(orm.Model):
  26. _name = 'tile'
  27. def _get_tile_count(self, cr, uid, ids, field_name, field_value,
  28. arg, context=None):
  29. result = {}
  30. records = self.browse(cr, uid, ids)
  31. for r in records:
  32. model = self.pool.get(r.model_id.model)
  33. result[r.id] = model.search_count(cr, uid, eval(r.domain), context)
  34. return result
  35. _columns = {
  36. 'name': fields.char('Tile Name'),
  37. 'model_id': fields.many2one('ir.model', 'Model'),
  38. 'user_id': fields.many2one('res.users', 'User'),
  39. 'domain': fields.text('Domain'),
  40. 'action_id': fields.many2one('ir.actions.act_window', 'Action'),
  41. 'count': fields.function(_get_tile_count, type='int', String='Count',
  42. readonly=True),
  43. 'color': fields.char('Kanban Color')
  44. }
  45. _defaults = {
  46. 'domain': '[]',
  47. 'color': 0,
  48. }
  49. def open_link(self, cr, uid, ids, context=None):
  50. tile_id = ids[0]
  51. tile_object = self.browse(cr, uid, tile_id, context=context)
  52. if not context:
  53. context = {}
  54. if tile_object.action_id:
  55. act_obj = self.pool.get('ir.actions.act_window')
  56. result = act_obj.read(cr, uid, [tile_object.action_id.id],
  57. context=context)[0]
  58. # FIXME: restore original Domain + Filter would be better
  59. result['domain'] = tile_object.domain
  60. return result
  61. # we have no action_id stored,
  62. # so try to load a default tree view
  63. return {
  64. 'name': tile_object.name,
  65. 'view_type': 'form',
  66. 'view_mode': 'tree',
  67. 'view_id': [False],
  68. 'res_model': tile_object.model_id.model,
  69. 'type': 'ir.actions.act_window',
  70. 'context': context,
  71. 'nodestroy': True,
  72. 'target': 'current',
  73. 'domain': tile_object.domain,
  74. }
  75. def add(self, cr, uid, vals, context=None):
  76. # TODO: check if string
  77. if 'model_id' in vals:
  78. # need to replace model_name with its id
  79. model_ids = self.pool.get('ir.model').search(cr, uid,
  80. [('model', '=',
  81. vals['model_id'])])
  82. vals['model_id'] = model_ids[0]
  83. if 'color' not in vals:
  84. vals['color'] = random.randint(1, 10)
  85. return self.create(cr, uid, vals, context)