crm_task.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # This module uses OpenERP, Open Source Management Solution Framework.
  5. # Copyright (C) 2014-Today BrowseInfo (<http://www.browseinfo.in>)
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>
  19. #
  20. ##############################################################################
  21. from openerp.tools.translate import _
  22. from datetime import datetime, timedelta, date
  23. from dateutil.relativedelta import relativedelta
  24. from openerp import tools, api
  25. from openerp.tools import DEFAULT_SERVER_DATE_FORMAT
  26. from openerp import api, fields, models, _
  27. import logging
  28. from openerp.osv import osv
  29. from openerp import SUPERUSER_ID
  30. class crm_lead(models.Model):
  31. """ CRM Lead Case """
  32. _inherit = "crm.lead"
  33. @api.multi
  34. def task_count(self):
  35. task_obj = self.env['project.task']
  36. self.task_number = task_obj.search_count([('lead_id', 'in', [a.id for a in self])])
  37. task_number = fields.Integer(compute='task_count', string='Tasks')
  38. class crm_task_wizard(models.TransientModel):
  39. _name = 'crm.task.wizard'
  40. def get_name(self):
  41. ctx = dict(self._context or {})
  42. active_id = ctx.get('active_id')
  43. crm_brw = self.env['crm.lead'].browse(active_id)
  44. name = crm_brw.name
  45. return name
  46. project_id = fields.Many2one('project.project','Project')
  47. dead_line = fields.Date('Deadline')
  48. name = fields.Char('Task Name',default = get_name)
  49. user_id = fields.Many2one('res.users','Assigned To',default=lambda self: self.env.uid,
  50. index=True, track_visibility='always')
  51. @api.one
  52. def create_task(self):
  53. ctx = dict(self._context or {})
  54. active_id = ctx.get('active_id')
  55. crm_brw = self.env['crm.lead'].browse(active_id)
  56. vals = {'name': self.name,
  57. 'project_id':self.project_id.id or False,
  58. 'user_id': self.user_id.id or False,
  59. 'date_deadline': self.dead_line or False,
  60. 'partner_id': crm_brw.partner_id.id or False,
  61. 'lead_id': crm_brw.id or False
  62. }
  63. self.env['project.task'].create(vals)
  64. class project_Task(models.Model):
  65. _inherit='project.task'
  66. lead_id = fields.Many2one('crm.lead', 'Opportunity')