[IMP] Import module wizard convert into osv memory wizard

bzr revid: ksa@tinyerp.co.in-20100826101850-e8tsrqre2ksdpr3b
This commit is contained in:
ksa (Open ERP)
2010-08-26 15:48:50 +05:30
parent a6941afcf7
commit f917fe27b0
6 changed files with 115 additions and 128 deletions
+3
View File
@@ -48,6 +48,7 @@
'module/module_web_view.xml',
'module/module_data.xml',
'module/module_report.xml',
'module/wizard/base_module_import_view.xml',
'res/res_request_view.xml',
'res/res_lang_view.xml',
'res/res_log_view.xml',
@@ -62,9 +63,11 @@
'res/partner/wizard/partner_clear_ids_view.xml',
'res/partner/wizard/partner_wizard_ean_check_view.xml',
'res/partner/partner_data.xml',
'res/ir_property_view.xml',
'security/base_security.xml',
'maintenance/maintenance_view.xml',
'security/ir.model.access.csv'
],
+1 -7
View File
@@ -1,12 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="wizard_base_module_import" model="ir.actions.wizard">
<field name="name">Import module</field>
<field name="wiz_name">base.module.import</field>
</record>
<menuitem action="wizard_base_module_import" id="menu_wizard_module_import" parent="menu_management" type="wizard"/>
<record id="wizard_update" model="ir.actions.wizard">
<field name="name">Update Modules List</field>
<field name="wiz_name">module.module.update</field>
@@ -15,7 +9,7 @@
<wizard id="wizard_upgrade" model="ir.module.module" name="module.upgrade" string="Apply Scheduled Upgrades"/>
<menuitem action="wizard_upgrade" id="menu_wizard_upgrade" parent="menu_management" type="wizard"/>
+4 -3
View File
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
##############################################################################
#
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
@@ -15,7 +15,7 @@
# 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/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
@@ -26,8 +26,9 @@ import wizard_module_lang_install
import add_new
import wizard_export_lang
import wizard_import_lang
import wizard_module_import
import wizard_update_translations
import base_module_import
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -0,0 +1,65 @@
# -*- 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 pooler
import os
import tools
import zipfile
from StringIO import StringIO
import base64
from tools.translate import _
from osv import osv, fields
class base_module_import(osv.osv_memory):
""" Import Module """
_name = "base.module.import"
_description = "Import Module"
_columns = {
'module_file': fields.binary('Module .ZIP file', required=True),
}
def action_module_open(self, cr, uid, ids, context):
module_obj = self.pool.get('base.module.import')
data = module_obj.browse(cr, uid, ids , context=context)[0]
module_data = data.module_file
val =base64.decodestring(module_data)
fp = StringIO()
fp.write(val)
fdata = zipfile.ZipFile(fp, 'r')
fname = fdata.namelist()[0]
module_name = os.path.split(fname)[0]
return {
'domain': str([('name', '=', module_name)]),
'name': 'Module List',
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'ir.module.module',
'type': 'ir.actions.act_window',
}
base_module_import()
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_base_module_import" model="ir.ui.view">
<field name="name">Module Import</field>
<field name="model">base.module.import</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Module import">
<separator string="Module Import" colspan="4"/>
<label string="Please give your module .ZIP file to import." colspan="4"/>
<field name="module_file"/>
<separator string="" colspan="4" />
<newline/>
<group colspan="6" >
<button special="cancel" string="Close" icon="gtk-cancel"/>
<button name="action_module_open" string="Import module" type="object" icon="gtk-ok"/>
</group>
</form>
</field>
</record>
<record id="action_view_base_module_import" model="ir.actions.act_window">
<field name="name">Module Import</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">base.module.import</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<menuitem
name="Import Module"
action="action_view_base_module_import"
id="menu_view_base_module_import"
parent="menu_management"
sequence="1"/>
</data>
</openerp>
@@ -1,118 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 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
import osv
import pooler
import os
import tools
import zipfile
from StringIO import StringIO
import base64
from tools.translate import _
finish_form ='''<?xml version="1.0"?>
<form string="Module import">
<label string="Module successfully imported !" colspan="4"/>
</form>
'''
ask_form ='''<?xml version="1.0"?>
<form string="Module import">
<separator string="Module Import" colspan="4"/>
<label string="Please give your module .ZIP file to import." colspan="4"/>
<field name="module_file"/>
</form>
'''
ask_fields = {
'module_file': {'string': 'Module .ZIP file', 'type': 'binary', 'required': True},
}
class move_module_wizard(wizard.interface):
def importzip(self, cr, uid, data, context):
module_obj=pooler.get_pool(cr.dbname).get('ir.module.module')
module_data = data['form']['module_file']
val =base64.decodestring(module_data)
fp = StringIO()
fp.write(val)
fdata = zipfile.ZipFile(fp, 'r')
fname = fdata.namelist()[0]
module_name = os.path.split(fname)[0]
ad = tools.config['addons_path']
fname = os.path.join(ad,module_name+'.zip')
try:
fp = file(fname, 'wb')
fp.write(val)
fp.close()
except IOError, e:
raise wizard.except_wizard(_('Error !'), _('Can not create the module file: %s !') % (fname,) )
pooler.get_pool(cr.dbname).get('ir.module.module').update_list(cr, uid)
return {'module_name': module_name}
def _action_module_open(self, cr, uid, data, context):
return {
'domain': str([('name', '=', data['form']['module_name'])]),
'name': 'Module List',
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'ir.module.module',
'view_id': False,
'type': 'ir.actions.act_window'
}
states = {
'init': {
'actions': [],
'result': {
'type': 'form',
'arch': ask_form,
'fields': ask_fields,
'state': [
('end', 'Cancel', 'gtk-cancel'),
('import', 'Import module', 'gtk-ok', True)
]
}
},
'import': {
'actions': [importzip],
'result': {
'type':'form',
'arch':finish_form,
'fields':{},
'state':[('open_window','Close')]
}
},
'open_window': {
'actions': [],
'result': {'type': 'action', 'action': _action_module_open, 'state':'end'}
},
}
move_module_wizard('base.module.import')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: