~luc-demeyer/openobject-addons/7.0-account_financial_report_webkit-fixes

« back to all changes in this revision

Viewing changes to account_financial_report/wizard/wizard_account_balance_4_report.py

  • Committer: Gabriela (Vauxoo)
  • Date: 2012-01-20 23:53:06 UTC
  • mfrom: (5.1.2 miguel-bug-918857)
  • Revision ID: gabrielaquilarque97@gmail.com-20120120235306-jwp7ck633wj32lz7

[MERGE] Merge from lp:~vauxoo/account-financial-report/miguel-bug-918857.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- encoding: utf-8 -*-
 
2
###########################################################################
 
3
#    Module Writen to OpenERP, Open Source Management Solution
 
4
#    Copyright (C) OpenERP Venezuela (<http://openerp.com.ve>).
 
5
#    All Rights Reserved
 
6
###############Credits######################################################
 
7
#    Coded by:   Humberto Arocha humberto@openerp.com.ve
 
8
#                Angelica Barrios angelicaisabelb@gmail.com
 
9
#               Jordi Esteve <jesteve@zikzakmedia.com>
 
10
#               Javier Duran <javieredm@gmail.com>
 
11
#    Planified by: Humberto Arocha
 
12
#    Finance by: LUBCAN COL S.A.S http://www.lubcancol.com
 
13
#    Audited by: Humberto Arocha humberto@openerp.com.ve
 
14
#############################################################################
 
15
#    This program is free software: you can redistribute it and/or modify
 
16
#    it under the terms of the GNU General Public License as published by
 
17
#    the Free Software Foundation, either version 3 of the License, or
 
18
#    (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, see <http://www.gnu.org/licenses/>.
 
27
##############################################################################
 
28
 
2
29
from osv import osv,fields
3
30
import pooler
4
31
import time
 
32
 
5
33
class wizard_report(osv.osv_memory):
6
34
    _name = "wizard.report"
7
35
 
8
36
    _columns = {
9
37
        'company_id': fields.many2one('res.company','Company',required=True),
10
38
        'account_list': fields.many2many ('account.account','rel_wizard_account','account_list','account_id','Root accounts',required=True),
11
 
        'state': fields.selection([('bydate','By Date'),('byperiod','By Period'),('all','By Date and Period'),('none','No Filter')],'Date/Period Filter'),
 
39
        'filter': fields.selection([('bydate','By Date'),('byperiod','By Period'),('all','By Date and Period'),('none','No Filter')],'Date/Period Filter'),
12
40
        'fiscalyear': fields.many2one('account.fiscalyear','Fiscal year',help='Keep empty to use all open fiscal years to compute the balance',required=True),
13
41
        'periods': fields.many2many('account.period','rel_wizard_period','wizard_id','period_id','Periods',help='All periods in the fiscal year if empty'),
14
 
        'display_account': fields.selection([('bal_all','All'),('bal_solde', 'With balance'),('bal_mouvement','With movements')],'Display accounts'),
 
42
        'display_account': fields.selection([('all','All'),('con_balance', 'With balance'),('con_movimiento','With movements')],'Display accounts'),
15
43
        'display_account_level': fields.integer('Up to level',help='Display accounts up to this level (0 to show all)'),
16
 
        'date_from': fields.date('Start date',required=True),
17
 
        'date_to': fields.date('End date',required=True),
 
44
        'date_from': fields.date('Start date'),
 
45
        'date_to': fields.date('End date'),
18
46
        'tot_check': fields.boolean('Show Total'),
19
47
        'lab_str': fields.char('Description', size= 128),
20
 
        'inf_type': fields.selection([('bgen','Balance General'),('bcom','Balance Comprobacion'),('edogp','Estado Ganancias y Perdidas'),('bml','Libro Mayor Legal')],'Tipo Informe',required=True),
 
48
        'inf_type': fields.selection([('bgen','Balance General'),('bcom','Balance Comprobacion'),('edogp','Estado Ganancias y Perdidas')],'Tipo Informe',required=True),
 
49
        #~ 'type_report': fields.selection([('un_col','Una Columna'),('dos_col','Dos Columnas'),('cuatro_col','Cuatro Columnas')],'Tipo Informe',required=True),
21
50
    }
22
51
    
23
52
    _defaults = {
24
53
        'date_from': lambda *a: time.strftime('%Y-%m-%d'),
25
54
        'date_to': lambda *a: time.strftime('%Y-%m-%d'),
26
 
        'state': lambda *a:'byperiod',
 
55
        'filter': lambda *a:'byperiod',
27
56
        'display_account_level': lambda *a: 0,
28
57
        'inf_type': lambda *a:'bcom',
29
58
        'company_id': lambda *a: 1,
30
 
        'fiscalyear': lambda *a: 1,
31
 
        'display_account': lambda *a:'bal_mouvement',
32
 
        
 
59
        'fiscalyear': lambda self, cr, uid, c: self.pool.get('account.fiscalyear').find(cr, uid),
 
60
        'display_account': lambda *a:'con_movimiento',
33
61
    }
