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

« back to all changes in this revision

Viewing changes to account_financial_report/wizard/wizard_account_balance_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 time
 
28
from tools.translate import _
 
29
 
 
30
period_form = '''<?xml version="1.0"?>
 
31
<form string="Select period">
 
32
    <field name="company_id"/>
 
33
    <field name="display_account" required = "True"/>
 
34
    <newline/>
 
35
    <field name="fiscalyear"/>
 
36
    <label colspan="2" string="(Keep empty for all open fiscal years)" align="0.0"/>
 
37
    <newline/>
 
38
    <separator string="Filters" colspan="4"/>
 
39
    <field name="state" required="True"/>
 
40
    <newline/>
 
41
    <group attrs="{'invisible':[('state','=','none')]}" colspan="4">
 
42
        <group attrs="{'invisible':[('state','=','byperiod')]}" colspan="4">
 
43
            <separator string="Date Filter" colspan="4"/>
 
44
            <field name="date_from"/>
 
45
            <field name="date_to"/>
 
46
        </group>
 
47
        <group attrs="{'invisible':[('state','=','bydate')]}" colspan="4">
 
48
            <separator string="Filter on Periods" colspan="4"/>
 
49
            <field name="periods" colspan="4" nolabel="1"/>
 
50
        </group>
 
51
    </group>
 
52
</form>'''
 
53
 
 
54
period_fields = {
 
55
    'company_id': {'string': 'Company', 'type': 'many2one', 'relation': 'res.company', 'required': True},
 
56
    'state':{
 
57
        'string':"Date/Period Filter",
 
58
        'type':'selection',
 
59
        'selection':[('bydate','By Date'),('byperiod','By Period'),('all','By Date and Period'),('none','No Filter')],
 
60
        'default': lambda *a:'none'
 
61
    },
 
62
    'fiscalyear': {
 
63
        'string':'Fiscal year',
 
64
        'type':'many2one',
 
65
        'relation':'account.fiscalyear',
 
66
        'help':'Keep empty for all open fiscal year'
 
67
    },
 
68
    'periods': {'string': 'Periods', 'type': 'many2many', 'relation': 'account.period', 'help': 'All periods if empty'},
 
69
    'display_account':{'string':"Display accounts ", 'type':'selection', 'selection':[('bal_mouvement','With movements'),('bal_all','All'),('bal_solde', 'With balance is not equal to 0')]},
 
70
    'date_from': {'string':"Start date", 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-01-01')},
 
71
    'date_to': {'string':"End date", 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
 
72
}
 
73
 
 
74
account_form = '''<?xml version="1.0"?>
 
75
<form string="Select parent account">
 
76
    <field name="Account_list" colspan="4"/>
 
77
</form>'''
 
78
 
 
79
account_fields = {
 
80
    'Account_list': {'string':'Account', 'type':'many2many', 'relation':'account.account', 'required':True ,'domain':[]},
 
81
}
 
82
 
 
83
 
 
84
class wizard_report(wizard.interface):
 
85
    def _get_defaults(self, cr, uid, data, context={}):
 
86
        user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid, context=context)
 
87
        if user.company_id:
 
88
           company_id = user.company_id.id
 
89
        else:
 
90
           company_id = pooler.get_pool(cr.dbname).get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
 
91
        data['form']['company_id'] = company_id
 
92
        fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear')
 
93
        data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid)
 
94
        # Better allow users to set theirs defaults
 
95
        #periods_obj=pooler.get_pool(cr.dbname).get('account.period')
 
96
        #data['form']['periods'] = periods_obj.search(cr, uid, [('fiscalyear_id','=',data['form']['fiscalyear'])])
 
97
        #data['form']['display_account'] = 'bal_all'
 
98
        data['form']['context'] = context
 
99
        return data['form']
 
100
 
 
101
 
 
102
    def _check_path(self, cr, uid, data, context):
 
103
        if data['model'] == 'account.account':
 
104
           return 'checktype'
 
105
        else:
 
106
           return 'account_selection'
 
107
 
 
108
 
 
109
    def _check_state(self, cr, uid, data, context):
 
110
        if data['form']['state'] == 'bydate':
 
111
           self._check_date(cr, uid, data, context)
 
112
        return data['form']
 
113
    
 
114
 
 
115
    def _check_date(self, cr, uid, data, context):
 
116
        sql = """SELECT f.id, f.date_start, f.date_stop
 
117
            FROM account_fiscalyear f
 
118
            WHERE '%s' between f.date_start and f.date_stop """%(data['form']['date_from'])
 
119
        cr.execute(sql)
 
120
        res = cr.dictfetchall()
 
121
        if res:
 
122
            if (data['form']['date_to'] > res[0]['date_stop'] or data['form']['date_to'] < res[0]['date_start']):
 
123
                raise  wizard.except_wizard(_('UserError'),_('Date to must be set between %s and %s') % (res[0]['date_start'], res[0]['date_stop']))
 
124
            else:
 
125
                return 'report'
 
126
        else:
 
127
            raise wizard.except_wizard(_('UserError'),_('Date not in a defined fiscal year'))
 
128
 
 
129
 
 
130
    states = {
 
131
 
 
132
        'init': {
 
133
            'actions': [],
 
134
            'result': {'type':'choice','next_state':_check_path}
 
135
        },
 
136
        'account_selection': {
 
137
            'actions': [],
 
138
            'result': {'type':'form', 'arch':account_form,'fields':account_fields, 'state':[('end','Cancel','gtk-cancel'),('checktype','Next','gtk-go-forward')]}
 
139
        },
 
140
        'checktype': {
 
141
            'actions': [_get_defaults],
 
142
            'result': {'type':'form', 'arch':period_form, 'fields':period_fields, 'state':[('end','Cancel','gtk-cancel'),('report','Print','gtk-print')]}
 
143
        },
 
144
        'report': {
 
145
            'actions': [_check_state],
 
146
            'result': {'type':'print', 'report':'account.balance.full', 'state':'end'}
 
147
        }
 
148
    }
 
149
wizard_report('account.balance.full.report')
 
150
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: