From bc64a38e6f5d5470499d0d682f6bee67789de730 Mon Sep 17 00:00:00 2001 From: Miguel Delgado Date: Fri, 20 Jan 2012 11:43:05 -0530 Subject: [PATCH 1/2] [FIX] Se cambio el campo state por filter ya que el primero causaba errores en la impresion de los reportes --- .../report/account_balance.py | 15 ++++++------ .../report/account_balance_2_cols.py | 10 ++++---- .../report/account_balance_4_cols.py | 18 +++++++------- .../report/balance_full.rml | 4 ++-- .../wizard/account_report_wizard.xml | 24 +++++++++---------- .../wizard/wizard_account_balance_2_report.py | 6 ++--- .../wizard/wizard_account_balance_4_report.py | 6 ++--- .../wizard/wizard_account_balance_report.py | 10 +++++--- 8 files changed, 49 insertions(+), 44 deletions(-) diff --git a/account_financial_report/report/account_balance.py b/account_financial_report/report/account_balance.py index 1f4a14ca..5cc60abc 100644 --- a/account_financial_report/report/account_balance.py +++ b/account_financial_report/report/account_balance.py @@ -107,12 +107,12 @@ class account_balance(report_sxw.rml_parse): periods_str = None fiscalyear_id = form['fiscalyear'] or fiscalyear_obj.find(self.cr, self.uid) period_ids = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear_id),('special','=',False)]) - if form['state'] in ['byperiod', 'all']: + if form['filter'] in ['byperiod', 'all']: period_ids = form['periods'] periods_str = ', '.join([period.name or period.code for period in period_obj.browse(self.cr, self.uid, period_ids)]) dates_str = None - if form['state'] in ['bydate', 'all']: + if form['filter'] in ['bydate', 'all']: dates_str = self.formatLang(form['date_from'], date=True) + ' - ' + self.formatLang(form['date_to'], date=True) + ' ' return {'periods':periods_str, 'date':dates_str} @@ -184,13 +184,12 @@ class account_balance(report_sxw.rml_parse): ctx['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),'|',('special','=',False),('date_stop','<',fiscalyear.date_stop)]) else: # Use all the open fiscal years - open_fiscalyear_ids = fiscalyear_obj.search(self.cr, self.uid, [('state','=','draft')]) + open_fiscalyear_ids = fiscalyear_obj.search(self.cr, self.uid, [('filter','=','draft')]) ctx['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','in',open_fiscalyear_ids),'|',('special','=',False),('date_stop','<',fiscalyear.date_stop)]) fy_balance = {} for acc in account_obj.read(self.cr, self.uid, [x[0] for x in account_ids], ['balance'], ctx): fy_balance[acc['id']] = acc['balance'] - # # Calculate the FY Debit/Credit # (from full fiscal year without opening or closing periods) @@ -204,12 +203,12 @@ class account_balance(report_sxw.rml_parse): # (from the selected period or all the non special periods in the fy) # ctx = self.context.copy() - ctx['state'] = form.get('state','all') + ctx['filter'] = form.get('filter','all') ctx['fiscalyear'] = fiscalyear.id ctx['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id)]) - if form['state'] in ['byperiod', 'all']: + if form['filter'] in ['byperiod', 'all']: ctx['periods'] = form['periods'] - if form['state'] in ['bydate', 'all']: + if form['filter'] in ['bydate', 'all']: ctx['date_from'] = form['date_from'] ctx['date_to'] = form['date_to'] @@ -217,6 +216,7 @@ class account_balance(report_sxw.rml_parse): val = account_obj.browse(self.cr, self.uid, [aa_id[0] for aa_id in account_ids], ctx) c = 0 for aa_id in account_ids: + print '%s %s \n'%(val[c].name,val[c].balance) new_acc = { 'id' :val[c].id, 'type' :val[c].type, @@ -294,6 +294,7 @@ class account_balance(report_sxw.rml_parse): if form['tot_check'] and res['type'] == 'view' and res['level'] == 1 and (res['id'] not in tot): tot[res['id']] = True tot_eje += res['balance'] + print 'tot_eje',tot_eje if form['tot_check']: str_label = form['lab_str'] res2 = { diff --git a/account_financial_report/report/account_balance_2_cols.py b/account_financial_report/report/account_balance_2_cols.py index 9da31018..5279c9a9 100644 --- a/account_financial_report/report/account_balance_2_cols.py +++ b/account_financial_report/report/account_balance_2_cols.py @@ -108,12 +108,12 @@ class account_balance(report_sxw.rml_parse): periods_str = None fiscalyear_id = form['fiscalyear'] or fiscalyear_obj.find(self.cr, self.uid) period_ids = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear_id),('special','=',False)]) - if form['state'] in ['byperiod', 'all']: + if form['filter'] in ['byperiod', 'all']: period_ids = form['periods'] periods_str = ', '.join([period.name or period.code for period in period_obj.browse(self.cr, self.uid, period_ids)]) dates_str = None - if form['state'] in ['bydate', 'all']: + if form['filter'] in ['bydate', 'all']: dates_str = self.formatLang(form['date_from'], date=True) + ' - ' + self.formatLang(form['date_to'], date=True) + ' ' return {'periods':periods_str, 'date':dates_str} @@ -180,13 +180,13 @@ class account_balance(report_sxw.rml_parse): # ctx = self.context.copy() - ctx['state'] = form.get('state','all') + ctx['filter'] = form.get('filter','all') ctx['fiscalyear'] = fiscalyear.id ctx['periods'] = form.get('periods') - if form['state'] in ['byperiod', 'all']: + if form['filter'] in ['byperiod', 'all']: date_start = min([period.date_start for period in period_obj.browse(self.cr, self.uid, ctx['periods'])]) ctx['periods'] = ctx['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('date_stop','<=',date_start)]) - if form['state'] in ['bydate', 'all']: + if form['filter'] in ['bydate', 'all']: ctx['date_from'] = form['date_from'] ctx['date_to'] = form['date_to'] diff --git a/account_financial_report/report/account_balance_4_cols.py b/account_financial_report/report/account_balance_4_cols.py index 959a84d8..8075c7aa 100644 --- a/account_financial_report/report/account_balance_4_cols.py +++ b/account_financial_report/report/account_balance_4_cols.py @@ -108,12 +108,12 @@ class account_balance(report_sxw.rml_parse): periods_str = None fiscalyear_id = form['fiscalyear'] or fiscalyear_obj.find(self.cr, self.uid) period_ids = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear_id),('special','=',False)]) - if form['state'] in ['byperiod', 'all']: + if form['filter'] in ['byperiod', 'all']: period_ids = form['periods'] periods_str = ', '.join([period.name or period.code for period in period_obj.browse(self.cr, self.uid, period_ids)]) dates_str = None - if form['state'] in ['bydate', 'all']: + if form['filter'] in ['bydate', 'all']: dates_str = self.formatLang(form['date_from'], date=True) + ' - ' + self.formatLang(form['date_to'], date=True) + ' ' return {'periods':periods_str, 'date':dates_str} @@ -186,12 +186,12 @@ class account_balance(report_sxw.rml_parse): ############################################################################# ctx = self.context.copy() - ctx['state'] = form.get('state','all') + ctx['filter'] = form.get('filter','all') ctx['fiscalyear'] = fiscalyear.id ctx['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('special','=',False)]) - if form['state'] in ['byperiod', 'all']: + if form['filter'] in ['byperiod', 'all']: ctx['periods'] = period_obj.search(self.cr, self.uid, [('id','in',form['periods'] or ctx['periods']),('special','=',False)]) - if form['state'] in ['bydate', 'all']: + if form['filter'] in ['bydate', 'all']: ctx['date_from'] = form['date_from'] ctx['date_to'] = form['date_to'] @@ -227,20 +227,20 @@ class account_balance(report_sxw.rml_parse): ############################################################################# ctx = self.context.copy() - ctx['state'] = form.get('state','all') + ctx['filter'] = form.get('filter','all') ctx['fiscalyear'] = fiscalyear.id - if form['state'] in ['byperiod', 'all']: + if form['filter'] in ['byperiod', 'all']: ctx['periods'] = form['periods'] date_start = min([period.date_start for period in period_obj.browse(self.cr, self.uid, ctx['periods'])]) ctx['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('date_stop','<=',date_start)]) if not ctx['periods']: missing_period() - elif form['state'] in ['bydate']: + elif form['filter'] in ['bydate']: ctx['date_from'] = fiscalyear.date_start ctx['date_to'] = form['date_from'] ctx['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('date_stop','<=',ctx['date_to'])]) - elif form['state'] == 'none': + elif form['filter'] == 'none': ctx['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('special','=',True)]) date_start = min([period.date_start for period in period_obj.browse(self.cr, self.uid, ctx['periods'])]) ctx['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('date_start','<=',date_start),('special','=',True)]) diff --git a/account_financial_report/report/balance_full.rml b/account_financial_report/report/balance_full.rml index 67149646..6c9127d4 100644 --- a/account_financial_report/report/balance_full.rml +++ b/account_financial_report/report/balance_full.rml @@ -108,7 +108,7 @@ Cuenta - + Balance @@ -127,7 +127,7 @@ [[ a['type']<>'view' and setTag('para','para',{'fontName':"Courier"}) or removeParentNode('font') ]] - [[ (a['total']==True) and formatLang(a['balance']) or '']] + [[(a['total']==True) and formatLang(a['balance']) or '']] diff --git a/account_financial_report/wizard/account_report_wizard.xml b/account_financial_report/wizard/account_report_wizard.xml index 7870e94d..6bbe3b81 100644 --- a/account_financial_report/wizard/account_report_wizard.xml +++ b/account_financial_report/wizard/account_report_wizard.xml @@ -22,16 +22,16 @@ - + - - + + - + @@ -87,15 +87,15 @@ - + - - + + - + @@ -149,15 +149,15 @@ - + - - + + - + diff --git a/account_financial_report/wizard/wizard_account_balance_2_report.py b/account_financial_report/wizard/wizard_account_balance_2_report.py index 1b55ffe7..bb41cb1a 100644 --- a/account_financial_report/wizard/wizard_account_balance_2_report.py +++ b/account_financial_report/wizard/wizard_account_balance_2_report.py @@ -35,7 +35,7 @@ class wizard_account_balance_gene_2(osv.osv_memory): _columns = { 'company_id': fields.many2one('res.company','Company',required=True), 'account_list': fields.many2many ('account.account','rel_wizard_account','account_list','account_id','Root accounts',required=True), - 'state': fields.selection([('bydate','By Date'),('byperiod','By Period'),('all','By Date and Period'),('none','No Filter')],'Date/Period Filter'), + 'filter': fields.selection([('bydate','By Date'),('byperiod','By Period'),('all','By Date and Period'),('none','No Filter')],'Date/Period Filter'), 'fiscalyear': fields.many2one('account.fiscalyear','Fiscal year',help='Keep empty to use all open fiscal years to compute the balance',required=True), 'periods': fields.many2many('account.period','rel_wizard_period','wizard_id','period_id','Periods',help='All periods in the fiscal year if empty'), 'display_account': fields.selection([('bal_all','All'),('bal_solde', 'With balance'),('bal_mouvement','With movements')],'Display accounts'), @@ -50,7 +50,7 @@ class wizard_account_balance_gene_2(osv.osv_memory): _defaults = { 'date_from': lambda *a: time.strftime('%Y-%m-%d'), 'date_to': lambda *a: time.strftime('%Y-%m-%d'), - 'state': lambda *a:'byperiod', + 'filter': lambda *a:'byperiod', 'display_account_level': lambda *a: 0, 'inf_type': lambda *a:'bcom', 'company_id': lambda *a: 1, @@ -77,7 +77,7 @@ class wizard_account_balance_gene_2(osv.osv_memory): def _check_state(self, cr, uid, data, context=None): if context is None: context = {} - if data['form']['state'] == 'bydate': + if data['form']['filter'] == 'bydate': self._check_date(cr, uid, data, context) return data['form'] diff --git a/account_financial_report/wizard/wizard_account_balance_4_report.py b/account_financial_report/wizard/wizard_account_balance_4_report.py index 9810ce76..1c4b1343 100644 --- a/account_financial_report/wizard/wizard_account_balance_4_report.py +++ b/account_financial_report/wizard/wizard_account_balance_4_report.py @@ -8,7 +8,7 @@ class wizard_report(osv.osv_memory): _columns = { 'company_id': fields.many2one('res.company','Company',required=True), 'account_list': fields.many2many ('account.account','rel_wizard_account','account_list','account_id','Root accounts',required=True), - 'state': fields.selection([('bydate','By Date'),('byperiod','By Period'),('all','By Date and Period'),('none','No Filter')],'Date/Period Filter'), + 'filter': fields.selection([('bydate','By Date'),('byperiod','By Period'),('all','By Date and Period'),('none','No Filter')],'Date/Period Filter'), 'fiscalyear': fields.many2one('account.fiscalyear','Fiscal year',help='Keep empty to use all open fiscal years to compute the balance',required=True), 'periods': fields.many2many('account.period','rel_wizard_period','wizard_id','period_id','Periods',help='All periods in the fiscal year if empty'), 'display_account': fields.selection([('bal_all','All'),('bal_solde', 'With balance'),('bal_mouvement','With movements')],'Display accounts'), @@ -23,7 +23,7 @@ class wizard_report(osv.osv_memory): _defaults = { 'date_from': lambda *a: time.strftime('%Y-%m-%d'), 'date_to': lambda *a: time.strftime('%Y-%m-%d'), - 'state': lambda *a:'byperiod', + 'filter': lambda *a:'byperiod', 'display_account_level': lambda *a: 0, 'inf_type': lambda *a:'bcom', 'company_id': lambda *a: 1, @@ -50,7 +50,7 @@ class wizard_report(osv.osv_memory): def _check_state(self, cr, uid, data, context=None): if context is None: context = {} - if data['form']['state'] == 'bydate': + if data['form']['filter'] == 'bydate': self._check_date(cr, uid, data, context) return data['form'] diff --git a/account_financial_report/wizard/wizard_account_balance_report.py b/account_financial_report/wizard/wizard_account_balance_report.py index 5b75145d..2ff078e0 100644 --- a/account_financial_report/wizard/wizard_account_balance_report.py +++ b/account_financial_report/wizard/wizard_account_balance_report.py @@ -30,13 +30,14 @@ from osv import osv,fields import pooler import time + class wizard_account_balance_gene(osv.osv_memory): _name = "wizard.report.account.balance.gene" _columns = { 'company_id': fields.many2one('res.company','Company',required=True), 'account_list': fields.many2many ('account.account','rel_wizard_account','account_list','account_id','Root accounts',required=True), - 'state': fields.selection([('bydate','By Date'),('byperiod','By Period'),('all','By Date and Period'),('none','No Filter')],'Date/Period Filter'), + 'filter': fields.selection([('bydate','By Date'),('byperiod','By Period'),('all','By Date and Period'),('none','No Filter')],'Date/Period Filter'), 'fiscalyear': fields.many2one('account.fiscalyear','Fiscal year',help='Keep empty to use all open fiscal years to compute the balance',required=True), 'periods': fields.many2many('account.period','rel_wizard_period','wizard_id','period_id','Periods',help='All periods in the fiscal year if empty'), 'display_account': fields.selection([('bal_all','All'),('bal_solde', 'With balance'),('bal_mouvement','With movements')],'Display accounts'), @@ -51,7 +52,7 @@ class wizard_account_balance_gene(osv.osv_memory): _defaults = { 'date_from': lambda *a: time.strftime('%Y-%m-%d'), 'date_to': lambda *a: time.strftime('%Y-%m-%d'), - 'state': lambda *a:'byperiod', + 'filter': lambda *a:'byperiod', 'display_account_level': lambda *a: 0, 'inf_type': lambda *a:'bcom', 'company_id': lambda *a: 1, @@ -78,7 +79,7 @@ class wizard_account_balance_gene(osv.osv_memory): def _check_state(self, cr, uid, data, context=None): if context is None: context = {} - if data['form']['state'] == 'bydate': + if data['form']['filter'] == 'bydate': self._check_date(cr, uid, data, context) return data['form'] @@ -106,6 +107,9 @@ class wizard_account_balance_gene(osv.osv_memory): data['ids'] = context.get('active_ids', []) data['model'] = context.get('active_model', 'ir.ui.menu') data['form'] = self.read(cr, uid, ids[0]) + + print 'data',data + return {'type': 'ir.actions.report.xml', 'report_name': 'account.account.balance.gene', 'datas': data} wizard_account_balance_gene() From 50803f27e955a013d817d354171864365724d9ae Mon Sep 17 00:00:00 2001 From: Miguel Delgado Date: Fri, 20 Jan 2012 18:04:50 -0530 Subject: [PATCH 2/2] [FIX] bug 918857, ademas de adecuar las cabeceras de los reportes a la nueva ley --- .../report/account_balance.py | 34 +++-- .../report/account_balance_2_cols.py | 142 ++++++++++++------ .../report/account_balance_4_cols.py | 37 ++--- .../report/balance_full.rml | 23 +-- .../report/balance_full_2_cols.rml | 46 ++---- .../report/balance_full_4_cols.rml | 21 +-- .../wizard/wizard_account_balance_2_report.py | 68 +++++++-- .../wizard/wizard_account_balance_4_report.py | 95 ++++++++++-- .../wizard/wizard_account_balance_report.py | 68 ++++++--- 9 files changed, 337 insertions(+), 197 deletions(-) diff --git a/account_financial_report/report/account_balance.py b/account_financial_report/report/account_balance.py index 5cc60abc..8f25dc0a 100644 --- a/account_financial_report/report/account_balance.py +++ b/account_financial_report/report/account_balance.py @@ -53,8 +53,8 @@ class account_balance(report_sxw.rml_parse): 'lines': self.lines, 'get_fiscalyear_text': self.get_fiscalyear_text, 'get_periods_and_date_text': self.get_periods_and_date_text, - 'get_inf_text': self.get_informe_text, - 'get_month':self._get_month, + 'get_informe_text': self.get_informe_text, + 'get_month':self.get_month, }) self.context = context @@ -72,21 +72,25 @@ class account_balance(report_sxw.rml_parse): fiscalyear = fiscalyear_obj.browse(self.cr, self.uid, fiscalyear_obj.find(self.cr, self.uid)) return "%s*" % (fiscalyear.name or fiscalyear.code) - def _get_month(self, form): + def get_month(self, form): ''' return day, year and month ''' - - months=["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"] - - mes = months[time.strptime(form['date_to'],"%Y-%m-%d")[1]-1] - ano = time.strptime(form['date_to'],"%Y-%m-%d")[0] - dia = time.strptime(form['date_to'],"%Y-%m-%d")[2] - - if form['inf_type']=='edogp': - return 'DESDE: '+self.formatLang(form['date_from'], date=True)+' HASTA: '+self.formatLang(form['date_to'], date=True) - else: - return 'AL '+str(dia) + ' DE ' + mes.upper() + ' DE ' + str(ano) + if form['filter'] in ['bydate', 'all']: + months=["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"] + mes = months[time.strptime(form['date_to'],"%Y-%m-%d")[1]-1] + ano = time.strptime(form['date_to'],"%Y-%m-%d")[0] + dia = time.strptime(form['date_to'],"%Y-%m-%d")[2] + return 'Período del '+self.formatLang(form['date_from'], date=True)+' al '+self.formatLang(form['date_to'], date=True) + elif form['filter'] in ['byperiod', 'all']: + aux=[] + period_obj = self.pool.get('account.period') + + for period in period_obj.browse(self.cr, self.uid, form['periods']): + aux.append(period.date_start) + aux.append(period.date_stop) + sorted(aux) + return 'Período del '+self.formatLang(aux[0], date=True)+' al '+self.formatLang(aux[-1], date=True) def get_informe_text(self, form): """ @@ -216,7 +220,6 @@ class account_balance(report_sxw.rml_parse): val = account_obj.browse(self.cr, self.uid, [aa_id[0] for aa_id in account_ids], ctx) c = 0 for aa_id in account_ids: - print '%s %s \n'%(val[c].name,val[c].balance) new_acc = { 'id' :val[c].id, 'type' :val[c].type, @@ -294,7 +297,6 @@ class account_balance(report_sxw.rml_parse): if form['tot_check'] and res['type'] == 'view' and res['level'] == 1 and (res['id'] not in tot): tot[res['id']] = True tot_eje += res['balance'] - print 'tot_eje',tot_eje if form['tot_check']: str_label = form['lab_str'] res2 = { diff --git a/account_financial_report/report/account_balance_2_cols.py b/account_financial_report/report/account_balance_2_cols.py index 5279c9a9..6783b5e6 100644 --- a/account_financial_report/report/account_balance_2_cols.py +++ b/account_financial_report/report/account_balance_2_cols.py @@ -53,8 +53,8 @@ class account_balance(report_sxw.rml_parse): 'lines': self.lines, 'get_fiscalyear_text': self.get_fiscalyear_text, 'get_periods_and_date_text': self.get_periods_and_date_text, - 'get_inf_text': self.get_informe_text, - 'get_month':self._get_month, + 'get_informe_text': self.get_informe_text, + 'get_month':self.get_month, }) self.context = context @@ -78,27 +78,30 @@ class account_balance(report_sxw.rml_parse): """ inf_type = { 'bgen' : ' Balance General', - 'bcom' : ' Balance de Comprobacion', - 'edogp': 'Estado de Ganancias y Perdidas', - 'bdl': 'Libro Diario Legal', + 'bcom' : ' Balance de Comprobacion', + 'edogp': 'Estado de Ganancias y Perdidas' } return inf_type[form['inf_type']] - def _get_month(self, form): + def get_month(self, form): ''' return day, year and month ''' - - months=["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"] - - mes = months[time.strptime(form['date_to'],"%Y-%m-%d")[1]-1] - ano = time.strptime(form['date_to'],"%Y-%m-%d")[0] - dia = time.strptime(form['date_to'],"%Y-%m-%d")[2] - - if form['inf_type']=='edogp': - return 'DESDE: '+self.formatLang(form['date_from'], date=True)+' HASTA: '+self.formatLang(form['date_to'], date=True) - else: - return 'AL '+str(dia) + ' DE ' + mes.upper() + ' DE ' + str(ano) + if form['filter'] in ['bydate', 'all']: + months=["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"] + mes = months[time.strptime(form['date_to'],"%Y-%m-%d")[1]-1] + ano = time.strptime(form['date_to'],"%Y-%m-%d")[0] + dia = time.strptime(form['date_to'],"%Y-%m-%d")[2] + return 'Período del '+self.formatLang(form['date_from'], date=True)+' al '+self.formatLang(form['date_to'], date=True) + elif form['filter'] in ['byperiod', 'all']: + aux=[] + period_obj = self.pool.get('account.period') + + for period in period_obj.browse(self.cr, self.uid, form['periods']): + aux.append(period.date_start) + aux.append(period.date_stop) + sorted(aux) + return 'Período del '+self.formatLang(aux[0], date=True)+' al '+self.formatLang(aux[-1], date=True) def get_periods_and_date_text(self, form): """ @@ -115,7 +118,6 @@ class account_balance(report_sxw.rml_parse): dates_str = None if form['filter'] in ['bydate', 'all']: dates_str = self.formatLang(form['date_from'], date=True) + ' - ' + self.formatLang(form['date_to'], date=True) + ' ' - return {'periods':periods_str, 'date':dates_str} @@ -125,14 +127,17 @@ class account_balance(report_sxw.rml_parse): (account info plus debit/credit/balance in the selected period and the full year) """ + tot_bin = 0.0 tot_deb = 0.0 tot_crd = 0.0 + tot_eje = 0.0 if not ids: ids = self.ids if not ids: return [] if not done: done = {} + if form.has_key('account_list') and form['account_list']: account_ids = form['account_list'] del form['account_list'] @@ -143,7 +148,6 @@ class account_balance(report_sxw.rml_parse): period_obj = self.pool.get('account.period') fiscalyear_obj = self.pool.get('account.fiscalyear') - # Get the fiscal year fiscalyear = None if form.get('fiscalyear'): fiscalyear = fiscalyear_obj.browse(self.cr, self.uid, form['fiscalyear']) @@ -153,6 +157,7 @@ class account_balance(report_sxw.rml_parse): # # Get the accounts # + def _get_children_and_consol(cr, uid, ids, level, context={}): aa_obj = self.pool.get('account.account') ids2=[] @@ -173,38 +178,42 @@ class account_balance(report_sxw.rml_parse): child_ids = _get_children_and_consol(self.cr, self.uid, account_ids, form['display_account_level'] and form['display_account_level'] or 100,self.context) if child_ids: account_ids = child_ids + + account_obj = self.pool.get('account.account') + period_obj = self.pool.get('account.period') + fiscalyear_obj = self.pool.get('account.fiscalyear') - # - # Calculate the period Debit/Credit - # (from the selected period or all the non special periods in the fy) - # + ############################################################################# + # Calculate the period Debit/Credit # + # (from the selected period or all the non special periods in the fy) # + ############################################################################# ctx = self.context.copy() ctx['filter'] = form.get('filter','all') ctx['fiscalyear'] = fiscalyear.id - ctx['periods'] = form.get('periods') + ctx['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('special','=',False)]) if form['filter'] in ['byperiod', 'all']: - date_start = min([period.date_start for period in period_obj.browse(self.cr, self.uid, ctx['periods'])]) - ctx['periods'] = ctx['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('date_stop','<=',date_start)]) + ctx['periods'] = period_obj.search(self.cr, self.uid, [('id','in',form['periods'] or ctx['periods']),('special','=',False)]) if form['filter'] in ['bydate', 'all']: ctx['date_from'] = form['date_from'] ctx['date_to'] = form['date_to'] accounts=[] + val = account_obj.browse(self.cr, self.uid, [aa_id[0] for aa_id in account_ids], ctx) c = 0 for aa_id in account_ids: new_acc = { - 'id' :val[c].id, - 'type' :val[c].type, - 'code' :val[c].code, - 'name' :val[c].name, - 'debit' :val[c].debit, - 'credit' :val[c].credit, - 'parent_id' :val[c].parent_id and val[c].parent_id.id, - 'level' :val[c].level, - 'label' :aa_id[1], - 'total' :aa_id[2], + 'id' :val[c].id, + 'type' :val[c].type, + 'code' :val[c].code, + 'name' :val[c].name, + 'debit' :val[c].debit, + 'credit' :val[c].credit, + 'parent_id' :val[c].parent_id and val[c].parent_id.id, + 'level' :val[c].level, + 'label' :aa_id[1], + 'total' :aa_id[2], } c += 1 accounts.append(new_acc) @@ -214,11 +223,38 @@ class account_balance(report_sxw.rml_parse): fiscalyear_obj.search(self.cr, self.uid, [('date_stop','<',fiscalyear.date_start)],order='date_stop')[-1] or [] ctx['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',ctx['fiscalyear']),('date_stop','<',fiscalyear.date_start)]) + ############################################################################# + # Calculate the period initial Balance # + # (fy balance minus the balance from the start of the selected period # + # to the end of the year) # + ############################################################################# + + ctx = self.context.copy() + ctx['filter'] = form.get('filter','all') + ctx['fiscalyear'] = fiscalyear.id + + if form['filter'] in ['byperiod', 'all']: + ctx['periods'] = form['periods'] + date_start = min([period.date_start for period in period_obj.browse(self.cr, self.uid, ctx['periods'])]) + ctx['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('date_stop','<=',date_start)]) + if not ctx['periods']: + missing_period() + elif form['filter'] in ['bydate']: + ctx['date_from'] = fiscalyear.date_start + ctx['date_to'] = form['date_from'] + ctx['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('date_stop','<=',ctx['date_to'])]) + elif form['filter'] == 'none': + ctx['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('special','=',True)]) + date_start = min([period.date_start for period in period_obj.browse(self.cr, self.uid, ctx['periods'])]) + ctx['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('date_start','<=',date_start),('special','=',True)]) + + period_balanceinit = {} + for acc in account_obj.browse(self.cr, self.uid, [x[0] for x in account_ids], ctx): + period_balanceinit[acc['id']] = acc.balance # # Generate the report lines (checking each account) # - tot = {} for account in accounts: account_id = account['id'] @@ -233,26 +269,31 @@ class account_balance(report_sxw.rml_parse): # # Check if we need to include this level # - if not form['display_account_level'] or account['level'] <= form['display_account_level']: - # # Copy the account values # - res = { 'id' : account_id, 'type' : account['type'], 'code': account['code'], 'name': (account['total'] and not account['label']) and 'TOTAL %s'%(account['name'].upper()) or account['name'], 'level': account['level'], + 'balanceinit': period_balanceinit[account_id], 'debit': account['debit'], 'credit': account['credit'], + 'balance': period_balanceinit[account_id]+account['debit']-account['credit'], 'parent_id': account['parent_id'], 'bal_type': '', 'label': account['label'], 'total': account['total'], } + # + # Round the values to zero if needed (-0.000001 ~= 0) + # + + if abs(res['balance']) < 0.5 * 10**-4: + res['balance'] = 0.0 # # Check whether we must include this line in the report or not @@ -260,30 +301,31 @@ class account_balance(report_sxw.rml_parse): if form['display_account'] == 'bal_mouvement' and account['parent_id']: # Include accounts with movements - if abs(res['credit']-res['debit']) >= 0.5 * 10**-int(2) \ - or abs(res['credit']) >= 0.5 * 10**-int(2) \ - or abs(res['debit']) >= 0.5 * 10**-int(2): + if abs(res['balance']) >= 0.5 * 10**-int(2): result_acc.append(res) - elif form['display_account'] == 'bal_solde' and account['parent_id']: - # Include accounts with balance - if abs(res['credit']-res['debit']) >= 0.5 * 10**-int(2): - result_acc.append(res) - else: - # Include all account + elif form['display_account'] == 'bal_solde' and account['parent_id']: + # Include accounts with balance + if abs(res['balance']) >= 0.5 * 10**-4: result_acc.append(res) - + else: + # Include all accounts + result_acc.append(res) if form['tot_check'] and res['type'] == 'view' and res['level'] == 1 and (res['id'] not in tot): tot[res['id']] = True + tot_bin += res['balanceinit'] tot_deb += res['debit'] tot_crd += res['credit'] + tot_eje += res['balance'] if form['tot_check']: str_label = form['lab_str'] res2 = { 'type' : 'view', 'name': 'TOTAL %s'%(str_label), + 'balanceinit': tot_bin, 'debit': tot_deb, 'credit': tot_crd, + 'balance': tot_eje, 'label': False, 'total': True, } diff --git a/account_financial_report/report/account_balance_4_cols.py b/account_financial_report/report/account_balance_4_cols.py index 8075c7aa..f33f3e23 100644 --- a/account_financial_report/report/account_balance_4_cols.py +++ b/account_financial_report/report/account_balance_4_cols.py @@ -53,8 +53,8 @@ class account_balance(report_sxw.rml_parse): 'lines': self.lines, 'get_fiscalyear_text': self.get_fiscalyear_text, 'get_periods_and_date_text': self.get_periods_and_date_text, - 'get_inf_text': self.get_informe_text, - 'get_month':self._get_month, + 'get_informe_text': self.get_informe_text, + 'get_month':self.get_month, }) self.context = context @@ -78,27 +78,30 @@ class account_balance(report_sxw.rml_parse): """ inf_type = { 'bgen' : ' Balance General', - 'bcom' : ' Balance de Comprobacion', - 'edogp': 'Estado de Ganancias y Perdidas', - 'bml': 'Libro Mayor Legal', + 'bcom' : ' Balance de Comprobacion', + 'edogp': 'Estado de Ganancias y Perdidas' } return inf_type[form['inf_type']] - def _get_month(self, form): + def get_month(self, form): ''' return day, year and month ''' - - months=["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"] - - mes = months[time.strptime(form['date_to'],"%Y-%m-%d")[1]-1] - ano = time.strptime(form['date_to'],"%Y-%m-%d")[0] - dia = time.strptime(form['date_to'],"%Y-%m-%d")[2] - - if form['inf_type']=='edogp': - return 'DESDE: '+self.formatLang(form['date_from'], date=True)+' HASTA: '+self.formatLang(form['date_to'], date=True) - else: - return 'AL '+str(dia) + ' DE ' + mes.upper() + ' DE ' + str(ano) + if form['filter'] in ['bydate', 'all']: + months=["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"] + mes = months[time.strptime(form['date_to'],"%Y-%m-%d")[1]-1] + ano = time.strptime(form['date_to'],"%Y-%m-%d")[0] + dia = time.strptime(form['date_to'],"%Y-%m-%d")[2] + return 'Período del '+self.formatLang(form['date_from'], date=True)+' al '+self.formatLang(form['date_to'], date=True) + elif form['filter'] in ['byperiod', 'all']: + aux=[] + period_obj = self.pool.get('account.period') + + for period in period_obj.browse(self.cr, self.uid, form['periods']): + aux.append(period.date_start) + aux.append(period.date_stop) + sorted(aux) + return 'Período del '+self.formatLang(aux[0], date=True)+' al '+self.formatLang(aux[-1], date=True) def get_periods_and_date_text(self, form): """ diff --git a/account_financial_report/report/balance_full.rml b/account_financial_report/report/balance_full.rml index 6c9127d4..d75a846e 100644 --- a/account_financial_report/report/balance_full.rml +++ b/account_financial_report/report/balance_full.rml @@ -5,37 +5,26 @@ - - - - [[ company.name and company.name or 'NOMBRE DE COMPANIA NO DISPONIBLE' ]] - - - - [[ (company.partner_id.vat and ('RIF: %s-%s-%s'%(company.partner_id.vat[2:3],company.partner_id.vat[3:11],company.partner_id.vat[11:12])) or removeParentNode('para')) ]] + + [[ (company.name and company.name or 'NOMBRE DE COMPANIA NO DISPONIBLE')]] + [[ company.partner_id.vat and ('- %s-%s-%s'%(company.partner_id.vat[2:3],company.partner_id.vat[3:11],company.partner_id.vat[11:12])) or '' ]] + - [[ get_inf_text(data['form']) ]] + [[ get_informe_text(data['form']) ]][[data['form'] and (' (Expresado en %s)'%( company.currency_id.name)) or '']] [[data['form'] and get_month(data['form']) or '']] - - - [[data['form'] and ('(Expresado en %s)'%(company.currency_id.symbol)) or '']] - - [[ get_inf_text(data['form']) ]] / Pág.: - + [[ get_informe_text(data['form']) ]] / Pág.: - diff --git a/account_financial_report/report/balance_full_2_cols.rml b/account_financial_report/report/balance_full_2_cols.rml index 18889746..1b65f18a 100644 --- a/account_financial_report/report/balance_full_2_cols.rml +++ b/account_financial_report/report/balance_full_2_cols.rml @@ -5,37 +5,26 @@ - - - - [[ company.name and company.name or 'NOMBRE DE COMPANIA NO DISPONIBLE' ]] - - - - [[ (company.partner_id.vat and ('RIF: %s-%s-%s'%(company.partner_id.vat[2:3],company.partner_id.vat[3:11],company.partner_id.vat[11:12])) or removeParentNode('para')) ]] + + [[ (company.name and company.name or 'NOMBRE DE COMPANIA NO DISPONIBLE')]] + [[ company.partner_id.vat and ('- %s-%s-%s'%(company.partner_id.vat[2:3],company.partner_id.vat[3:11],company.partner_id.vat[11:12])) or '' ]] + - [[ get_inf_text(data['form']) ]] + [[ get_informe_text(data['form']) ]][[data['form'] and (' (Expresado en %s)'%( company.currency_id.name)) or '']] [[data['form'] and get_month(data['form']) or '']] - - - [[data['form'] and ('(Expresado en %s)'%(company.currency_id.symbol)) or '']] - - [[ get_inf_text(data['form']) ]] / Pág.: - + [[ get_informe_text(data['form']) ]] / Pág.: - @@ -43,7 +32,7 @@ - + @@ -75,32 +64,20 @@ alignment="RIGHT" spaceBefore="0.0" spaceAfter="0.0"/> - - + + - [[setLang(user.context_lang)]] - + - Código + Código @@ -119,7 +96,6 @@ [[ a['type']<>'view' and setTag('para','para',{'fontName':"Courier"}) or removeParentNode('font') ]] [[a['label']==True and a['code'] or '' ]] - diff --git a/account_financial_report/report/balance_full_4_cols.rml b/account_financial_report/report/balance_full_4_cols.rml index ba2007c9..3a590300 100644 --- a/account_financial_report/report/balance_full_4_cols.rml +++ b/account_financial_report/report/balance_full_4_cols.rml @@ -2,7 +2,7 @@