34
 
 
 
62
    
 
63
    def onchange_filter(self,cr,uid,ids,fiscalyear,filters,context=None):
 
64
        if context is None:
 
65
            context = {}
 
66
        res = {}
 
67
        if filters in ("bydate","all"):
 
68
            fisy = self.pool.get("account.fiscalyear")
 
69
            fis_actual = fisy.browse(cr,uid,fiscalyear,context=context)
 
70
            res = {'value':{'date_from': fis_actual.date_start, 'date_to': fis_actual.date_stop}}
 
71
        return res
 
72
    
35
73
    def _get_defaults(self, cr, uid, data, context=None):
36
74
        if context is None:
37
75
            context = {}
46
84
        data['form']['context'] = context
47
85
        return data['form']
48
86
 
49
 
 
50
87
    def _check_state(self, cr, uid, data, context=None):
51
88
        if context is None:
52
89
            context = {}
53
 
        if data['form']['state'] == 'bydate':
 
90
        if data['form']['filter'] == 'bydate':
54
91
           self._check_date(cr, uid, data, context)
55
92
        return data['form']
56
93
    
57
 
 
58
94
    def _check_date(self, cr, uid, data, context=None):
59
95
        if context is None:
60
96
            context = {}
 
97
            
 
98
        if data['form']['date_from'] > data['form']['date_to']:
 
99
            raise osv.except_osv(_('Error !'),('La fecha final debe ser mayor a la inicial'))
 
100
        
61
101
        sql = """SELECT f.id, f.date_start, f.date_stop
62
102
            FROM account_fiscalyear f
63
 
            WHERE '%s' between f.date_start and f.date_stop """%(data['form']['date_from'])
 
103
            WHERE '%s' = f.id """%(data['form']['fiscalyear'])
64
104
        cr.execute(sql)
65
105
        res = cr.dictfetchall()
 
106
 
66
107
        if res:
67
 
            if (data['form']['date_to'] > res[0]['date_stop'] or data['form']['date_to'] < res[0]['date_start']):
68
 
                raise  wizard.except_wizard(_('UserError'),_('Date to must be set between %s and %s') % (res[0]['date_start'], res[0]['date_stop']))
 
108
            if (data['form']['date_to'] > res[0]['date_stop'] or data['form']['date_from'] < res[0]['date_start']):
 
109
                raise osv.except_osv(_('UserError'),'Las fechas deben estar entre %s y %s' % (res[0]['date_start'], res[0]['date_stop']))
69
110
            else:
70
111
                return 'report'
71
112
        else:
72
 
            raise wizard.except_wizard(_('UserError'),_('Date not in a defined fiscal year'))
 
113
            raise osv.except_osv(_('UserError'),'No existe periodo fiscal')
73
114
 
74
115
    def print_report(self, cr, uid, ids,data, context=None):
75
116
        if context is None:
76
117
            context = {}
 
118
            
77
119
        data = {}
78
120
        data['ids'] = context.get('active_ids', [])
79
121
        data['model'] = context.get('active_model', 'ir.ui.menu')
80
122
        data['form'] = self.read(cr, uid, ids[0])
 
123
 
 
124
        if data['form']['filter'] == 'byperiod':
 
125
            del data['form']['date_from']
 
126
            del data['form']['date_to']
 
127
        elif data['form']['filter'] == 'bydate':
 
128
            self._check_date(cr, uid, data)
 
129
            del data['form']['periods']
 
130
        elif data['form']['filter'] == 'none':
 
131
            del data['form']['date_from']
 
132
            del data['form']['date_to']
 
133
            del data['form']['periods']
 
134
        else:
 
135
            self._check_date(cr, uid, data)
 
136
            lis2 = str(data['form']['periods']).replace("[","(").replace("]",")")
 
137
            sqlmm = """select min(p.date_start) as inicio, max(p.date_stop) as fin 
 
138
            from account_period p 
 
139
            where p.id in %s"""%lis2
 
140
            cr.execute(sqlmm)
 
141
            minmax = cr.dictfetchall()
 
142
            if minmax:
 
143
                if (data['form']['date_to'] < minmax[0]['inicio']) or (data['form']['date_from'] > minmax[0]['fin']):
 
144
                    raise osv.except_osv(_('Error !'),('La intersepcion entre el periodo y fecha es vacio'))
 
145
 
81
146
        return {'type': 'ir.actions.report.xml', 'report_name': 'wizard.report.reporte', 'datas': data}
82
 
 
 
147
            
83
148
wizard_report()