[ADD+IMP] project: Made wizard for duplicate template and call it in from project...
authorHarry (Open ERP) <hmo@tinyerp.com>
Fri, 22 Jan 2010 07:41:48 +0000 (13:11 +0530)
committerHarry (Open ERP) <hmo@tinyerp.com>
Fri, 22 Jan 2010 07:41:48 +0000 (13:11 +0530)
bzr revid: hmo@tinyerp.com-20100122074148-6adgv1fp7j117fe6

addons/project/project.py
addons/project/project_view.xml
addons/project/project_wizard.xml
addons/project/wizard/__init__.py
addons/project/wizard/duplicate_template_wizard.py [new file with mode: 0644]

index c7dc5ec..9174449 100644 (file)
@@ -197,21 +197,24 @@ class project(osv.osv):
         return res
 
     def duplicate_template(self, cr, uid, ids,context={}):
+        result = []
         for proj in self.browse(cr, uid, ids):
-            parent_id=context.get('parent_id',False)
-            new_id=self.pool.get('project.project').copy(cr, uid, proj.id,default={'name':proj.name+_(' (copy)'),'state':'open','parent_id':parent_id})
+            parent_id = context.get('parent_id',False)
+            new_id = self.pool.get('project.project').copy(cr, uid, proj.id, default = {
+                                    'name': proj.name +_(' (copy)'),
+                                    'state':'open',
+                                    'parent_id':parent_id})
+            result.append(new_id)
             cr.execute('select id from project_task where project_id=%s', (proj.id,))
             res = cr.fetchall()
             for (tasks_id,) in res:
-                self.pool.get('project.task').copy(cr, uid, tasks_id,default={'project_id':new_id,'active':True}, context=context)
+                self.pool.get('project.task').copy(cr, uid, tasks_id, default = {
+                                    'project_id': new_id,
+                                    'active':True}, context=context)
             child_ids = self.search(cr, uid, [('parent_id','=', proj.id)])            
             if child_ids:
                 self.duplicate_template(cr, uid, child_ids, context={'parent_id':new_id})
-
-        # TODO : Improve this to open the new project (using a wizard)
-
-        cr.commit()
-        raise osv.except_osv(_('Operation Done'), _('A new project has been created !\nWe suggest you to close this one and work on this new project.'))
+        return result
 
     # set active value for a project, its sub projects and its tasks
     def setActive(self, cr, uid, ids, value=True, context={}):
index cde3f07..55819fb 100644 (file)
@@ -58,9 +58,9 @@
                                 <button name="set_cancel" string="Cancel" type="object" states="open,pending" icon="gtk-cancel"/>
                                 <button name="set_done" string="Done" type="object" states="open,pending" icon="gtk-jump-to"/>
                                 <button name="reset_project" string="Reset as Project" type="object" states="template" icon="gtk-convert"/>
-                                <button name="duplicate_template"
+                                <button 
                                     string="New Project Based on Template"
-                                    type="object"
+                                    name="%(wizard_duplicate_template)d"  type="action" 
                                     states="template" icon="gtk-new"/>
                             </group>
                         </page>
index 3e441e3..a9b7ade 100644 (file)
@@ -3,5 +3,10 @@
     <data>
         <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" 
+            menu="False" 
+            model="project.project" 
+            name="project.duplicate.template" string="Duplicate Template"/>
     </data>
 </openerp>
index 4618faf..b724bd6 100644 (file)
@@ -21,6 +21,7 @@
 
 import close_task
 import task_delegate
+import duplicate_template_wizard
 
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
diff --git a/addons/project/wizard/duplicate_template_wizard.py b/addons/project/wizard/duplicate_template_wizard.py
new file mode 100644 (file)
index 0000000..27a4ec4
--- /dev/null
@@ -0,0 +1,71 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution  
+#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). All Rights Reserved
+#    $Id$
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU 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 General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+from mx.DateTime import now
+
+import wizard
+import netsvc
+import ir
+import pooler
+import time
+
+from tools.translate import _
+
+class project_duplicate_template(wizard.interface):
+
+    def duplicate_template(self, cr, uid, data, context):
+        pool = pooler.get_pool(cr.dbname)
+        project_obj = pool.get('project.project')
+        res = project_obj.duplicate_template(cr, uid, data['ids'])        
+        if res and len(res):
+            res_id = res[0]        
+            data_obj = pool.get('ir.model.data')                        
+            form_view_id = data_obj._get_id(cr, uid, 'project', 'edit_project')
+            form_view = data_obj.read(cr, uid, form_view_id, ['res_id']) 
+            tree_view_id = data_obj._get_id(cr, uid, 'project', 'view_project_list')
+            tree_view = data_obj.read(cr, uid, tree_view_id, ['res_id']) 
+            search_view_id = data_obj._get_id(cr, uid, 'project', 'view_project_project_filter')
+            search_view = data_obj.read(cr, uid, search_view_id, ['res_id'])                        
+            return {            
+                'name': _('Projects'),
+                'view_type': 'form',
+                'view_mode': 'form,tree',
+                'res_model': 'project.project',
+                'view_id': False,
+                'res_id' : res_id,
+                'views': [(form_view['res_id'],'form'),(tree_view['res_id'],'tree')],
+                'type': 'ir.actions.act_window',
+                'search_view_id': search_view['res_id']
+                }
+        return {}
+    states = {
+        'init': {
+            'actions': [],
+            'result': {'type': 'action', 'action': duplicate_template, 'state': 'order'}
+        },
+        'order': {
+            'actions': [],
+            'result': {'type': 'state', 'state': 'end'}
+        }
+    }
+project_duplicate_template('project.duplicate.template')
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: