[ADD,IMP] base_action_rule: Added a wizard to activate/deactivate all the rules at a time. Improved function field for action rule object.

bzr revid: uco@tinyerp.co.in-20100210095434-p4joqo4btxb9250n
This commit is contained in:
uco (OpenERP) 2010-02-10 15:24:34 +05:30
parent 4cd8792dea
commit 6916df304f
7 changed files with 161 additions and 6 deletions

View File

@ -20,5 +20,6 @@
##############################################################################
import base_action_rule
import wizard
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -30,6 +30,7 @@
'init_xml': ['base_action_rule_data.xml'],
'update_xml': [
'base_action_rule_view.xml',
'base_action_rule_wizard.xml',
'security/ir.model.access.csv',
],
'demo_xml': [],

View File

@ -1,3 +1,24 @@
# -*- 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 time
import mx.DateTime
import re
@ -34,6 +55,8 @@ class base_action_rule(osv.osv):
res[check.id] = len(check.rule_lines)
elif len(check.rule_lines) > 15:
raise osv.except_osv(_('Error !'), _('Max Level exceeded.'))
else:
res[check.id] = 0
return res
_columns = {
@ -42,17 +65,17 @@ class base_action_rule(osv.osv):
type='integer', store=True, help='Specifies maximum rule lines can be entered.'),
'rule_lines': fields.one2many('base.action.rule.line','rule_id','Rule Lines', states={'activate': [('readonly', True)]}),
'create_date': fields.datetime('Create Date', readonly=1),
'state': fields.selection([('draft','Draft'),('activate','Activated'),('deactivate','Deactivated')],'State',readonly=1)
'state': fields.selection([('activate','Activated'),('deactivate','Deactivated')],'State',readonly=1)
}
_defaults = {
'state': lambda *a: 'draft',
'state': lambda *a: 'deactivate',
}
def button_activate_rule(self, cr, uid, ids, context=None):
check = self.browse(cr, uid, ids[0]).rule_lines
check = all(rule.rule_lines for rule in self.browse(cr, uid, ids))
if not check:
raise osv.except_osv(_('Error !'), _('Rule Lines are empty ! Cannot activate the Rule.'))
raise osv.except_osv(_('Error !'), _('Rule Lines are empty ! Cannot activate the Rule(s).'))
cronobj = self.pool.get('ir.cron')
cronids = cronobj.search(cr,uid,[('model','=','base.action.rule'),('active','=',False)])
if cronids:

View File

@ -18,7 +18,7 @@
<newline/>
<group col="4" colspan="4">
<field name="state" select="1"/>
<button name="button_activate_rule" states="draft,deactivate" string="Activate" icon="gtk-execute" type="object"/>
<button name="button_activate_rule" states="deactivate" string="Activate" icon="gtk-execute" type="object"/>
<button name="button_deactivate_rule" states="activate" string="De-activate" icon="gtk-execute" type="object"/>
</group>
</form>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<wizard id="wiz_action_rule"
model="base.action.rule"
string="Activate/Deactivate All Rules"
name="base.action.rule.activate.all"/>
<menuitem action="wiz_action_rule" id="menu_action_rule_wizard" parent="menu_base_action_rule" type="wizard"/>
</data>
</openerp>

View File

@ -0,0 +1,24 @@
# -*- 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_activate_all
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,93 @@
# -*- 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 pooler
from tools.translate import _
rule_form = '''<?xml version="1.0"?>
<form string="Rules" colspan="4">
<group colspan="4" attrs="{'invisible':[('deactivate','=',True)]}">
<field name="activate"/>
</group>
<group colspan="4" attrs="{'invisible':[('activate','=',True)]}">
<field name="deactivate"/>
</group>
</form>'''
rule_fields = {
'activate': {'string': 'Activate', 'type': 'boolean'},
'deactivate': {'string': 'Deactivate', 'type': 'boolean'}
}
_rules_end = '''<?xml version="1.0"?>
<form string="Result">
<label string="Action completed successfully !" colspan="4"/>
</form>'''
class rules_activate_all(wizard.interface):
def _check(self, cr, uid, data, context):
actobj = pooler.get_pool(cr.dbname).get('base.action.rule')
cronobj = pooler.get_pool(cr.dbname).get('ir.cron')
cr.execute('select id, active from ir_cron where model=\'base.action.rule\'')
crons = cr.fetchall()[0]
check = actobj.search(cr, uid, [])
if not check:
cronobj.write(cr, uid, crons[0], {'active': False})
raise wizard.except_wizard(_('Warning !'),_('No Rules defined !'))
return {}
def _activate_all(self, cr, uid, data, context):
actobj = pooler.get_pool(cr.dbname).get('base.action.rule')
if data['form']['activate']:
actids = actobj.search(cr, uid, [('state','=','deactivate')])
if actids:
actobj.button_activate_rule(cr, uid, actids)
else:
raise wizard.except_wizard(_('Error'),_('All rules are already active.'))
elif data['form']['deactivate']:
actids = actobj.search(cr, uid, [('state','=','activate')])
if actids:
actobj.button_deactivate_rule(cr, uid, actids)
else:
raise wizard.except_wizard(_('Error'),_('All rules are already deactivated.'))
else:
raise wizard.except_wizard(_('Warning !'),_('No Action Performed !'))
return {}
states = {
'init': {
'actions': [_check],
'result': {'type': 'form', 'arch': rule_form, 'fields': rule_fields, 'state':[('end','Cancel','gtk-cancel'),('ok','Ok','gtk-go-forward')]}
},
'ok': {
'actions': [_activate_all],
'result': {'type': 'form', 'arch': _rules_end,
'fields': {},
'state': (
('end', 'Close','gtk-close'),
)
},
},
}
rules_activate_all('base.action.rule.activate.all')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: