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.

94 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.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 tile_object.action_id:
  53. act_obj = self.pool.get('ir.actions.act_window')
  54. result = act_obj.read(cr, uid, [tile_object.action_id.id],
  55. context=context)[0]
  56. # FIXME: restore original Domain + Filter would be better
  57. result['domain'] = tile_object.domain
  58. return result
  59. # we have no action_id stored,
  60. # so try to load a default tree view
  61. return {
  62. 'name': tile_object.name,
  63. 'view_type': 'form',
  64. 'view_mode': 'tree',
  65. 'view_id': [False],
  66. 'res_model': tile_object.model_id.model,
  67. 'type': 'ir.actions.act_window',
  68. 'context': context,
  69. 'nodestroy': True,
  70. 'target': 'current',
  71. 'domain': tile_object.domain,
  72. }
  73. def add(self, cr, uid, vals, context=None):
  74. # TODO: check if string
  75. if 'model_id' in vals:
  76. # need to replace model_name with its id
  77. model_ids = self.pool.get('ir.model').search(cr, uid,
  78. [('model', '=',
  79. vals['model_id'])])
  80. vals['model_id'] = model_ids[0]
  81. if 'color' not in vals:
  82. vals['color'] = random.randint(1, 10)
  83. return self.create(cr, uid, vals, context)