[IMP] improved code to show import result in wizard and improved typo
authortpa-odoo <tpa@tinyerp.com>
Thu, 22 May 2014 11:39:52 +0000 (17:09 +0530)
committertpa-odoo <tpa@tinyerp.com>
Thu, 22 May 2014 11:39:52 +0000 (17:09 +0530)
addons/base_import_module/controllers/main.py
addons/base_import_module/models/base_import_module.py
addons/base_import_module/models/ir_module.py
addons/base_import_module/views/base_import_module.xml

index 4707def..d97e75b 100644 (file)
@@ -36,4 +36,4 @@ class ImportModule(Controller):
     @webservice
     def upload(self, mod_file=None, **kw):
         self.check_user()
-        return request.registry['ir.module.module'].import_zipfile(request.cr, request.uid, mod_file, context=request.context)
+        return request.registry['ir.module.module'].import_zipfile(request.cr, request.uid, mod_file, context=request.context)[0]
index ffdbe0d..3d1e39e 100644 (file)
@@ -11,7 +11,7 @@ class base_import_module(osv.TransientModel):
     _columns = {
         'module_file': fields.binary('Module .ZIP file', required=True),
         'state':fields.selection([('init','init'),('done','done')], 'Status', readonly=True),
-        'module_name': fields.char('Module Name', size=128),
+        'import_messgae': fields.char('Import messge'),
     }
 
     _defaults = {  
@@ -24,15 +24,24 @@ class base_import_module(osv.TransientModel):
         zip_data = base64.decodestring(data.module_file)
         fp = BytesIO()
         fp.write(zip_data)
-        module_obj.import_zipfile(cr, uid, fp, context=context)
-        fp.close()
-        self.write(cr, uid, ids, {'state': 'done'}, context=context)
-        return False
+        res = module_obj.import_zipfile(cr, uid, fp, context=context)
+        self.write(cr, uid, ids, {'state': 'done', 'import_messgae': res[0]}, context=context)
+        context = dict(context, module_name=res[1])
+        # Return wizard otherwise it will close wizard and will not show result message to user. 
+        return {
+            'name': 'Import Module',
+            'view_type': 'form',
+            'view_mode': 'form',
+            'target': 'new',
+            'res_id': ids[0],
+            'res_model': 'base.import.module',
+            'type': 'ir.actions.act_window',
+            'context': context,
+        }
 
     def action_module_open(self, cr, uid, ids, context):
-        data = self.browse(cr, uid, ids[0] , context=context)
         return {
-            'domain': str([('name', '=', data.module_name)]),
+            'domain': [('name', 'in', context.get('module_name',[]))],
             'name': 'Modules',
             'view_type': 'form',
             'view_mode': 'tree,form',
index 10ffccc..2a0a9ea 100644 (file)
@@ -81,6 +81,7 @@ class view(osv.osv):
 
         success = []
         errors = dict()
+        module_names = []
         with zipfile.ZipFile(module_file, "r") as z:
             for zf in z.filelist:
                 if zf.file_size > MAX_FILE_SIZE:
@@ -90,6 +91,7 @@ class view(osv.osv):
                 z.extractall(module_dir)
                 dirs = [d for d in os.listdir(module_dir) if os.path.isdir(opj(module_dir, d))]
                 for mod_name in dirs:
+                    module_names.append(mod_name)
                     try:
                         # assert mod_name.startswith('theme_')
                         path = opj(module_dir, mod_name)
@@ -100,4 +102,4 @@ class view(osv.osv):
         r = ["Successfully imported module '%s'" % mod for mod in success]
         for mod, error in errors.items():
             r.append("Error while importing module '%s': %r" % (mod, error))
-        return '\n'.join(r)
+        return '\n'.join(r), module_names
index 405ec76..ffc3c18 100644 (file)
@@ -3,18 +3,18 @@
     <data>
 
         <record id="view_base_module_import" model="ir.ui.view">
-            <field name="name">Module Import</field>
+            <field name="name">Import Module</field>
             <field name="model">base.import.module</field>
             <field name="arch" type="xml">
                 <form string="Import module" version="7.0">
                     <field name="state" invisible="1"/>
-                    <separator string="Module Import" colspan="4"/>
+                    <separator string="Import Module" colspan="4"/>
                     <group states="init" col="4">
                         <label string="Select module package to import (.zip file):" colspan="4"/>
                         <field name="module_file" colspan="4"/>
                     </group>
                     <group states="done" col="4">
-                        <label string="Module file successfully imported!" colspan="4"/>
+                        <field name="import_messgae" colspan="4" nolabel="1" readonly="1"/>
                     </group>
                     <footer>
                         <div states="init">
@@ -31,7 +31,7 @@
         </record>
 
         <record id="action_view_base_module_import" model="ir.actions.act_window">
-            <field name="name">Module Import</field>
+            <field name="name">Import Module</field>
             <field name="type">ir.actions.act_window</field>
             <field name="res_model">base.import.module</field>
             <field name="view_type">form</field>