~openerp-commiter/openobject-addons/extra-6.0

« back to all changes in this revision

Viewing changes to account_voucher/wizard/open_voucher.py

  • Committer: Mantavya Gajjar
  • Date: 2009-04-16 13:01:59 UTC
  • mto: (3589.23.3 addons-extra)
  • mto: This revision was merged to the branch mainline in revision 3608.
  • Revision ID: mga@tinyerp.com-20090416130159-z5ec22atycrwcl1v
uploda the new reviewd clean code for the indian accounting

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
# Copyright (c) 2004-2008 TINY SPRL. (http://tiny.be) All Rights Reserved.
 
5
#
 
6
# $Id$
 
7
#
 
8
# WARNING: This program as such is intended to be used by professional
 
9
# programmers who take the whole responsability of assessing all potential
 
10
# consequences resulting from its eventual inadequacies and bugs
 
11
# End users who are looking for a ready-to-use solution with commercial
 
12
# garantees and support are strongly adviced to contract a Free Software
 
13
# Service Company
 
14
#
 
15
# This program is Free Software; you can redistribute it and/or
 
16
# modify it under the terms of the GNU General Public License
 
17
# as published by the Free Software Foundation; either version 2
 
18
# of the License, or (at your option) any later version.
 
19
#
 
20
# This program is distributed in the hope that it will be useful,
 
21
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
22
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
23
# GNU General Public License for more details.
 
24
#
 
25
# You should have received a copy of the GNU General Public License
 
26
# along with this program; if not, write to the Free Software
 
27
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
28
#
 
29
##############################################################################
 
30
 
 
31
import wizard
 
32
from tools.translate import _
 
33
import pooler
 
34
 
 
35
_voucher_form = '''<?xml version="1.0"?>
 
36
<form string="Open Vouchers">
 
37
    <field name="type"/>
 
38
    <field name="state"/>
 
39
    <field name="period_ids" colspan="4"/>
 
40
</form>'''
 
41
 
 
42
_types = {
 
43
    'pay_voucher':'Cash Payment Voucher',
 
44
    'bank_pay_voucher':'Bank Payment Voucher',
 
45
    'rec_voucher':'Cash Receipt Voucher',
 
46
    'bank_rec_voucher':'Bank Receipt Voucher',
 
47
    'cont_voucher':'Contra Voucher',
 
48
    'journal_sale_voucher':'Journal Sale Voucher',
 
49
    'journal_pur_voucher':'Journal Purchase Voucher'
 
50
}
 
51
_states = {
 
52
    'draft':'Draft',
 
53
    'proforma':'Pro-forma',
 
54
    'posted':'Posted',
 
55
    'cancel':'Cancel'  
 
56
}
 
57
 
 
58
_voucher_fields = {
 
59
    'type': {'string':'Voucher Type', 'type':'selection', 'selection':[
 
60
            ('pay_voucher','Cash Payment Voucher'),
 
61
            ('bank_pay_voucher','Bank Payment Voucher'),
 
62
            ('rec_voucher','Cash Receipt Voucher'),
 
63
            ('bank_rec_voucher','Bank Receipt Voucher'),
 
64
            ('cont_voucher','Contra Voucher'),
 
65
            ('journal_sale_voucher','Journal Sale Voucher'),
 
66
            ('journal_pur_voucher','Journal Purchase Voucher')], 'required':True},
 
67
    'state': {'string':'State', 'type':'selection', 'selection':[
 
68
                    ('draft','Draft'),
 
69
                    ('proforma','Pro-forma'),
 
70
                    ('posted','Posted'),
 
71
                    ('cancel','Cancel')], 'required':True},
 
72
    'period_ids': {'string':'Periods', 'type':'many2many', 'relation':'account.period'},
 
73
}
 
74
 
 
75
def _action_open_window(self, cr, uid, data, context):
 
76
    form = data['form']
 
77
    periods = []
 
78
    
 
79
    if not form['period_ids'][0][2]:
 
80
        pool = pooler.get_pool(cr.dbname)
 
81
        period = pool.get('account.period')
 
82
        year = pool.get('account.fiscalyear')
 
83
        
 
84
        year = year.find(cr, uid)
 
85
        periods = period.search(cr, uid, [('fiscalyear_id','=',year)])
 
86
    else:
 
87
        periods = form['period_ids'][0][2]
 
88
        
 
89
    return {
 
90
        'domain': "[('type','=','%s'), ('state','=','%s'), ('period_id','in',%s)]" % (form['type'], form['state'], periods),
 
91
        'name': "%s - %s" % (_types[form['type']], _states[form['state']]),
 
92
        'view_type': 'form',
 
93
        'view_mode': 'tree,form',
 
94
        'res_model': 'account.voucher',
 
95
        'view_id': False,
 
96
        'context': "{'type':'%s', 'state':'%s', 'period_id':%s}" % (form['type'], form['state'], periods),
 
97
        'type': 'ir.actions.act_window'
 
98
    }
 
99
 
 
100
class OpenVoucherEntries(wizard.interface):
 
101
    states = {
 
102
        'init': {
 
103
            'actions': [],
 
104
            'result': {'type': 'form', 'arch':_voucher_form, 'fields':_voucher_fields, 'state':[('end','Cancel'),('open','Open Voucher Entries')]}
 
105
        },
 
106
        'open': {
 
107
            'actions': [],
 
108
            'result': {'type': 'action', 'action': _action_open_window, 'state':'end'}
 
109
        }
 
110
    }
 
111
OpenVoucherEntries('account.voucher.open')
 
112
 
 
113
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: