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

« back to all changes in this revision

Viewing changes to account_financial_report/wizard/wizard_general_ledger_report.py

  • Committer: Borja L.S.
  • Date: 2010-04-07 17:17:06 UTC
  • mto: This revision was merged to the branch mainline in revision 4498.
  • Revision ID: borjals@pexego.es-20100407171706-bdyhd0essc5237g2
[ADD] account_financial_report: Added the module from the 5.0 extra-addons.

  This module from the 5.0 extra-addons was missing on the 
  trunk extra-addons branch.
 
  We have just tested that it works with the 5.2 version.

  The module adds some extra financial/accounting reports:
  * Account chart list
  * Invoice list
  * Account move (journal ledger)
  * Account move line
  * Account balance compared period-fiscal year
  * Cumulative general ledger

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution   
 
5
#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
 
6
#    Copyright (c) 2009 Zikzakmedia S.L. (http://zikzakmedia.com) All Rights Reserved.
 
7
#                       Jordi Esteve <jesteve@zikzakmedia.com>
 
8
#    $Id$
 
9
#
 
10
#    This program is free software: you can redistribute it and/or modify
 
11
#    it under the terms of the GNU General Public License as published by
 
12
#    the Free Software Foundation, either version 3 of the License, or
 
13
#    (at your option) any later version.
 
14
#
 
15
#    This program is distributed in the hope that it will be useful,
 
16
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
#    GNU General Public License for more details.
 
19
#
 
20
#    You should have received a copy of the GNU General Public License
 
21
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
22
#
 
23
##############################################################################
 
24
 
 
25
import wizard
 
26
import pooler
 
27
import locale
 
28
import time
 
29
from tools.translate import _
 
30
 
 
31
account_form = '''<?xml version="1.0"?>
 
32
<form string="Select parent account">
 
33
    <field name="Account_list" colspan="4"/>
 
34
</form>'''
 
35
 
 
36
account_fields = {
 
37
    'Account_list': {'string':'Account', 'type':'many2many', 'relation':'account.account', 'required':True ,'domain':[]},
 
38
}
 
39
 
 
40
period_form = '''<?xml version="1.0"?>
 
41
<form string="Select Date-Period">
 
42
    <field name="company_id" colspan="4"/>
 
43
    <newline/>
 
44
    <field name="fiscalyear"/>
 
45
    <label colspan="2" string="(Keep empty for all open fiscal years)" align="0.0"/>
 
46
    <newline/>
 
47
 
 
48
    <field name="display_account" required="True"/>
 
49
    <field name="sortbydate" required="True"/>
 
50
    <field name="landscape"/>
 
51
    <field name="amount_currency"/>
 
52
    <field name="initial_balance"/>  
 
53
    <newline/>
 
54
    <separator string="Filters" colspan="4"/>
 
55
    <field name="state" required="True"/>
 
56
    <newline/>
 
57
    <group attrs="{'invisible':[('state','=','none')]}" colspan="4">
 
58
        <group attrs="{'invisible':[('state','=','byperiod')]}" colspan="4">
 
59
            <separator string="Date Filter" colspan="4"/>
 
60
            <field name="date_from"/>
 
61
            <field name="date_to"/>
 
62
        </group>
 
63
        <group attrs="{'invisible':[('state','=','bydate')]}" colspan="4">
 
64
            <separator string="Filter on Periods" colspan="4"/>
 
65
            <field name="periods" colspan="4" nolabel="1"/>
 
66
        </group>
 
67
    </group> 
 
68
</form>'''
 
69
 
 
70
period_fields = {
 
71
    'company_id': {'string': 'Company', 'type': 'many2one', 'relation': 'res.company', 'required': True},
 
72
    'state':{
 
73
        'string':"Date/Period Filter",
 
74
        'type':'selection',
 
75
        'selection':[('bydate','By Date'),('byperiod','By Period'),('all','By Date and Period'),('none','No Filter')],
 
76
        'default': lambda *a:'none'
 
77
    },
 
78
    'fiscalyear': {'string': 'Fiscal year', 'type': 'many2one', 'relation': 'account.fiscalyear',
 
79
        'help': 'Keep empty for all open fiscal year'},
 
80
    'periods': {'string': 'Periods', 'type': 'many2many', 'relation': 'account.period', 'help': 'All periods if empty'},
 
81
    'sortbydate':{'string':"Sort by:", 'type':'selection', 'selection':[('sort_date','Date'),('sort_mvt','Movement')]},
 
82
    'display_account':{'string':"Display accounts ", 'type':'selection', 'selection':[('bal_mouvement','With movements'),('bal_all','All'),('bal_solde','With balance is not equal to 0')]},
 
83
    'landscape':{'string':"Landscape Mode", 'type':'boolean'},
 
84
    'initial_balance':{'string':"Show initial balances", 'type':'boolean'},
 
85
    'amount_currency':{'string':"With Currency", 'type':'boolean'},
 
86
    'date_from': {'string':"Start date", 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-01-01')},
 
87
    'date_to': {'string':"End date", 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
 
88
}
 
89
 
 
90
 
 
91
class wizard_report(wizard.interface):
 
92
    def _get_defaults(self, cr, uid, data, context={}):
 
93
        user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid, context=context)
 
94
        if user.company_id:
 
95
            company_id = user.company_id.id
 
96
        else:
 
97
            company_id = pooler.get_pool(cr.dbname).get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
 
98
        data['form']['company_id'] = company_id
 
99
        fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear')
 
100
        data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid)
 
101
        # Better allow users to set theirs defaults
 
102
        #periods_obj=pooler.get_pool(cr.dbname).get('account.period')
 
103
        #data['form']['periods'] =periods_obj.search(cr, uid, [('fiscalyear_id','=',data['form']['fiscalyear'])])
 
104
        #data['form']['display_account']='bal_all'
 
105
        #data['form']['sortbydate'] = 'sort_date'
 
106
        #data['form']['landscape']=True
 
107
        #data['form']['amount_currency'] = True
 
108
        data['form']['context'] = context
 
109
        return data['form']
 
110
 
 
111
 
 
112
    def _check_path(self, cr, uid, data, context):
 
113
        if data['model'] == 'account.account':
 
114
            return 'checktype'
 
115
        else:
 
116
            return 'account_selection'
 
117
 
 
118
 
 
119
    def _check(self, cr, uid, data, context):
 
120
        if data['form']['landscape']==True:
 
121
            return 'report_landscape'
 
122
        else:
 
123
            return 'report'
 
124
 
 
125
 
 
126
    def _check_date(self, cr, uid, data, context):
 
127
        sql = """SELECT f.id, f.date_start, f.date_stop
 
128
            FROM account_fiscalyear f
 
129
            WHERE '%s' between f.date_start and f.date_stop """ % (data['form']['date_from'])
 
130
        cr.execute(sql)
 
131
        res = cr.dictfetchall()
 
132
        if res:
 
133
            if (data['form']['date_to'] > res[0]['date_stop'] or data['form']['date_to'] < res[0]['date_start']):
 
134
                    raise  wizard.except_wizard(_('UserError'),_('Date to must be set between %s and %s') % (str(res[0]['date_start']), str(res[0]['date_stop'])))
 
135
            else:
 
136
                return 'checkreport'
 
137
        else:
 
138
            raise wizard.except_wizard(_('UserError'),_('Date not in a defined fiscal year'))
 
139
 
 
140
 
 
141
    def _check_state(self, cr, uid, data, context):
 
142
            if data['form']['state'] == 'bydate':
 
143
               self._check_date(cr, uid, data, context)
 
144
    #           data['form']['fiscalyear'] = 0
 
145
    #        else :
 
146
    #           data['form']['fiscalyear'] = 1
 
147
            return data['form']
 
148
 
 
149
 
 
150
    states = {
 
151
        'init': {
 
152
            'actions': [],
 
153
            'result': {'type':'choice','next_state':_check_path}
 
154
        },
 
155
        'account_selection': {
 
156
            'actions': [],
 
157
            'result': {'type':'form', 'arch':account_form,'fields':account_fields, 'state':[('end','Cancel','gtk-cancel'),('checktype','Next','gtk-go-forward')]}
 
158
        },
 
159
        'checktype': {
 
160
            'actions': [_get_defaults],
 
161
            'result': {'type':'form', 'arch':period_form, 'fields':period_fields, 'state':[('end','Cancel','gtk-cancel'),('checkreport','Print','gtk-print')]}
 
162
        },
 
163
        'checkreport': {
 
164
            'actions': [],
 
165
            'result': {'type':'choice','next_state':_check}
 
166
        },
 
167
        'report_landscape': {
 
168
            'actions': [_check_state],
 
169
            'result': {'type':'print', 'report':'account.general.ledger.cumulative.landscape', 'state':'end'}
 
170
        },
 
171
        'report': {
 
172
            'actions': [_check_state],
 
173
            'result': {'type':'print', 'report':'account.general.ledger.cumulative', 'state':'end'}
 
174
        }
 
175
    }
 
176
wizard_report('account.general.ledger.cumulative.report')
 
177
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: