_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 = {
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',
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:
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)
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
<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">
</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>