diff --git a/project_subtask/__manifest__.py b/project_subtask/__manifest__.py index 3e7d9b324..346813b9d 100644 --- a/project_subtask/__manifest__.py +++ b/project_subtask/__manifest__.py @@ -31,6 +31,7 @@ 'website': "http://www.cybrosys.com", 'depends': ['base', 'project'], 'data': [ + 'security/ir.model.access.csv', 'views/project_view.xml', 'views/task_view.xml', 'views/sub_task.xml', diff --git a/project_subtask/__manifest__.py~ b/project_subtask/__manifest__.py~ index 2705f11bf..3e7d9b324 100644 --- a/project_subtask/__manifest__.py~ +++ b/project_subtask/__manifest__.py~ @@ -22,7 +22,7 @@ ############################################################################## { 'name': 'Sub Tasks in Project', - 'version': '10.0.1.0.0', + 'version': '10.0.2.0.0', 'summary': """Implementation & Reports of Sub-Task in Project Module""", 'description': 'This module helps you to create sub task under a task', 'category': 'Project', diff --git a/project_subtask/models/project.py b/project_subtask/models/project.py index 91a8ee4c1..055e06e34 100644 --- a/project_subtask/models/project.py +++ b/project_subtask/models/project.py @@ -34,15 +34,40 @@ class ProjectMaster(models.Model): class SubTaskMaster(models.Model): _name = 'project.sub_task' + def stage_find(self, section_id, domain=[], order='sequence'): + section_ids = [] + if section_id: + section_ids.append(section_id) + section_ids.extend(self.mapped('task_ref').ids) + search_domain = [] + if section_ids: + search_domain = [('|')] * (len(section_ids) - 1) + for section_id in section_ids: + search_domain.append(('task_ids', '=', section_id)) + search_domain += list(domain) + # perform search, return the first found + return self.env['project.sub_task.type'].search(search_domain, order=order, limit=1).id + + @api.onchange('task_ref') + def get_default_stage_id(self): + """ Gives default stage_id """ + project_id = self.task_ref.id + if not project_id: + return False + self.stage_id = self.stage_find(project_id, [('fold', '=', False)]) + @api.constrains('date_deadline', 'task_ref') def date_deadline_validation(self): if self.date_deadline > self.task_ref.date_deadline: raise ValidationError(_("Your main task will dead at this date")) + active = fields.Boolean(default=True) name = fields.Char(string="Name", requires=True) priority = fields.Selection([('0', 'Normal'), ('1', 'High')], 'Priority', select=True, default='0') assigned_user = fields.Many2one('res.users', string="Assigned Person", required=1) - task_ref = fields.Many2one('project.task', string='Task', required=1, domain=['|', '|', ('project_id.use_sub_task', '=', True), + task_ref = fields.Many2one('project.task', string='Task', required=1, + default=lambda self: self.env.context.get('default_task_ref'), + domain=['|', '|', ('project_id.use_sub_task', '=', True), ('stage_id.done_state', '=', False), ('stage_id.cancel_state', '=', False)]) stage_id = fields.Many2one('project.sub_task.type', string='Stage', select=True, @@ -62,47 +87,26 @@ class SubTaskMaster(models.Model): tag_ids = fields.Many2one('project.sub_task.tags', string='Tags') write_date = fields.Datetime(string='Last Modification Date', readonly=True, select=True) - date_start = fields.Datetime(string='Starting Date', readonly=True, select=True) + date_start = fields.Datetime(string='Starting Date', readonly=True, select=True, default=fields.Datetime.now()) date_deadline = fields.Date(string='Deadline') active = fields.Boolean(string='Active', default=True) description = fields.Html(String='Description') sequence = fields.Integer(string='Sequence', select=True, default=10, help="Gives the sequence order when displaying a list of sub tasks.") company_id = fields.Many2one('res.company', string='Company') - date_last_stage_update = fields.Datetime(string='Last Stage Update', select=True, copy=False, readonly=True) + date_last_stage_update = fields.Datetime(string='Last Stage Update', select=True, copy=False, readonly=True, + default=fields.Datetime.now()) date_assign = fields.Datetime(string='Assigning Date', select=True, copy=False, readonly=True) - def stage_find(self, cr, uid, cases, section_id, domain=[], order='sequence', context=None): - if isinstance(cases, (int, long)): - cases = self.browse(cr, uid, cases, context=context) - section_ids = [] - if section_id: - section_ids.append(section_id) - for task in cases: - if task.project_id: - section_ids.append(task.project_id.id) - search_domain = [] - if section_ids: - search_domain = [('|')] * (len(section_ids) - 1) - for section_id in section_ids: - search_domain.append(('project_ids', '=', section_id)) - search_domain += list(domain) - stage_ids = self.pool.get('project.sub_task.type').search(cr, uid, search_domain, order=order, context=context) - if stage_ids: - return stage_ids[0] - return False - - def _get_default_stage_id(self, cr, uid, context=None): - """ Gives default stage_id """ - if context is None: - context = {} - return self.stage_find(cr, uid, [], context.get('default_project_id'), [('fold', '=', False)], context=context) - - _defaults = { - 'stage_id': _get_default_stage_id, - 'date_last_stage_update': fields.Datetime.now(), - 'date_start': fields.Datetime.now(), - } + @api.model + def create(self, vals): + context = dict(self.env.context) + if vals.get('task_ref'): + vals['stage_id'] = self.stage_find(vals.get('task_ref'), [('fold', '=', False)]) + if vals.get('user_id'): + vals['date_assign'] = fields.Datetime.now() + task = super(SubTaskMaster, self.with_context(context)).create(vals) + return task class TaskMaster(models.Model): diff --git a/project_subtask/security/ir.model.access.csv b/project_subtask/security/ir.model.access.csv new file mode 100644 index 000000000..8c2a7e6b1 --- /dev/null +++ b/project_subtask/security/ir.model.access.csv @@ -0,0 +1,7 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_project_task_type_user,project.sub_task.type.user,model_project_sub_task_type,base.group_user,1,0,0,0 +access_project_task_type_project_user,project.sub_task.type.project.user,model_project_sub_task_type,project.group_project_user,1,0,0,0 +access_project_task_type_manager,project.sub_task.type manager,model_project_sub_task_type,project.group_project_manager,1,1,1,1 +access_project_task,project.sub_task,model_project_sub_task,project.group_project_user,1,1,1,1 +access_report_project_task_user,report.project.subtask.user,model_report_project_subtask_user,project.group_project_manager,1,1,1,1 +access_task_on_partner,project.sub_task on partners,model_project_sub_task,base.group_user,1,0,0,0