dashboard.py 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Cybrosys Technologies Pvt. Ltd.
  5. # Copyright (C) 2008-TODAY Cybrosys Technologies(<http://www.cybrosys.com>).
  6. # Author: Nilmar Shereef(<http://www.cybrosys.com>)
  7. # you can modify it under the terms of the GNU LESSER
  8. # GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
  9. #
  10. # It is forbidden to publish, distribute, sublicense, or sell copies
  11. # of the Software or modified copies of the Software.
  12. #
  13. # This program 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 LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
  17. #
  18. # You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
  19. # GENERAL PUBLIC LICENSE (LGPL v3) along with this program.
  20. # If not, see <http://www.gnu.org/licenses/>.
  21. #
  22. ##############################################################################
  23. from openerp.tools.translate import _
  24. from openerp.osv import fields, osv
  25. class CarVehicle(osv.osv):
  26. _name = 'car.car'
  27. _inherit = ['mail.thread']
  28. def _get_visibility_selection_id(self, cr, uid, context=None):
  29. """ Overriden in portal_project to offer more options """
  30. return [('portal', _('Customer Project: visible in portal if the customer is a follower')),
  31. ('employees', _('All Employees Project: all employees can access')),
  32. ('followers', _('Private Project: followers only'))]
  33. _visibility_selections = lambda self, *args, **kwargs: self._get_visibility_selection_id(*args, **kwargs)
  34. def get_task_count(self, cr, uid, ids, field_name, arg, context=None):
  35. if context is None:
  36. context = {}
  37. res = {}
  38. for vehicle in self.browse(cr, uid, ids, context=context):
  39. res[vehicle.id] = len(vehicle.task_ids)
  40. return res
  41. def _get_all_attached_docs(self, cr, uid, ids, field_name, arg, context):
  42. res = {}
  43. attachment = self.pool.get('ir.attachment')
  44. worksheet = self.pool.get('car.workshop')
  45. for id in ids:
  46. project_attachments = attachment.search(cr, uid, [('res_model', '=', 'car.car'),
  47. ('res_id', '=', id)], context=context, count=True)
  48. task_ids = worksheet.search(cr, uid, [('vehicle_id', '=', id)], context=context)
  49. task_attachments = attachment.search(cr, uid, [('res_model', '=', 'car.workshop'), ('res_id', 'in', task_ids)], context=context, count=True)
  50. res[id] = (project_attachments or 0) + (task_attachments or 0)
  51. return res
  52. def attachment_tree_views(self, cr, uid, ids, context):
  53. task_ids = self.pool.get('car.workshop').search(cr, uid, [('vehicle_id', 'in', ids)])
  54. domain = [
  55. '|',
  56. '&', ('res_model', '=', 'car.car'), ('res_id', 'in', ids),
  57. '&', ('res_model', '=', 'car.workshop'), ('res_id', 'in', task_ids)]
  58. res_id = ids and ids[0] or False
  59. return {
  60. 'name': _('Attachments'),
  61. 'domain': domain,
  62. 'res_model': 'ir.attachment',
  63. 'type': 'ir.actions.act_window',
  64. 'view_id': False,
  65. 'view_mode': 'kanban,tree,form',
  66. 'view_type': 'form',
  67. 'help': _('''<p class="oe_view_nocontent_create">
  68. Documents are attached to the tasks and issues of your project.</p><p>
  69. Send messages or log internal notes with attachments to link
  70. documents to your project.
  71. </p>'''),
  72. 'limit': 80,
  73. 'context': "{'default_res_model': '%s','default_res_id': %d}" % (self._name, res_id)
  74. }
  75. _columns = {
  76. 'active': fields.boolean(string='Active'),
  77. 'name': fields.many2one('fleet.vehicle', string='Vehicle Name', track_visibility='onchange', required=True),
  78. 'sequence': fields.integer(string='Sequence', help="Gives the sequence order when displaying a list of Projects."),
  79. 'label_tasks': fields.char(string='Use Tasks as', help="Gives label to tasks on project's kanban view."),
  80. 'worksheet': fields.one2many('car.workshop', 'vehicle_id', string="Task Activities"),
  81. 'type_ids': fields.many2many('worksheet.stages', 'car_workshop_type_rel', 'vehicle_id',
  82. 'type_id', 'Worksheet Stages',
  83. states={'close': [('readonly', True)], 'cancelled': [('readonly', True)]}),
  84. 'task_count': fields.function(get_task_count, type='integer', string="Tasks", ),
  85. 'task_ids': fields.one2many('car.workshop', 'vehicle_id',
  86. domain=['|', ('stage_id.fold', '=', False), ('stage_id', '=', False)]),
  87. 'doc_count': fields.function(_get_all_attached_docs, string="Number of documents attached", type='integer'),
  88. 'color': fields.integer('Color Index'),
  89. 'partner_id': fields.many2one('res.partner', 'Customer'),
  90. 'state': fields.selection([('draft', 'Nuevo'),
  91. ('open', 'En progreso'),
  92. ('cancelled', 'Cancelado'),
  93. ('pending', 'Pendiente'),
  94. ('close', 'Cerrado')],
  95. string='Status', required=True, track_visibility='onchange', copy=False),
  96. 'date_start': fields.date(string='Start Date'),
  97. 'date': fields.date(string='Expiration Date', select=True, track_visibility='onchange'),
  98. 'use_tasks': fields.boolean(string='Tasks'),
  99. 'image_medium': fields.related('name', 'image_medium', type="binary", string="Logo (medium)"),
  100. }
  101. _defaults = {
  102. 'active': True,
  103. 'use_tasks': True,
  104. 'label_tasks': 'Tasks',
  105. 'state': 'open',
  106. }
  107. def on_change_vehicle(self):
  108. if not self.name:
  109. return {}
  110. model = self.pool.get('fleet.vehicle').browse(self.name)
  111. return {
  112. 'value': {
  113. 'image_medium': model.image_medium,
  114. }
  115. }