[ADD, MOD] account : wizard account use model is changed to osv memory wizard

bzr revid: vir@tinyerp.com-20100421053736-l9071dge8deuu1dl
This commit is contained in:
Vir (Open ERP) 2010-04-21 11:07:36 +05:30
parent fbe9da561f
commit d5f50a85d1
7 changed files with 210 additions and 136 deletions

View File

@ -70,6 +70,7 @@ module named account_voucherss
'wizard/account_pay_invoice_view.xml',
'wizard/account_unreconcile_view.xml',
'wizard/account_invoice_state_view.xml',
'wizard/account_use_model_view.xml',
'project/wizard/project_account_analytic_line_view.xml',
'account_view.xml',
'account_end_fy.xml',

View File

@ -1176,7 +1176,7 @@
<separator string="Legend" colspan="4"/>
<field name="legend" colspan="4" nolabel="1"/>
<group col="1" colspan="4">
<button name="%(wizard_account_use_model)d" string="Create entries" type="action" icon="gtk-execute"/>
<button name="%(action_account_use_model_create_entry)d" string="Create entries" type="action" icon="gtk-execute"/>
</group>
</form>
</field>

View File

@ -96,10 +96,10 @@
<wizard id="wizard_validate_account_moves_line" menu="True" model="account.move.line" name="account.move_line.validate" string="Validate Ledger Postings"/>-->
<!-- Use Models -->
<wizard string="Create Entries From Models" model="account.model" name="account_use_models" menu="False" id="wizard_account_use_model"/>
<menuitem action="wizard_account_use_model" type="wizard" parent="account.menu_finance_recurrent_entries" id="menu_account_use_model"/>
<!-- <wizard string="Create Entries From Models" model="account.model" name="account_use_models" menu="False" id="wizard_account_use_model"/>-->
<!-- <menuitem action="wizard_account_use_model" type="wizard" parent="account.menu_finance_recurrent_entries" id="menu_account_use_model"/>-->
<wizard string="Create Entries From Models" model="account.move.line" name="account_use_models" menu="True" id="wizard_line_account_use_model"/>
<!-- <wizard string="Create Entries From Models" model="account.move.line" name="account_use_models" menu="True" id="wizard_line_account_use_model"/>-->
<!-- account.invoice -->
<!-- <wizard string="Open State" model="account.invoice" name="account.wizard_paid_open" menu="False" id="wizard_paid_open" groups="base.group_user"/> -->

View File

@ -48,7 +48,7 @@ import account_chart
import wizard_move_line_select
import account_validate_account_move
import wizard_use_model
import account_use_model
import account_state_open

View File

@ -0,0 +1,116 @@
# -*- 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 datetime
from osv import fields, osv
from tools.translate import _
class account_use_model(osv.osv_memory):
_name = 'account.use.model'
_description = 'Use model'
_columns = {
'model': fields.many2many('account.model', 'account_use_model_relation','account_id','model_id','Account Model'),
}
def create_entries(self, cr, uid, ids, context=None):
account_model_obj = self.pool.get('account.model')
account_period_obj = self.pool.get('account.period')
account_move_obj = self.pool.get('account.move')
account_move_line_obj = self.pool.get('account.move.line')
mod_obj = self.pool.get('ir.model.data')
if context is None:
context = {}
data = self.read(cr, uid, ids,context=context)[0]
record_id = context and context.get('model_line', False) or False
if record_id:
data_model = account_model_obj.browse(cr,uid,data['model'])
else:
data_model = account_model_obj.browse(cr,uid,context['active_ids'])
move_ids = []
for model in data_model:
period_id = account_period_obj.find(cr, uid, context=context)
if not period_id:
raise osv.except_osv(_('No period found !'), _('Unable to find a valid period !'))
period_id = period_id[0]
move_id = account_move_obj.create(cr, uid, {
'ref': model.ref,
'period_id': period_id,
'journal_id': model.journal_id.id,
})
move_ids.append(move_id)
for line in model.lines_id:
val = {
'move_id': move_id,
'journal_id': model.journal_id.id,
'period_id': period_id
}
val.update({
'name': line.name,
'quantity': line.quantity,
'debit': line.debit,
'credit': line.credit,
'account_id': line.account_id.id,
'move_id': move_id,
'ref': line.ref,
'partner_id': line.partner_id.id,
'date': time.strftime('%Y-%m-%d'),
'date_maturity': time.strftime('%Y-%m-%d')
})
c = context.copy()
c.update({'journal_id': model.journal_id.id,'period_id': period_id})
id_line = account_move_line_obj.create(cr, uid, val, context=c)
context.update({'move_ids':move_ids})
model_data_ids = mod_obj.search(cr, uid,[('model','=','ir.ui.view'),('name','=','view_account_use_model_open_entry')], context=context)
resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
return {
'name': _('Use Model'),
'context': context,
'view_type': 'form',
'view_mode': 'form',
'res_model': 'account.use.model',
'views': [(resource_id,'form')],
'type': 'ir.actions.act_window',
'target': 'new',
}
def open_moves(self, cr, uid, ids, context=None):
mod_obj = self.pool.get('ir.model.data')
if context is None:
context = {}
model_data_ids = mod_obj.search(cr, uid,[('model','=','ir.ui.view'),('name','=','view_move_form')], context=context)
resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
return {
'domain': "[('id','in', ["+','.join(map(str,context['move_ids']))+"])]",
'name': 'Entries',
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'account.move',
'views': [(False,'tree'),(resource_id,'form')],
'type': 'ir.actions.act_window',
}
account_use_model()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,88 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_account_use_model" model="ir.ui.view">
<field name="name">account.use.model.form</field>
<field name="model">account.use.model</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Create Entries From Models">
<group colspan="4" >
<field name="model"/>
</group>
<group colspan="4" col="6">
<label string ="" colspan="2"/>
<button icon="gtk-cancel" special="cancel" string="Cancel"/>
<button icon="gtk-execute" string="Create Entries" name="create_entries" type="object"/>
</group>
</form>
</field>
</record>
<record id="action_view_account_use_model" model="ir.actions.act_window">
<field name="name">Create Entries From Models</field>
<field name="res_model">account.use.model</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_account_use_model"/>
<field name="target">new</field>
<field name="context">{'model_line':'model_line'}</field>
</record>
<record model="ir.values" id="action_account_use_model_values">
<field name="model_id" ref="account.model_account_move_line" />
<field name="object" eval="1" />
<field name="name">Create Entries From Models</field>
<field name="key2">client_action_multi</field>
<field name="value" eval="'ir.actions.act_window,' +str(ref('action_view_account_use_model'))" />
<field name="key">action</field>
<field name="model">account.move.line</field>
</record>
<menuitem action="action_view_account_use_model" name="Create Entries From Models"
parent="account.menu_finance_recurrent_entries" id="menu_account_use_model"/>
<record id="view_account_use_model_open_entry" model="ir.ui.view">
<field name="name">account.use.model.open.entry.form</field>
<field name="model">account.use.model</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Use Model">
<group colspan="4" col="6">
<label string = "Entry Lines Created." colspan="2"/>
<newline/>
<button icon="gtk-ok" special="cancel" string="Ok"/>
<button icon="gtk-execute" string="Open" name="open_moves" type="object"/>
</group>
</form>
</field>
</record>
<record id="view_account_use_model_create_entry" model="ir.ui.view">
<field name="name">account.use.model.create.entry.form</field>
<field name="model">account.use.model</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Use Model">
<group colspan="4" col="6">
<label string = "Are you sure you want to create entries?" colspan="2"/>
<newline/>
<button icon="gtk-ok" special="cancel" string="Cancel"/>
<button icon="gtk-execute" string="Ok" name="create_entries" type="object"/>
</group>
</form>
</field>
</record>
<record id="action_account_use_model_create_entry" model="ir.actions.act_window">
<field name="name">Create Entries From Models</field>
<field name="res_model">account.use.model</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_account_use_model_create_entry"/>
<field name="target">new</field>
</record>
</data>
</openerp>

