[ADD] Project: Osv memory wizard convert (Close Task)

bzr revid: mra@tinyerp.com-20100405084437-7309p0p0p1lg9g0m
This commit is contained in:
mra (Open ERP)
2010-04-05 14:14:37 +05:30
parent c6ad3b5751
commit 84c1940f7b
8 changed files with 148 additions and 119 deletions
+2 -1
View File
@@ -40,7 +40,8 @@ works done on tasks, eso. It is able to render planning, order tasks, eso.
"project_report.xml",
"process/task_process.xml",
"project_installer.xml",
"report/project_report_view.xml"
"report/project_report_view.xml",
"wizard/project_close_task_view.xml",
],
'demo_xml': [
'project_demo.xml'
+19
View File
@@ -358,6 +358,8 @@ class task(osv.osv):
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)
for task in tasks:
@@ -373,6 +375,9 @@ class task(osv.osv):
'ref_doc1': 'project.task,%d'% (task.id,),
'ref_doc2': 'project.project,%d'% (project.id,),
})
elif project.warn_manager:
task_id = ids[0]
mail_send = True
self.write(cr, uid, [task.id], {'state': 'done', 'date_end':time.strftime('%Y-%m-%d %H:%M:%S'), 'remaining_hours': 0.0})
for parent_id in task.parent_ids:
if parent_id.state in ('pending','draft'):
@@ -382,6 +387,20 @@ 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']
return {
'name': _('Email Send to Customer'),
'view_type': 'form',
'context': {'task_id': task_id,}, # improve me
'view_mode': 'tree,form',
'res_model': 'close.task',
'views': [(resource_id,'form')],
'type': 'ir.actions.act_window',
'target': 'new',
'nodestroy': True
}
return True
def do_reopen(self, cr, uid, ids, *args):
+4 -2
View File
@@ -271,7 +271,8 @@
<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="%(wizard_delegate_task)d" states="pending,open" string="Delegate" type="action" icon="gtk-sort-descending"/>
<button name="%(wizard_close_task)d" states="pending,open" string="Done" type="action" icon="gtk-jump-to"/>
<!--<button name="%(wizard_close_task)d" states="pending,open" string="Done" type="action" icon="gtk-jump-to"/>-->
<button name="do_close" states="pending,open" string="Done" type="object" icon="gtk-jump-to"/>
<button name="do_cancel" states="draft,open,pending" string="Cancel" type="object" icon="gtk-cancel"/>
</group>
</page>
@@ -350,7 +351,8 @@
<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="%(wizard_delegate_task)d" states="pending,open,draft" string="Delegate" type="action" icon="gtk-execute" help="For changing to delegate state"/>
<button name="%(wizard_close_task)d" states="draft,pending,open" string="Done" type="action" icon="gtk-jump-to" help="For changing to done state"/>
<!--<button name="%(wizard_close_task)d" states="draft,pending,open" string="Done" type="action" icon="gtk-jump-to" help="For changing to done state"/>-->
<button name="do_close" states="draft,pending,open" string="Done" type="object" icon="gtk-jump-to" 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>
+1 -1
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<wizard id="wizard_close_task" menu="False" model="project.task" name="project.task.close" string="Close Task"/>
<!--<wizard id="wizard_close_task" menu="False" model="project.task" name="project.task.close" string="Close Task"/>-->
<wizard id="wizard_delegate_task" menu="False" model="project.task" name="project.task.delegate" string="Delegate Task"/>
<wizard
id="wizard_duplicate_template"
+1 -1
View File
@@ -19,7 +19,7 @@
#
##############################################################################
import close_task
import project_close_task
import task_delegate
import duplicate_template_wizard
-114
View File
@@ -1,114 +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 wizard
from tools import email_send as email
import pooler
from osv import osv
from tools.translate import _
mail_form = """<?xml version="1.0" ?>
<form string="Send mail to customer">
<field name="email" colspan="4"/>
<field name="description" colspan="4"/>
</form>"""
mail_fields = {
'email': {'string': 'E-Mails', 'type': 'char', 'required': 'True', 'size':64},
'description': {'string':'Description', 'type':'text', 'required':'True'},
}
def email_send(cr, uid, ids, to_adr, description, context={}):
pool = pooler.get_pool(cr.dbname)
for task in pool.get('project.task').browse(cr, uid, ids, 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 wizard.except_wizard(_('Error'), _("Couldn't send mail because your email address is not configured!"))
if to_adr:
val = {
'name': task.name,
'user_id': task.user_id.name,
'task_id': "%d/%d" % (project.id, task.id),
'date_start': task.date_start,
'date_close': task.date_close,
'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)
email(from_adr, [to_adr], subject, body.encode('utf-8'), email_bcc=[from_adr])
else:
raise wizard.except_wizard(_('Error'), _("Couldn't send mail because the contact for this task (%s) has no email address!") % contact.name)
class wizard_close(wizard.interface):
def _check_complete(self, cr, uid, data, context):
task = pooler.get_pool(cr.dbname).get('project.task').browse(cr, uid, data['ids'])[0]
if not (task.project_id and task.project_id.warn_customer):
return 'close'
return 'mail_ask'
def _get_data(self, cr, uid, data, context):
email = ''
task = pooler.get_pool(cr.dbname).get('project.task').browse(cr, uid, data['ids'][0])
partner_id = task.partner_id or task.project_id.partner_id
if partner_id and partner_id.address[0].email:
email = partner_id.address[0].email
return {'description': task.description or task.name, 'email':email}
def _data_send(self, cr, uid, data, context):
task_obj = pooler.get_pool(cr.dbname).get('project.task')
if data['form']['email']:
description = data['form'].get('description', False)
email_send(cr, uid, data['ids'], data['form']['email'], data['form']['description'])
return {}
def _do_close(self, cr, uid, data, context):
task_obj = pooler.get_pool(cr.dbname).get('project.task')
task_obj.do_close(cr, uid, data['ids'], context)
return {}
states = {
'init': {
'actions': [],
'result': {'type':'choice', 'next_state':_check_complete}
},
'mail_ask': {
'actions': [_get_data],
'result': {'type':'form', 'arch':mail_form, 'fields':mail_fields, 'state':[('end', 'Cancel'), ('close', 'Quiet close'), ('mail_send', 'Send Message')]},
},
'mail_send': {
'actions': [_data_send],
'result': {'type':'state', 'state':'close'},
},
'close': {
'actions': [_do_close],
'result': {'type':'state', 'state':'end'},
},
}
wizard_close('project.task.close')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -0,0 +1,87 @@
# -*- 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/>.
#
##############################################################################
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 = {
'email': fields.char('E-Mails', size=64,),
'description': fields.text('Description',),
}
def _get_email(self, cr, uid, context={}):
email = ''
task = self.pool.get('project.task').browse(cr, uid, context['active_ids'][0])
partner_id = task.partner_id or task.project_id.partner_id
if partner_id and partner_id.address[0].email:
email = partner_id.address[0].email
return email
def _get_desc(self, cr, uid, context={}):
task = self.pool.get('project.task').browse(cr, uid, context['active_ids'][0])
return task.description or task.name
_defaults={
'email': _get_email,
'description': _get_desc,
}
def confirm(self, cr, uid, ids, context={}):
if not 'task_id' in context:
return {}
close_task = self.read(cr, uid, ids[0], [])
to_adr = close_task['email']
description = close_task['description']
for task in self.pool.get('project.task').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!"))
if to_adr:
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)
email(from_adr, [to_adr], subject, body.encode('utf-8'), email_bcc=[from_adr])
else:
raise osv.except_osv(_('Error'), _("Couldn't send mail because the contact for this task (%s) has no email address!") % contact.name)
return {}
project_close_task()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -0,0 +1,34 @@
<?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">
<field name="email" />
<newline/>
<field name="description" />
<group colspan="4" col="6">
<button icon="gtk-cancel" special="cancel" string="_Cancel"/>
<button icon="gtk-ok" name="confirm" string="Send Mail" 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>