From 95a565f38d20147980eb0d12c803b6d0efab9558 Mon Sep 17 00:00:00 2001 From: "mra (Open ERP)" Date: Tue, 27 Apr 2010 10:30:53 +0530 Subject: [PATCH] [ADD] Account_analytic_plan: create model => osv memory bzr revid: mra@tinyerp.com-20100427050053-2e0xma7y41moxdnc --- addons/account_analytic_plans/__openerp__.py | 4 +- .../account_analytic_plans.py | 2 +- .../account_analytic_plans/model_wizard.xml | 11 --- .../account_analytic_plans/wizard/__init__.py | 6 +- .../wizard/analytic_plan_create_model.py | 56 +++++++++++++++ .../analytic_plan_create_model_view.xml | 53 ++++++++++++++ .../wizard/create_model.py | 71 ------------------- 7 files changed, 115 insertions(+), 88 deletions(-) delete mode 100644 addons/account_analytic_plans/model_wizard.xml create mode 100644 addons/account_analytic_plans/wizard/analytic_plan_create_model.py create mode 100644 addons/account_analytic_plans/wizard/analytic_plan_create_model_view.xml delete mode 100644 addons/account_analytic_plans/wizard/create_model.py diff --git a/addons/account_analytic_plans/__openerp__.py b/addons/account_analytic_plans/__openerp__.py index b3067358a62..d2183563462 100644 --- a/addons/account_analytic_plans/__openerp__.py +++ b/addons/account_analytic_plans/__openerp__.py @@ -60,9 +60,9 @@ of distribution models. 'init_xml': [], 'update_xml': [ 'security/ir.model.access.csv', - 'model_wizard.xml', 'account_analytic_plans_view.xml', - 'account_analytic_plans_report.xml' + 'account_analytic_plans_report.xml', + 'wizard/analytic_plan_create_model_view.xml' ], 'demo_xml': [], 'installable': True, diff --git a/addons/account_analytic_plans/account_analytic_plans.py b/addons/account_analytic_plans/account_analytic_plans.py index ea3dbdd0475..57acdb6dee5 100644 --- a/addons/account_analytic_plans/account_analytic_plans.py +++ b/addons/account_analytic_plans/account_analytic_plans.py @@ -145,7 +145,7 @@ class account_analytic_plan_instance(osv.osv): return self.name_get(cr, uid, ids, context or {}) def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): - wiz_id = self.pool.get('ir.actions.wizard').search(cr, uid, [("wiz_name","=","create.model")]) + wiz_id = self.pool.get('ir.actions.act_window').search(cr, uid, [("name","=","analytic.plan.create.model.action")]) res = super(account_analytic_plan_instance,self).fields_view_get(cr, uid, view_id, view_type, context, toolbar=toolbar, submenu=submenu) if (res['type']=='form'): diff --git a/addons/account_analytic_plans/model_wizard.xml b/addons/account_analytic_plans/model_wizard.xml deleted file mode 100644 index 9dc545b90a5..00000000000 --- a/addons/account_analytic_plans/model_wizard.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - diff --git a/addons/account_analytic_plans/wizard/__init__.py b/addons/account_analytic_plans/wizard/__init__.py index 4b47827094b..3da1c55b8bf 100644 --- a/addons/account_analytic_plans/wizard/__init__.py +++ b/addons/account_analytic_plans/wizard/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (). # @@ -15,11 +15,11 @@ # 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 . +# along with this program. If not, see . # ############################################################################## -import create_model +import analytic_plan_create_model import wizard_crossovered_analytic # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/account_analytic_plans/wizard/analytic_plan_create_model.py b/addons/account_analytic_plans/wizard/analytic_plan_create_model.py new file mode 100644 index 00000000000..aafaf986b51 --- /dev/null +++ b/addons/account_analytic_plans/wizard/analytic_plan_create_model.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# 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 . +# +############################################################################## +from osv import osv +from tools.translate import _ + +class analytic_plan_create_model(osv.osv_memory): + _name = 'analytic.plan.create.model' + _description = 'analytic.plan.create.model' + + def activate(self, cr, uid, ids, context=None): + plan_obj = self.pool.get('account.analytic.plan.instance') + mod_obj = self.pool.get('ir.model.data') + if 'active_id' in context and context['active_id']: + plan = plan_obj.browse(cr, uid, context['active_id'], context=context) + if (not plan.name) or (not plan.code): + raise osv.except_osv(_('Error'), _('Please put a name and a code before saving the model !')) + pids = self.pool.get('account.analytic.plan').search(cr, uid, [], context=context) + if (not pids): + raise osv.except_osv(_('Error'), _('No analytic plan defined !')) + plan_obj.write(cr, uid, [context['active_id']], {'plan_id':pids[0]}) + + model_data_ids = mod_obj.search(cr,uid,[('model', '=', 'ir.ui.view'),('name', '=', 'view_analytic_plan_create_model')], context=context) + resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id'] + return { + 'name': _('Distribution Model Saved'), + 'view_type': 'form', + 'view_mode': 'tree,form', + 'res_model': 'analytic.plan.create.model', + 'views': [(resource_id,'form')], + 'type': 'ir.actions.act_window', + 'target': 'new', + } + else: + return {} + +analytic_plan_create_model() + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file diff --git a/addons/account_analytic_plans/wizard/analytic_plan_create_model_view.xml b/addons/account_analytic_plans/wizard/analytic_plan_create_model_view.xml new file mode 100644 index 00000000000..75ef07e0098 --- /dev/null +++ b/addons/account_analytic_plans/wizard/analytic_plan_create_model_view.xml @@ -0,0 +1,53 @@ + + + + + analytic.plan.create.model.msg.form + analytic.plan.create.model + form + +
+ + + + +