View File

@ -1,131 +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 datetime
import pooler
from tools.translate import _
model_form = """<?xml version="1.0"?>
<form string="Create entries from models">
<field name="model"/>
</form>"""
model_fields = {
'model': {'string': 'Account Model', 'type': 'many2many', 'relation': 'account.model', 'required': True},
}
form = """<?xml version="1.0"?>
<form string="Use Model">
<label string="Entry Lines Created."/>
</form>
"""
fields = {
}
def _create_entries(self, cr, uid, data, context):
pool_obj = pooler.get_pool(cr.dbname)
if data['model']=='ir.ui.menu' or data['model']=='account.move.line':
model_ids = data['form']['model'][0][2]
data_model = pool_obj.get('account.model').browse(cr,uid,model_ids)
else:
data_model = pool_obj.get('account.model').browse(cr,uid,data['ids'])
move_ids = []
for model in data_model:
period_id = pool_obj.get('account.period').find(cr,uid, context=context)
if not period_id:
raise wizard.except_wizard(_('No period found !'), _('Unable to find a valid period !'))
period_id = period_id[0]
move_id = pool_obj.get('account.move').create(cr, uid, {
'ref': model.ref,
'period_id': period_id,
'journal_id': model.journal_id.id,
})
move_ids.append(move_id)
for line in model.lines_id:
val = {
'move_id': move_id,
'journal_id': model.journal_id.id,
'period_id': period_id
}
val.update({
'name': line.name,
'quantity': line.quantity,
'debit': line.debit,
'credit': line.credit,
'account_id': line.account_id.id,
'move_id': move_id,
'ref': line.ref,
'partner_id': line.partner_id.id,
'date': time.strftime('%Y-%m-%d'),
'date_maturity': time.strftime('%Y-%m-%d')
})
c = context.copy()
c.update({'journal_id': model.journal_id.id,'period_id': period_id})
id_line = pool_obj.get('account.move.line').create(cr, uid, val, context=c)
data['form']['move_ids']=move_ids
return data['form']
class use_model(wizard.interface):
def _open_moves(self, cr, uid, data, context):
pool_obj = pooler.get_pool(cr.dbname)
model_data_ids = pool_obj.get('ir.model.data').search(cr,uid,[('model','=','ir.ui.view'),('name','=','view_move_form')])
resource_id = pool_obj.get('ir.model.data').read(cr,uid,model_data_ids,fields=['res_id'])[0]['res_id']
return {
'domain': "[('id','in', ["+','.join(map(str,data['form']['move_ids']))+"])]",
'name': 'Entries',
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'account.move',
'views': [(False,'tree'),(resource_id,'form')],
'type': 'ir.actions.act_window'
}
def _check(self, cr, uid, data, context):
if data['model']=='ir.ui.menu' or data['model']=='account.move.line':
return 'init_form'
return 'create'
states = {
'init': {
'actions': [],
'result': {'type':'choice','next_state':_check}
},
'init_form': {
'actions': [],
'result': {'type':'form', 'arch':model_form, 'fields':model_fields, 'state':[('end','Cancel', 'gtk-cancel'),('create','Create', 'gtk-ok')]},
},
'create': {
'actions': [_create_entries],
'result': {'type': 'form','arch':form, 'fields':fields, 'state':[('end','Ok'),('open_move','Open')]},
},
'open_move': {
'actions': [],
'result': {'type':'action', 'action':_open_moves, 'state':'end'}
}
}
use_model("account_use_models")# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: