diff --git a/addons/account/__openerp__.py b/addons/account/__openerp__.py
index 0afe7f878e0..d12ee4ec836 100644
--- a/addons/account/__openerp__.py
+++ b/addons/account/__openerp__.py
@@ -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',
diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml
index c0bd50eb7bc..a386901a083 100644
--- a/addons/account/account_view.xml
+++ b/addons/account/account_view.xml
@@ -1176,7 +1176,7 @@
-
+
diff --git a/addons/account/account_wizard.xml b/addons/account/account_wizard.xml
index 148491fb2a1..69fc1ef5902 100644
--- a/addons/account/account_wizard.xml
+++ b/addons/account/account_wizard.xml
@@ -96,10 +96,10 @@
-->
-
-
+
+
-
+
diff --git a/addons/account/wizard/__init__.py b/addons/account/wizard/__init__.py
index e9ca2487604..6d63cb665d9 100644
--- a/addons/account/wizard/__init__.py
+++ b/addons/account/wizard/__init__.py
@@ -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
diff --git a/addons/account/wizard/account_use_model.py b/addons/account/wizard/account_use_model.py
new file mode 100644
index 00000000000..28a892a398b
--- /dev/null
+++ b/addons/account/wizard/account_use_model.py
@@ -0,0 +1,116 @@
+# -*- 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 .
+#
+##############################################################################
+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:
+
diff --git a/addons/account/wizard/account_use_model_view.xml b/addons/account/wizard/account_use_model_view.xml
new file mode 100644
index 00000000000..877a83dbb00
--- /dev/null
+++ b/addons/account/wizard/account_use_model_view.xml
@@ -0,0 +1,88 @@
+
+
+
+
+
+ account.use.model.form
+ account.use.model
+ form
+
+
+
+
+
+
+ Create Entries From Models
+ account.use.model
+ form
+ tree,form
+
+ new
+ {'model_line':'model_line'}
+
+
+
+
+
+ Create Entries From Models
+ client_action_multi
+
+ action
+ account.move.line
+
+
+
+
+
+ account.use.model.open.entry.form
+ account.use.model
+ form
+
+
+
+
+
+
+ account.use.model.create.entry.form
+ account.use.model
+ form
+
+
+
+
+
+
+ Create Entries From Models
+ account.use.model
+ form
+ tree,form
+
+ new
+
+
+
+
diff --git a/addons/account/wizard/wizard_use_model.py b/addons/account/wizard/wizard_use_model.py
deleted file mode 100644
index ef3a4ba1310..00000000000
--- a/addons/account/wizard/wizard_use_model.py
+++ /dev/null
@@ -1,131 +0,0 @@
-# -*- 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 .
-#
-##############################################################################
-
-import wizard
-import time
-import datetime
-import pooler
-from tools.translate import _
-
-model_form = """
-"""
-
-model_fields = {
- 'model': {'string': 'Account Model', 'type': 'many2many', 'relation': 'account.model', 'required': True},
- }
-
-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:
-