1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
24 from tools.translate import _
27 asset_end_arch = '''<?xml version="1.0"?>
28 <form string="Compute assets">
29 <separator string="Generated entries" colspan="4"/>
30 <field name="move_ids" readonly="1" nolabel="1"/>
34 'move_ids': {'string':'Entries', 'type': 'one2many', 'relation':'account.move'},
38 asset_ask_form = '''<?xml version="1.0"?>
39 <form string="Compute assets">
40 <field name="period_id"/>
44 'period_id': {'string': 'Period', 'type': 'many2one', 'relation':'account.period', 'required':True},
47 def _asset_compute(self, cr, uid, data, context):
48 pool = pooler.get_pool(cr.dbname)
49 ass_obj = pool.get('account.asset.asset')
50 ids = ass_obj.search(cr, uid, [('state','=','normal')], context=context)
52 for asset in ass_obj.browse(cr, uid, ids, context):
53 ids_create += ass_obj._compute_entries(cr, uid, asset, data['form']['period_id'], context)
54 self.move_ids = ids_create
55 return {'move_ids': ids_create}
57 def _asset_open(self, cr, uid, data, context):
59 'name': 'Created moves',
61 'view_mode': 'tree,form',
62 'res_model': 'account.move',
64 'type': 'ir.actions.act_window'
66 if data['form']['move_ids']:
67 value['domain']= "[('id','in',["+','.join(map(str,self.move_ids))+"])]"
69 value['domain']= "[('id','=', False)]"
72 def _get_period(self, cr, uid, data, context={}):
73 pool = pooler.get_pool(cr.dbname)
74 ids = pool.get('account.period').find(cr, uid, context=context)
78 return {'period_id': period_id}
80 class wizard_asset_compute(wizard.interface):
83 'actions': [_get_period],
84 'result': {'type':'form', 'arch':asset_ask_form, 'fields':asset_ask_fields, 'state':[
86 ('asset_compute','Compute assets')
90 'actions': [_asset_compute],
91 'result': {'type' : 'form', 'arch': asset_end_arch, 'fields':asset_end_fields, 'state':[
93 ('asset_open','Open entries')
98 'result': {'type':'action', 'action': _asset_open, 'state':'end'}
101 wizard_asset_compute('account.asset.compute')
104 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: