From f93597330bab8b2696cbb2ae877c8ab6ba434588 Mon Sep 17 00:00:00 2001 From: SHEREEF PT Date: Fri, 16 Jun 2017 18:05:30 +0530 Subject: [PATCH] [ADD] Initial Commit --- project_code_in_task/models/project_code.py | 3 +- project_code_in_task/models/project_code.py~ | 59 ++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 project_code_in_task/models/project_code.py~ diff --git a/project_code_in_task/models/project_code.py b/project_code_in_task/models/project_code.py index f787f6662..a1eb849c4 100644 --- a/project_code_in_task/models/project_code.py +++ b/project_code_in_task/models/project_code.py @@ -36,7 +36,8 @@ class ProjectCodeTask(models.Model): def create(self, vals): if vals['project_id']: obj = self.env['project.project'].browse(vals['project_id']) - vals['name'] = obj.project_code + '/' + vals['name'] + if obj.project_code: + vals['name'] = obj.project_code + '/' + vals['name'] return super(ProjectCodeTask, self).create(vals) @api.multi diff --git a/project_code_in_task/models/project_code.py~ b/project_code_in_task/models/project_code.py~ new file mode 100644 index 000000000..f787f6662 --- /dev/null +++ b/project_code_in_task/models/project_code.py~ @@ -0,0 +1,59 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2016-TODAY Cybrosys Technologies(). +# Author: Jesni Banu() +# you can modify it under the terms of the GNU LESSER +# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. +# +# It is forbidden to publish, distribute, sublicense, or sell copies +# of the Software or modified copies of the Software. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. +# +# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE +# GENERAL PUBLIC LICENSE (LGPL v3) along with this program. +# If not, see . +# +############################################################################## +from openerp import models, fields, api, _ + + +class ProjectCode(models.Model): + _inherit = 'project.project' + + project_code = fields.Char(string='Project Code', required=True) + + +class ProjectCodeTask(models.Model): + _inherit = 'project.task' + + @api.model + def create(self, vals): + if vals['project_id']: + obj = self.env['project.project'].browse(vals['project_id']) + vals['name'] = obj.project_code + '/' + vals['name'] + return super(ProjectCodeTask, self).create(vals) + + @api.multi + def write(self, vals): + if vals.get('project_id'): + obj = self.env['project.project'].browse(vals.get('project_id')) + if obj.project_code: + if vals.get('name'): + vals['name'] = obj.project_code + '/' + vals['name'] + else: + vals['name'] = obj.project_code + '/' + self.name + else: + if not vals.get('name'): + if '/' in self.name: + s = self.name.index('/') + s += 1 + vals['name'] = self.name[s:] + elif vals.get('name'): + vals['name'] = self.project_id.project_code + '/' + vals['name'] + return super(ProjectCodeTask, self).write(vals)