[REF] project: refactor code for close task
bzr revid: hmo@tinyerp.com-20100827105611-4eeazhomqs2su86a
This commit is contained in:
parent
4bb4715c19
commit
de7903ffc9
|
@ -31,14 +31,13 @@
|
|||
work done on tasks, eso. It is able to render planning, order tasks, eso.
|
||||
Dashboard for project members that includes:
|
||||
* List of my open tasks
|
||||
* List of messages
|
||||
* Members list of project
|
||||
* Issues
|
||||
""",
|
||||
"init_xml": [],
|
||||
"update_xml": [
|
||||
"security/project_security.xml",
|
||||
"wizard/project_task_delegate_view.xml",
|
||||
"wizard/project_task_close_view.xml",
|
||||
"security/ir.model.access.csv",
|
||||
"project_data.xml",
|
||||
"project_view.xml",
|
||||
|
@ -46,7 +45,6 @@ work done on tasks, eso. It is able to render planning, order tasks, eso.
|
|||
"project_installer.xml",
|
||||
"res_partner_view.xml",
|
||||
"report/project_report_view.xml",
|
||||
"wizard/project_close_task_view.xml",
|
||||
"board_project_view.xml",
|
||||
'board_project_manager_view.xml'
|
||||
],
|
||||
|
|
|
@ -487,18 +487,17 @@ class task(osv.osv):
|
|||
res['fields'][f]['string'] = res['fields'][f]['string'].replace('Hours',tm)
|
||||
return res
|
||||
|
||||
def do_close(self, cr, uid, ids, *args):
|
||||
mail_send = False
|
||||
mod_obj = self.pool.get('ir.model.data')
|
||||
request = self.pool.get('res.request')
|
||||
tasks = self.browse(cr, uid, ids)
|
||||
task_id = ids[0]
|
||||
cntx = {}
|
||||
if len(args):
|
||||
cntx = args[0]
|
||||
for task in tasks:
|
||||
def do_close(self, cr, uid, ids, context=None):
|
||||
"""
|
||||
Close Task
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
request_pool = self.pool.get('res.request')
|
||||
for task in self.browse(cr, uid, ids, context=context):
|
||||
project = task.project_id
|
||||
if project:
|
||||
# Send request to project manager
|
||||
if project.warn_manager and project.user_id and (project.user_id.id != uid):
|
||||
request.create(cr, uid, {
|
||||
'name': _("Task '%s' closed") % task.name,
|
||||
|
@ -509,12 +508,7 @@ class task(osv.osv):
|
|||
'ref_doc1': 'project.task,%d'% (task.id,),
|
||||
'ref_doc2': 'project.project,%d'% (project.id,),
|
||||
})
|
||||
elif (project.warn_manager or project.warn_customer) and cntx.get('mail_send',True):
|
||||
cntx.update({'send_manager': project.warn_manager, 'send_partner': project.warn_customer})
|
||||
mail_send = True
|
||||
message = _('Task ') + " '" + task.name + "' "+ _("is Done.")
|
||||
self.log(cr, uid, task.id, message)
|
||||
|
||||
|
||||
for parent_id in task.parent_ids:
|
||||
if parent_id.state in ('pending','draft'):
|
||||
reopen = True
|
||||
|
@ -523,24 +517,10 @@ class task(osv.osv):
|
|||
reopen = False
|
||||
if reopen:
|
||||
self.do_reopen(cr, uid, [parent_id.id])
|
||||
if mail_send:
|
||||
model_data_ids = mod_obj.search(cr,uid,[('model','=','ir.ui.view'),('name','=','view_project_close_task')])
|
||||
resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'])[0]['res_id']
|
||||
cntx.update({'task_id': task_id})
|
||||
return {
|
||||
'name': _('Email Send to Customer'),
|
||||
'view_type': 'form',
|
||||
'context': cntx, # improve me
|
||||
'view_mode': 'tree,form',
|
||||
'res_model': 'close.task',
|
||||
'views': [(resource_id,'form')],
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new',
|
||||
'nodestroy': True
|
||||
}
|
||||
else:
|
||||
self.write(cr, uid, [task_id], {'state': 'done', 'date_end':time.strftime('%Y-%m-%d %H:%M:%S'), 'remaining_hours': 0.0})
|
||||
return False
|
||||
self.write(cr, uid, [task.id], {'state': 'done', 'date_end':time.strftime('%Y-%m-%d %H:%M:%S'), 'remaining_hours': 0.0})
|
||||
message = _('Task ') + " '" + task.name + "' "+ _("is Done.")
|
||||
self.log(cr, uid, task.id, message)
|
||||
return True
|
||||
|
||||
def do_reopen(self, cr, uid, ids, *args):
|
||||
request = self.pool.get('res.request')
|
||||
|
|
|
@ -267,7 +267,7 @@
|
|||
<button name="%(action_config_compute_remaining)d" states="done,cancelled" string="Reactivate" type="action" icon="gtk-convert" context="{'button_reactivate':True}" />
|
||||
<button name="do_pending" states="open" string="Pending" type="object" icon="gtk-media-pause"/>
|
||||
<button groups="base.group_extended" name="%(action_project_task_delegate)d" states="pending,open" string="Delegate" type="action" icon="gtk-sort-descending"/>
|
||||
<button name="do_close" states="pending,open" string="Done" type="object" icon="gtk-apply"/>
|
||||
<button name="%(action_project_task_close)d" states="pending,open" string="Done" type="action" icon="gtk-apply"/>
|
||||
<button name="do_cancel" states="draft,open,pending" string="Cancel" type="object" icon="gtk-cancel"/>
|
||||
</group>
|
||||
</page>
|
||||
|
@ -344,7 +344,7 @@
|
|||
<field name="state" invisible="context.get('set_visible',False)"/>
|
||||
<button name="do_open" states="pending,draft,done,cancel" string="Start Task" type="object" icon="gtk-execute" help="For changing to open state" invisible="context.get('set_visible',False)"/>
|
||||
<button groups="base.group_extended" name="%(action_project_task_delegate)d" states="pending,open,draft" string="Delegate" type="action" icon="gtk-sort-descending" help="For changing to delegate state"/>
|
||||
<button name="do_close" states="draft,pending,open" string="Done" type="object" icon="gtk-apply" help="For changing to done state"/>
|
||||
<button name="%(action_project_task_close)d" states="draft,pending,open" string="Done" type="action" icon="gtk-apply" help="For changing to done state"/>
|
||||
<button name="do_cancel" states="draft,open,pending" string="Cancel" type="object" icon="gtk-cancel" help="For cancelling the task"/>
|
||||
</tree>
|
||||
</field>
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#
|
||||
##############################################################################
|
||||
|
||||
import project_close_task
|
||||
import project_task_close
|
||||
import project_task_delegate
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -1,145 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# 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 Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import time
|
||||
|
||||
from osv import fields, osv
|
||||
from tools.translate import _
|
||||
from tools import email_send as email
|
||||
|
||||
class project_close_task(osv.osv_memory):
|
||||
"""
|
||||
Close Task
|
||||
"""
|
||||
_name = "close.task"
|
||||
_description = "Project Close Task"
|
||||
_columns = {
|
||||
'manager_email': fields.char('Manager E-Mail ID', size=64, help="Email Address of Project's Manager"),
|
||||
'partner_email': fields.char('Partner E-Mail ID', size=64, help="Email Address of Partner"),
|
||||
'description': fields.text('Description'),
|
||||
}
|
||||
|
||||
def _get_manager_email(self, cr, uid, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
email = ''
|
||||
if context.get('send_manager', False) and ('task_id' in context):
|
||||
project_id = self.pool.get('project.task').read(cr, uid, context['task_id'], ['project_id'])['project_id'][0]
|
||||
project = self.pool.get('project.project').browse(cr, uid, project_id)
|
||||
manager_id = project.user_id or False
|
||||
if manager_id and manager_id.user_email:
|
||||
email = manager_id.user_email
|
||||
return email
|
||||
|
||||
def _get_partner_email(self, cr, uid, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
email = ''
|
||||
if context.get('send_partner', False) and ('task_id' in context):
|
||||
task = self.pool.get('project.task').browse(cr, uid, context['task_id'])
|
||||
partner_id = task.partner_id or task.project_id.partner_id
|
||||
if partner_id and len(partner_id.address) and partner_id.address[0].email:
|
||||
email = partner_id.address[0].email
|
||||
return email
|
||||
|
||||
def _get_desc(self, cr, uid, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
if 'task_id' in context:
|
||||
task = self.pool.get('project.task').browse(cr, uid, context['task_id'])
|
||||
return task.description or task.name
|
||||
return ''
|
||||
|
||||
_defaults = {
|
||||
'manager_email': _get_manager_email,
|
||||
'partner_email': _get_partner_email,
|
||||
}
|
||||
|
||||
def close(self, cr, uid, ids, context=None):
|
||||
data = self.read(cr,uid,ids)[0]
|
||||
notes=data['description'] or ''
|
||||
task_pool = self.pool.get('project.task')
|
||||
user_name = self.pool.get('res.users').browse(cr, uid, uid).name
|
||||
description = _("Closed By ") + user_name + _(" At ") + time.strftime('%Y-%m-%d %H:%M:%S')
|
||||
description += "\n" + "=======================" + "\n" + notes
|
||||
if 'task_id' in context:
|
||||
task = task_pool.browse(cr, uid, context['task_id'])
|
||||
description = task.description and task.description + "\n\n" + description
|
||||
task_pool.write(cr, uid, [task.id], {
|
||||
'description': description,
|
||||
'state': 'done',
|
||||
'date_end':time.strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'remaining_hours': 0.0
|
||||
})
|
||||
return {}
|
||||
|
||||
def confirm(self, cr, uid, ids, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
if not 'task_id' in context:
|
||||
return {}
|
||||
close_task = self.read(cr, uid, ids[0], [])
|
||||
to_adr = []
|
||||
description = close_task['description']
|
||||
|
||||
if 'task_id' in context:
|
||||
if context.get('send_manager', False) and not close_task.get('manager_email', False):
|
||||
raise osv.except_osv(_('Error'), _("Please specify the email address of Project Manager."))
|
||||
|
||||
elif context.get('send_partner', False) and not close_task.get('partner_email', False):
|
||||
raise osv.except_osv(_('Error'), _("Please specify the email address of partner."))
|
||||
|
||||
else:
|
||||
task_obj = self.pool.get('project.task')
|
||||
task = task_obj.browse(cr, uid, context['task_id'], context=context)
|
||||
project = task.project_id
|
||||
subject = "Task '%s' closed" % task.name
|
||||
if task.user_id and task.user_id.address_id and task.user_id.address_id.email:
|
||||
from_adr = task.user_id.address_id.email
|
||||
signature = task.user_id.signature
|
||||
else:
|
||||
raise osv.except_osv(_('Error'), _("Couldn't send mail because your email address is not configured!"))
|
||||
val = {
|
||||
'name': task.name,
|
||||
'user_id': task.user_id.name,
|
||||
'task_id': "%d/%d" % (project.id, task.id),
|
||||
'date_start': task.date_start,
|
||||
'date_end': task.date_end,
|
||||
'state': task.state
|
||||
}
|
||||
|
||||
header = (project.warn_header or '') % val
|
||||
footer = (project.warn_footer or '') % val
|
||||
body = u'%s\n%s\n%s\n\n-- \n%s' % (header, description, footer, signature)
|
||||
to_adr.append(context.get('send_manager', '') and close_task.get('manager_email', '') or '')
|
||||
to_adr.append(context.get('send_partner', '') and close_task.get('partner_email', '') or '')
|
||||
mail_id = email(from_adr, to_adr, subject, body.encode('utf-8'), email_bcc=[from_adr])
|
||||
if not mail_id:
|
||||
raise osv.except_osv(_('Error'), _("Couldn't send mail! Check the email ids and smtp configuration settings"))
|
||||
task_obj.write(cr, uid, [task.id], {'state': 'done', 'date_end':time.strftime('%Y-%m-%d %H:%M:%S'), 'remaining_hours': 0.0})
|
||||
message = _('Task ') + " '" + task.name + "' "+ _("is Done.")
|
||||
self.log(cr, uid, task.id, message)
|
||||
|
||||
return {}
|
||||
|
||||
project_close_task()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -1,43 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<record id="view_project_close_task" model="ir.ui.view">
|
||||
<field name="name">Project Close Task</field>
|
||||
<field name="model">close.task</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Project Close Task" >
|
||||
<separator string="Send mail to the specified email address" colspan="4"/>
|
||||
<group colspan="4" col="6">
|
||||
<newline/>
|
||||
<field name="manager_email" invisible="not context.get('send_manager',False)"/>
|
||||
<newline/>
|
||||
<field name="partner_email" invisible="not context.get('send_partner',False)"/>
|
||||
<newline/>
|
||||
<separator string="Remark" colspan="4"/>
|
||||
<newline/>
|
||||
<field name="description" nolabel="1" colspan="4"/>
|
||||
</group>
|
||||
<separator string="" colspan="6"/>
|
||||
<group colspan="6" col="6">
|
||||
<button icon="gtk-close" name="confirm" string="Close" type="object"/>
|
||||
<button icon="gtk-jump-to" string="Done" name="close" type="object"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_project_close_task" model="ir.actions.act_window">
|
||||
<field name="name">Project Close Task</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">close.task</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="view_id" ref="view_project_close_task"/>
|
||||
<field name="context">{'record_id' : active_id}</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
|
@ -0,0 +1,120 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# 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 Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import time
|
||||
|
||||
from osv import fields, osv
|
||||
from tools.translate import _
|
||||
from tools import email_send as email
|
||||
|
||||
class project_task_close(osv.osv_memory):
|
||||
"""
|
||||
Close Task
|
||||
"""
|
||||
_name = "project.task.close"
|
||||
_description = "Project Close Task"
|
||||
_columns = {
|
||||
'manager_warn': fields.boolean("Warn Manager", help="Warn Manager by Email"),
|
||||
'partner_warn': fields.boolean("Warn Customer", help="Warn Customer by Email"),
|
||||
'manager_email': fields.char('Manager Email', size=128, help="Email Address of Project's Manager"),
|
||||
'partner_email': fields.char('Customer Email', size=128, help="Email Address of Customer"),
|
||||
'description': fields.text('Description'),
|
||||
}
|
||||
|
||||
def default_get(self, cr, uid, fields, context=None):
|
||||
"""
|
||||
This function gets default values
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
record_id = context and context.get('active_id', False) or False
|
||||
task_pool = self.pool.get('project.task')
|
||||
project_pool = self.pool.get('project.project')
|
||||
|
||||
res = super(project_task_close, self).default_get(cr, uid, fields, context=context)
|
||||
task = task_pool.browse(cr, uid, record_id, context=context)
|
||||
project = task.project_id
|
||||
manager = project.user_id or False
|
||||
partner = task.partner_id or task.project_id.partner_id
|
||||
|
||||
if 'description' in fields:
|
||||
res.update({'description': task.description})
|
||||
if 'manager_warn' in fields:
|
||||
res.update({'manager_warn': project.warn_manager})
|
||||
if 'partner_warn' in fields:
|
||||
res.update({'partner_warn': project.warn_customer})
|
||||
if 'manager_email' in fields:
|
||||
res.update({'manager_email': manager and manager.user_email or False})
|
||||
if partner and len(partner.address) and 'partner_email' in fields:
|
||||
res.update({'partner_email': partner.address[0].email})
|
||||
return res
|
||||
|
||||
def confirm(self, cr, uid, ids, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
|
||||
task_pool = self.pool.get('project.task')
|
||||
task_id = context.get('active_id', False)
|
||||
if not task_id:
|
||||
return {}
|
||||
task = task_pool.browse(cr, uid, task_id, context=context)
|
||||
for data in self.browse(cr, uid, ids, context=context):
|
||||
res = task_pool.do_close(cr, uid, [task.id], context=context)
|
||||
if res:
|
||||
# Send Acknowledgement by Email to Manager and Customer
|
||||
if data.manager_warn and not data.manager_email:
|
||||
raise osv.except_osv(_('Error'), _("Please specify the email address of Project Manager."))
|
||||
|
||||
elif data.partner_warn and not data.partner_email:
|
||||
raise osv.except_osv(_('Error'), _("Please specify the email address of Customer."))
|
||||
|
||||
elif data.manager_warn or data.partner_warn:
|
||||
project = task.project_id
|
||||
subject = _("Task '%s' Closed") % task.name
|
||||
if task.user_id and task.user_id.address_id and task.user_id.address_id.email:
|
||||
from_adr = task.user_id.address_id.email
|
||||
signature = task.user_id.signature
|
||||
else:
|
||||
raise osv.except_osv(_('Error'), _("Couldn't send mail because your email address is not configured!"))
|
||||
val = {
|
||||
'name': task.name,
|
||||
'user_id': task.user_id.name,
|
||||
'task_id': "%d/%d" % (project.id, task.id),
|
||||
'date_start': task.date_start,
|
||||
'date_end': task.date_end,
|
||||
'state': task.state
|
||||
}
|
||||
|
||||
header = (project.warn_header or '') % val
|
||||
footer = (project.warn_footer or '') % val
|
||||
body = u'%s\n%s\n%s\n\n-- \n%s' % (header, description, footer, signature)
|
||||
if data.manager_warn and data.manager_email:
|
||||
to_adr.append(data.manager_email)
|
||||
if data.partner_warn and data.partner_email:
|
||||
to_adr.append(data.partner_email)
|
||||
mail_id = email(from_adr, to_adr, subject, tools.ustr(body), email_bcc=[from_adr])
|
||||
if not mail_id:
|
||||
raise osv.except_osv(_('Error'), _("Couldn't send mail! Check the email ids and smtp configuration settings"))
|
||||
return {}
|
||||
|
||||
project_task_close()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -0,0 +1,42 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<record id="view_project_task_close" model="ir.ui.view">
|
||||
<field name="name">Done Task</field>
|
||||
<field name="model">project.task.close</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Done Task" >
|
||||
<separator string="Done Task and Inform to Project Manager or Customer by Email " colspan="4"/>
|
||||
<group colspan="4" col="4">
|
||||
<field name="manager_warn" invisible="1"/>
|
||||
<field name="manager_email" widget="email" attrs="{'invisible':[('manager_warn','=',False)], 'required':[('manager_warn','=',True)]}"/>
|
||||
<field name="partner_warn" invisible="1"/>
|
||||
<field name="partner_email" widget="email" attrs="{'invisible':[('partner_warn','=',False)], 'required':[('partner_warn','=',True)]}"/>
|
||||
<separator string="Warn Message" colspan="4"/>
|
||||
<field name="description" nolabel="1" colspan="4"/>
|
||||
</group>
|
||||
<separator string="" colspan="4"/>
|
||||
<group colspan="2" col="2">
|
||||
</group>
|
||||
<group colspan="2" col="2">
|
||||
<button icon="gtk-close" special="cancel" string="_Close"/>
|
||||
<button icon="gtk-jump-to" string="_Done" name="confirm" type="object"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_project_task_close" model="ir.actions.act_window">
|
||||
<field name="name">Done Task</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">project.task.close</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="view_id" ref="view_project_task_close"/>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
Loading…
Reference in New Issue