[ADD] Account_analytic_plan: create model => osv memory
bzr revid: mra@tinyerp.com-20100427050053-2e0xma7y41moxdnc
This commit is contained in:
parent
c5f39991fb
commit
95a565f38d
|
@ -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,
|
||||
|
|
|
@ -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'):
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<wizard
|
||||
string="Create Model"
|
||||
model="account.analytic.plan.instance"
|
||||
name="create.model" id="create_model"
|
||||
menu="False"/>
|
||||
</data>
|
||||
</openerp>
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import create_model
|
||||
import analytic_plan_create_model
|
||||
import wizard_crossovered_analytic
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
# -*- 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/>.
|
||||
#
|
||||
##############################################################################
|
||||
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:
|
|
@ -0,0 +1,53 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<record id="view_analytic_plan_create_model_msg" model="ir.ui.view">
|
||||
<field name="name">analytic.plan.create.model.msg.form</field>
|
||||
<field name="model">analytic.plan.create.model</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Distribution Model Saved">
|
||||
<group col="4" colspan="6">
|
||||
<label string="Save This Distribution as a Model"/>
|
||||
<newline/>
|
||||
</group>
|
||||
<separator colspan="4"/>
|
||||
<group col="2" colspan="4">
|
||||
<button special="cancel" string="Cancel" icon='gtk-ok' />
|
||||
<button string="Ok" icon='gtk-execute' type="object" name="activate" default_focus="1"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_analytic_plan_create_model" model="ir.ui.view">
|
||||
<field name="name">analytic.plan.create.model.form</field>
|
||||
<field name="model">analytic.plan.create.model</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Distribution Model Saved">
|
||||
<group col="4" colspan="6">
|
||||
<label string="This distribution model has been saved.You will be able to reuse it later."/>
|
||||
<newline/>
|
||||
</group>
|
||||
<separator colspan="4"/>
|
||||
<group col="2" colspan="4">
|
||||
<button special="cancel" string="Ok" icon='gtk-ok'/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record id="action_analytic_plan_create_model" model="ir.actions.act_window">
|
||||
<field name="name">analytic.plan.create.model.action</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">analytic.plan.create.model</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
<field name="view_id" ref="view_analytic_plan_create_model_msg"/>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
|
@ -1,71 +0,0 @@
|
|||
# -*- 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 wizard
|
||||
import time
|
||||
import netsvc
|
||||
import pooler
|
||||
from tools.translate import _
|
||||
|
||||
info = '''<?xml version="1.0"?>
|
||||
<form string="Distribution Model Saved">
|
||||
<label string="This distribution model has been saved.\nYou will be able to reuse it later."/>
|
||||
</form>'''
|
||||
|
||||
|
||||
def activate(self, cr, uid, data, context):
|
||||
plan_obj = pooler.get_pool(cr.dbname).get('account.analytic.plan.instance')
|
||||
if data['id']:
|
||||
plan = plan_obj.browse(cr, uid, data['id'], context)
|
||||
if (not plan.name) or (not plan.code):
|
||||
raise wizard.except_wizard(_('Error'), _('Please put a name and a code before saving the model !'))
|
||||
pids = pooler.get_pool(cr.dbname).get('account.analytic.plan').search(cr, uid, [], context=context)
|
||||
if (not pids):
|
||||
raise wizard.except_wizard(_('Error'), _('No analytic plan defined !'))
|
||||
plan_obj.write(cr,uid,[data['id']],{'plan_id':pids[0]})
|
||||
return 'info'
|
||||
else:
|
||||
return 'endit'
|
||||
|
||||
def _do_nothing(self, cr, uid, data, context):
|
||||
return 1
|
||||
|
||||
class create_model(wizard.interface):
|
||||
|
||||
states = {
|
||||
'init': {
|
||||
'actions': [],
|
||||
'result': {'type':'choice','next_state':activate}
|
||||
},
|
||||
'info': {
|
||||
'actions': [],
|
||||
'result': {'type':'form', 'arch':info, 'fields':{}, 'state':[('end','OK')]}
|
||||
},
|
||||
'endit': {
|
||||
'actions': [],
|
||||
'result': {'type':'action','action':_do_nothing , 'state':'end'} #FIXME: check
|
||||
},
|
||||
}
|
||||
create_model('create.model')
|
||||
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
Loading…
Reference in New Issue