~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_2_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:
29
29
from osv import osv,fields
30
30
import pooler
31
31
import time
 
32
 
32
33
class wizard_account_balance_gene_2(osv.osv_memory):
33
34
    _name = "wizard.report.account.balance.gene.2"
34
35
 
35
36
    _columns = {
36
37
        'company_id': fields.many2one('res.company','Company',required=True),
37
38
        'account_list': fields.many2many ('account.account','rel_wizard_account','account_list','account_id','Root accounts',required=True),
38
 
        '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'),
39
40
        'fiscalyear': fields.many2one('account.fiscalyear','Fiscal year',help='Keep empty to use all open fiscal years to compute the balance',required=True),
40
41
        'periods': fields.many2many('account.period','rel_wizard_period','wizard_id','period_id','Periods',help='All periods in the fiscal year if empty'),
41
 
        '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'),
42
43
        'display_account_level': fields.integer('Up to level',help='Display accounts up to this level (0 to show all)'),
43
 
        'date_from': fields.date('Start date',required=True),
44
 
        'date_to': fields.date('End date',required=True),
 
44
        'date_from': fields.date('Start date'),
 
45
        'date_to': fields.date('End date'),
45
46
        'tot_check': fields.boolean('Show Total'),
46
47
        'lab_str': fields.char('Description', size= 128),
47
 
        'inf_type': fields.selection([('bgen','Balance General'),('bcom','Balance Comprobacion'),('edogp','Estado Ganancias y Perdidas'),('bdl','Libro Diario 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),
48
50
    }
49
51
    
50
52
    _defaults = {
51
53
        'date_from': lambda *a: time.strftime('%Y-%m-%d'),
52
54
        'date_to': lambda *a: time.strftime('%Y-%m-%d'),
53
 
        'state': lambda *a:'byperiod',
 
55
        'filter': lambda *a:'byperiod',
54
56
        'display_account_level': lambda *a: 0,
55
57
        'inf_type': lambda *a:'bcom',
56
58
        'company_id': lambda *a: 1,
57
 
        'fiscalyear': lambda *a: 1,
58
 
        'display_account': lambda *a:'bal_mouvement',
59
 
        
 
59
        'fiscalyear': lambda self, cr, uid, c: self.pool.get('account.fiscalyear').find(cr, uid),
 
60
        'display_account': lambda *a:'con_movimiento',
60
61
    }
61
 
 
 
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
    
62
73
    def _get_defaults(self, cr, uid, data, context=None):
63
74
        if context is None:
64
75
            context = {}
73
84
        data['form']['context'] = context
74
85
        return data['form']
75
86
 
76
 
 
77
87
    def _check_state(self, cr, uid, data, context=None):
78
88
        if context is None:
79
89
            context = {}
80
 
        if data['form']['state'] == 'bydate':
 
90
        if data['form']['filter'] == 'bydate':
81
91
           self._check_date(cr, uid, data, context)
82
92
        return data['form']
83
93
    
84
 
 
85
94
    def _check_date(self, cr, uid, data, context=None):
86
95
        if context is None:
87
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
        
88
101
        sql = """SELECT f.id, f.date_start, f.date_stop
89
102
            FROM account_fiscalyear f
90
 
            WHERE '%s' between f.date_start and f.date_stop """%(data['form']['date_from'])
 
103
            WHERE '%s' = f.id """%(data['form']['fiscalyear'])
91
104
        cr.execute(sql)
92
105
        res = cr.dictfetchall()
 
106
 
93
107
        if res:
94
 
            if (data['form']['date_to'] > res[0]['date_stop'] or data['form']['date_to'] < res[0]['date_start']):
95
 
                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']))
96
110
            else:
97
111
                return 'report'
98
112
        else:
99
 
            raise wizard.except_wizard(_('UserError'),_('Date not in a defined fiscal year'))
 
113
            raise osv.except_osv(_('UserError'),'No existe periodo fiscal')
100
114
 
101
115
    def print_report(self, cr, uid, ids,data, context=None):
102
116
        if context is None:
103
117
            context = {}
 
118
            
104
119
        data = {}
105
120
        data['ids'] = context.get('active_ids', [])
106
121
        data['model'] = context.get('active_model', 'ir.ui.menu')
107
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
 
108
146
        return {'type': 'ir.actions.report.xml', 'report_name': 'account.account.balance.gene.2', 'datas': data}
109
147
 
110
148
wizard_account_balance_gene_2()
111
 
 
112