Browse Source

[MERGE] from lp:~vauxoo/account-financial-report/7.0-mig_account_financial_report

pull/7/merge
Luis Escobar 12 years ago
parent
commit
7f37153f0f
  1. 44
      account_financial_report/__openerp__.py
  2. 122
      account_financial_report/model/account_financial_report.py
  3. 23
      account_financial_report/model/res_company.py
  4. 573
      account_financial_report/report/parser.py
  5. 23
      account_financial_report/view/account_view.xml

44
account_financial_report/__openerp__.py

@ -1,9 +1,8 @@
# -*- encoding: utf-8 -*- # -*- encoding: utf-8 -*-
########################################################################### ###########################################################################
# Module Writen to OpenERP, Open Source Management Solution
# Copyright (C) OpenERP Venezuela (<http://openerp.com.ve>). # Copyright (C) OpenERP Venezuela (<http://openerp.com.ve>).
# All Rights Reserved # All Rights Reserved
###############Credits######################################################
# Credits######################################################
# Coded by: Humberto Arocha humberto@openerp.com.ve # Coded by: Humberto Arocha humberto@openerp.com.ve
# Angelica Barrios angelicaisabelb@gmail.com # Angelica Barrios angelicaisabelb@gmail.com
# Jordi Esteve <jesteve@zikzakmedia.com> # Jordi Esteve <jesteve@zikzakmedia.com>
@ -25,28 +24,39 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
############################################################################## ##############################################################################
{ {
"name" : "Common financial reports",
"version" : "2.0",
"author" : "Vauxoo",
"website" : "http://www.vauxoo.com",
"depends" : ["base","account"],
"category" : "Localisation/Accounting",
"name": "Common financial reports",
"version": "2.0",
"author": "Vauxoo",
"website": "http://www.vauxoo.com",
"depends": ["base",
"account"
],
"category": "Accounting",
"description": """ "description": """
This modules is a multiporpuse report generator.
Multiporpuse Accounting report generator.
=========================================
From the wizard you will be asked to provide information needed to create your report.
From the wizard you will be asked to provide information needed to create your
report.
Not only you can set the option within the wizard you can create your own Customized Account Financial Reports, in here, you will be able to create Templates for generating Two types of Reports: Balance Sheets and Income Statements, incluiding Analytic Ledgers. Besides, you can select within a set of choices to get better detailed report, be it that you ask it by one or several periods, by months (12 Months + YTD), or by quarters (4QRT's + YTD). Even you can get your reports in currencies other than the one set on your company.
Not only you can set the option within the wizard you can create your own
Customized Account Financial Reports, in here, you will be able to create
Templates for generating Two types of Reports: Balance Sheets and Income
Statements, incluiding Analytic Ledgers. Besides, you can select within a set
of choices to get better detailed report, be it that you ask it by one or
several periods, by months (12 Months + YTD), or by quarters (4QRT's + YTD).
Even you can get your reports in currencies other than the one set on your
company.
In the [ Account's Sign on Reports ] Section in the Company will be able to set the sign conventions for the Accounts, so that you will be able to see in positives Values in your reports for those accounts with Accreditable nature where appropriate""",
"init_xml" : [],
"demo_xml" : [],
"update_xml" : [
In the [ Account's Sign on Reports ] Section in the Company will be able to
set the sign conventions for the Accounts, so that you will be able to see in
positives Values in your reports for those accounts with Accreditable nature
where appropriate""",
"data": [
"security/security.xml", "security/security.xml",
"security/ir.model.access.csv", "security/ir.model.access.csv",
"view/report.xml",
"view/report.xml",
"view/wizard.xml", "view/wizard.xml",
# "view/account_view.xml",
"view/company_view.xml", "view/company_view.xml",
"view/account_financial_report_view.xml", "view/account_financial_report_view.xml",
], ],

122
account_financial_report/model/account_financial_report.py

@ -3,7 +3,7 @@
# Module Writen to OpenERP, Open Source Management Solution # Module Writen to OpenERP, Open Source Management Solution
# Copyright (C) OpenERP Venezuela (<http://openerp.com.ve>). # Copyright (C) OpenERP Venezuela (<http://openerp.com.ve>).
# All Rights Reserved # All Rights Reserved
###############Credits######################################################
# Credits######################################################
# Coded by: Humberto Arocha humberto@openerp.com.ve # Coded by: Humberto Arocha humberto@openerp.com.ve
# Angelica Barrios angelicaisabelb@gmail.com # Angelica Barrios angelicaisabelb@gmail.com
# Jordi Esteve <jesteve@zikzakmedia.com> # Jordi Esteve <jesteve@zikzakmedia.com>
@ -26,111 +26,117 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
############################################################################## ##############################################################################
from osv import osv,fields
from osv import osv, fields
import pooler import pooler
import time import time
from tools.translate import _ from tools.translate import _
class account_financial_report(osv.osv): class account_financial_report(osv.osv):
_name = "afr" _name = "afr"
_columns = { _columns = {
'name': fields.char('Name', size= 128, required=True),
'company_id': fields.many2one('res.company','Company',required=True),
'name': fields.char('Name', size=128, required=True),
'company_id': fields.many2one('res.company', 'Company', required=True),
'currency_id': fields.many2one('res.currency', 'Currency', help="Currency at which this report will be expressed. If not selected will be used the one set in the company"), 'currency_id': fields.many2one('res.currency', 'Currency', help="Currency at which this report will be expressed. If not selected will be used the one set in the company"),
'inf_type': fields.selection([('BS','Balance Sheet'),('IS','Income Statement')],'Type',required=True),
'columns': fields.selection([('one','End. Balance'),('two','Debit | Credit'), ('four','Initial | Debit | Credit | YTD'), ('five','Initial | Debit | Credit | Period | YTD'),('qtr',"4 QTR's | YTD"), ('thirteen','12 Months | YTD')],'Columns',required=True),
'display_account': fields.selection([('all','All Accounts'),('bal', 'With Balance'),('mov','With movements'),('bal_mov','With Balance / Movements')],'Display accounts'),
'display_account_level': fields.integer('Up to level',help='Display accounts up to this level (0 to show all)'),
'account_ids': fields.many2many ('account.account','afr_account_rel','afr_id','account_id','Root accounts',required=True),
'fiscalyear_id': fields.many2one('account.fiscalyear','Fiscal year',help='Fiscal Year for this report',required=True),
'period_ids': fields.many2many('account.period','afr_period_rel','afr_id','period_id','Periods',help='All periods in the fiscal year if empty'),
'inf_type': fields.selection([('BS', 'Balance Sheet'), ('IS', 'Income Statement')], 'Type', required=True),
'columns': fields.selection([('one', 'End. Balance'), ('two', 'Debit | Credit'), ('four', 'Initial | Debit | Credit | YTD'), ('five', 'Initial | Debit | Credit | Period | YTD'), ('qtr', "4 QTR's | YTD"), ('thirteen', '12 Months | YTD')], 'Columns', required=True),
'display_account': fields.selection([('all', 'All Accounts'), ('bal', 'With Balance'), ('mov', 'With movements'), ('bal_mov', 'With Balance / Movements')], 'Display accounts'),
'display_account_level': fields.integer('Up to level', help='Display accounts up to this level (0 to show all)'),
'account_ids': fields.many2many('account.account', 'afr_account_rel', 'afr_id', 'account_id', 'Root accounts', required=True),
'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscal year', help='Fiscal Year for this report', required=True),
'period_ids': fields.many2many('account.period', 'afr_period_rel', 'afr_id', 'period_id', 'Periods', help='All periods in the fiscal year if empty'),
'analytic_ledger': fields.boolean('Analytic Ledger', help="Allows to Generate an Analytic Ledger for accounts with moves. Available when Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"), 'analytic_ledger': fields.boolean('Analytic Ledger', help="Allows to Generate an Analytic Ledger for accounts with moves. Available when Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"),
'tot_check': fields.boolean('Summarize?', help='Checking will add a new line at the end of the Report which will Summarize Columns in Report'), 'tot_check': fields.boolean('Summarize?', help='Checking will add a new line at the end of the Report which will Summarize Columns in Report'),
'lab_str': fields.char('Description', help='Description for the Summary', size= 128),
'lab_str': fields.char('Description', help='Description for the Summary', size=128),
#~ Deprecated fields #~ Deprecated fields
'filter': 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'),
'date_to': fields.date('End date'), 'date_to': fields.date('End date'),
'date_from': fields.date('Start date'), 'date_from': fields.date('Start date'),
} }
_defaults = { _defaults = {
'display_account_level': lambda *a: 0, 'display_account_level': lambda *a: 0,
'inf_type': lambda *a:'BS',
'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.invoice', context=c),
'inf_type': lambda *a: 'BS',
'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.invoice', context=c),
'fiscalyear_id': lambda self, cr, uid, c: self.pool.get('account.fiscalyear').find(cr, uid), 'fiscalyear_id': lambda self, cr, uid, c: self.pool.get('account.fiscalyear').find(cr, uid),
'display_account': lambda *a:'bal_mov',
'columns': lambda *a:'five',
'display_account': lambda *a: 'bal_mov',
'columns': lambda *a: 'five',
'date_from': lambda *a: time.strftime('%Y-%m-%d'), 'date_from': lambda *a: time.strftime('%Y-%m-%d'),
'date_to': lambda *a: time.strftime('%Y-%m-%d'), 'date_to': lambda *a: time.strftime('%Y-%m-%d'),
'filter': lambda *a:'byperiod',
'filter': lambda *a: 'byperiod',
} }
def copy(self, cr, uid, id, defaults, context=None): def copy(self, cr, uid, id, defaults, context=None):
if context is None: if context is None:
context = {} context = {}
previous_name = self.browse(cr, uid, id, context=context).name previous_name = self.browse(cr, uid, id, context=context).name
new_name = _('Copy of %s')%previous_name
lst = self.search(cr, uid, [('name','like',new_name)], context=context)
new_name = _('Copy of %s') % previous_name
lst = self.search(cr, uid, [(
'name', 'like', new_name)], context=context)
if lst: if lst:
new_name = '%s (%s)' % (new_name, len(lst)+1) new_name = '%s (%s)' % (new_name, len(lst)+1)
defaults['name'] = new_name defaults['name'] = new_name
return super(account_financial_report,self).copy(cr, uid, id, defaults, context=context)
return super(account_financial_report, self).copy(cr, uid, id, defaults, context=context)
def onchange_inf_type(self,cr,uid,ids,inf_type,context=None):
def onchange_inf_type(self, cr, uid, ids, inf_type, context=None):
if context is None: if context is None:
context = {} context = {}
res = {'value':{}}
res = {'value': {}}
if inf_type != 'BS': if inf_type != 'BS':
res['value'].update({'analytic_ledger':False})
res['value'].update({'analytic_ledger': False})
return res return res
def onchange_columns(self,cr,uid,ids,columns,fiscalyear_id,period_ids,context=None):
def onchange_columns(self, cr, uid, ids, columns, fiscalyear_id, period_ids, context=None):
if context is None: if context is None:
context = {} context = {}
res = {'value':{}}
res = {'value': {}}
if columns != 'four': if columns != 'four':
res['value'].update({'analytic_ledger':False})
res['value'].update({'analytic_ledger': False})
if columns in ('qtr', 'thirteen'): if columns in ('qtr', 'thirteen'):
p_obj = self.pool.get("account.period") p_obj = self.pool.get("account.period")
period_ids = p_obj.search(cr,uid,[('fiscalyear_id','=',fiscalyear_id),('special','=',False)],context=context)
res['value'].update({'period_ids':period_ids})
period_ids = p_obj.search(cr, uid, [('fiscalyear_id', '=', fiscalyear_id), (
'special', '=', False)], context=context)
res['value'].update({'period_ids': period_ids})
else: else:
res['value'].update({'period_ids':[]})
res['value'].update({'period_ids': []})
return res return res
def onchange_analytic_ledger(self,cr,uid,ids,company_id,analytic_ledger,context=None):
def onchange_analytic_ledger(self, cr, uid, ids, company_id, analytic_ledger, context=None):
if context is None: if context is None:
context = {} context = {}
context['company_id']=company_id
res = {'value':{}}
cur_id = self.pool.get('res.company').browse(cr,uid,company_id,context=context).currency_id.id
res['value'].update({'currency_id':cur_id})
context['company_id'] = company_id
res = {'value': {}}
cur_id = self.pool.get('res.company').browse(
cr, uid, company_id, context=context).currency_id.id
res['value'].update({'currency_id': cur_id})
return res return res
def onchange_company_id(self,cr,uid,ids,company_id,context=None):
def onchange_company_id(self, cr, uid, ids, company_id, context=None):
if context is None: if context is None:
context = {} context = {}
context['company_id']=company_id
res = {'value':{}}
context['company_id'] = company_id
res = {'value': {}}
if not company_id: if not company_id:
return res return res
cur_id = self.pool.get('res.company').browse(cr,uid,company_id,context=context).currency_id.id
fy_id = self.pool.get('account.fiscalyear').find(cr, uid,context=context)
res['value'].update({'fiscalyear_id':fy_id})
res['value'].update({'currency_id':cur_id})
res['value'].update({'account_ids':[]})
res['value'].update({'period_ids':[]})
cur_id = self.pool.get('res.company').browse(
cr, uid, company_id, context=context).currency_id.id
fy_id = self.pool.get('account.fiscalyear').find(
cr, uid, context=context)
res['value'].update({'fiscalyear_id': fy_id})
res['value'].update({'currency_id': cur_id})
res['value'].update({'account_ids': []})
res['value'].update({'period_ids': []})
return res return res

23
account_financial_report/model/res_company.py

@ -4,8 +4,8 @@
# Module Writen to OpenERP, Open Source Management Solution # Module Writen to OpenERP, Open Source Management Solution
# Copyright (C) OpenERP Venezuela (<http://openerp.com.ve>). # Copyright (C) OpenERP Venezuela (<http://openerp.com.ve>).
# All Rights Reserved # All Rights Reserved
###############Credits######################################################
# Coded by: Humberto Arocha <hbto@vauxoo.com>
# Credits######################################################
# Coded by: Humberto Arocha <hbto@vauxoo.com>
# Planified by: Rafael Silva <rsilvam@vauxoo.com> # Planified by: Rafael Silva <rsilvam@vauxoo.com>
# Audited by: Nhomar Hernandez <nhomar@vauxoo.com> # Audited by: Nhomar Hernandez <nhomar@vauxoo.com>
############################################################################# #############################################################################
@ -21,22 +21,23 @@
# #
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
################################################################################
##########################################################################
from osv import osv from osv import osv
from osv import fields from osv import fields
from tools.translate import _ from tools.translate import _
class res_company(osv.osv): class res_company(osv.osv):
_inherit = 'res.company' _inherit = 'res.company'
_columns = { _columns = {
'credit_account_ids':fields.many2many('account.account',
'credit_account_company_rel',
'company_id', 'account_id',
'Creditable Accounts'),
'debit_account_ids':fields.many2many('account.account',
'debit_account_company_rel',
'company_id', 'account_id',
'Debitable Accounts'),
'credit_account_ids': fields.many2many('account.account',
'credit_account_company_rel',
'company_id', 'account_id',
'Creditable Accounts'),
'debit_account_ids': fields.many2many('account.account',
'debit_account_company_rel',
'company_id', 'account_id',
'Debitable Accounts'),
} }
res_company() res_company()

573
account_financial_report/report/parser.py

@ -3,7 +3,7 @@
# Module Writen to OpenERP, Open Source Management Solution # Module Writen to OpenERP, Open Source Management Solution
# Copyright (C) OpenERP Venezuela (<http://openerp.com.ve>). # Copyright (C) OpenERP Venezuela (<http://openerp.com.ve>).
# All Rights Reserved # All Rights Reserved
###############Credits######################################################
# Credits######################################################
# Coded by: Humberto Arocha humberto@openerp.com.ve # Coded by: Humberto Arocha humberto@openerp.com.ve
# Angelica Barrios angelicaisabelb@gmail.com # Angelica Barrios angelicaisabelb@gmail.com
# Jordi Esteve <jesteve@zikzakmedia.com> # Jordi Esteve <jesteve@zikzakmedia.com>
@ -35,6 +35,8 @@ from report import report_sxw
from tools import config from tools import config
from tools.translate import _ from tools.translate import _
from osv import osv from osv import osv
class account_balance(report_sxw.rml_parse): class account_balance(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context): def __init__(self, cr, uid, name, context):
@ -53,12 +55,11 @@ class account_balance(report_sxw.rml_parse):
'get_fiscalyear_text': self.get_fiscalyear_text, 'get_fiscalyear_text': self.get_fiscalyear_text,
'get_periods_and_date_text': self.get_periods_and_date_text, 'get_periods_and_date_text': self.get_periods_and_date_text,
'get_informe_text': self.get_informe_text, 'get_informe_text': self.get_informe_text,
'get_month':self.get_month,
'exchange_name':self.exchange_name,
'get_month': self.get_month,
'exchange_name': self.exchange_name,
}) })
self.context = context self.context = context
def get_fiscalyear_text(self, form): def get_fiscalyear_text(self, form):
""" """
Returns the fiscal year text used on the report. Returns the fiscal year text used on the report.
@ -66,26 +67,29 @@ class account_balance(report_sxw.rml_parse):
fiscalyear_obj = self.pool.get('account.fiscalyear') fiscalyear_obj = self.pool.get('account.fiscalyear')
fiscalyear = None fiscalyear = None
if form.get('fiscalyear'): if form.get('fiscalyear'):
fiscalyear = fiscalyear_obj.browse(self.cr, self.uid, form['fiscalyear'])
fiscalyear = fiscalyear_obj.browse(
self.cr, self.uid, form['fiscalyear'])
return fiscalyear.name or fiscalyear.code return fiscalyear.name or fiscalyear.code
else: else:
fiscalyear = fiscalyear_obj.browse(self.cr, self.uid, fiscalyear_obj.find(self.cr, self.uid))
fiscalyear = fiscalyear_obj.browse(
self.cr, self.uid, fiscalyear_obj.find(self.cr, self.uid))
return "%s*" % (fiscalyear.name or fiscalyear.code) return "%s*" % (fiscalyear.name or fiscalyear.code)
def get_informe_text(self, form): def get_informe_text(self, form):
""" """
Returns the header text used on the report. Returns the header text used on the report.
""" """
afr_id = form['afr_id'] and type(form['afr_id']) in (list,tuple) and form['afr_id'][0] or form['afr_id']
afr_id = form['afr_id'] and type(form['afr_id']) in (
list, tuple) and form['afr_id'][0] or form['afr_id']
if afr_id: if afr_id:
name = self.pool.get('afr').browse(self.cr, self.uid, afr_id).name name = self.pool.get('afr').browse(self.cr, self.uid, afr_id).name
elif form['analytic_ledger'] and form['columns']=='four' and form['inf_type'] == 'BS':
elif form['analytic_ledger'] and form['columns'] == 'four' and form['inf_type'] == 'BS':
name = _('Analytic Ledger') name = _('Analytic Ledger')
elif form['inf_type'] == 'BS': elif form['inf_type'] == 'BS':
name = _('Balance Sheet') name = _('Balance Sheet')
elif form['inf_type'] == 'IS': elif form['inf_type'] == 'IS':
name = _('Income Statement') name = _('Income Statement')
return name return name
def get_month(self, form): def get_month(self, form):
@ -93,15 +97,16 @@ class account_balance(report_sxw.rml_parse):
return day, year and month return day, year and month
''' '''
if form['filter'] in ['bydate', 'all']: 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 _('From ')+self.formatLang(form['date_from'], date=True)+ _(' to ')+self.formatLang(form['date_to'], date=True)
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 _('From ')+self.formatLang(form['date_from'], date=True) + _(' to ')+self.formatLang(form['date_to'], date=True)
elif form['filter'] in ['byperiod', 'all']: elif form['filter'] in ['byperiod', 'all']:
aux=[]
aux = []
period_obj = self.pool.get('account.period') period_obj = self.pool.get('account.period')
for period in period_obj.browse(self.cr, self.uid, form['periods']): for period in period_obj.browse(self.cr, self.uid, form['periods']):
aux.append(period.date_start) aux.append(period.date_start)
aux.append(period.date_stop) aux.append(period.date_stop)
@ -114,17 +119,20 @@ class account_balance(report_sxw.rml_parse):
""" """
period_obj = self.pool.get('account.period') period_obj = self.pool.get('account.period')
periods_str = None 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)])
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['filter'] in ['byperiod', 'all']: if form['filter'] in ['byperiod', 'all']:
period_ids = form['periods'] period_ids = form['periods']
periods_str = ', '.join([period.name or period.code for period in period_obj.browse(self.cr, self.uid, period_ids)])
periods_str = ', '.join([period.name or period.code for period in period_obj.browse(
self.cr, self.uid, period_ids)])
dates_str = None dates_str = None
if form['filter'] 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}
dates_str = self.formatLang(form[
'date_from'], date=True) + ' - ' + self.formatLang(form['date_to'], date=True) + ' '
return {'periods': periods_str, 'date': dates_str}
def special_period(self, periods): def special_period(self, periods):
period_obj = self.pool.get('account.period') period_obj = self.pool.get('account.period')
@ -133,13 +141,15 @@ class account_balance(report_sxw.rml_parse):
if not period_counter: if not period_counter:
return True return True
return False return False
def exchange_name(self, form): def exchange_name(self, form):
self.from_currency_id = self.get_company_currency(form['company_id'] and type(form['company_id']) in (list,tuple) and form['company_id'][0] or form['company_id'])
self.from_currency_id = self.get_company_currency(form['company_id'] and type(form[
'company_id']) in (list, tuple) and form['company_id'][0] or form['company_id'])
if not form['currency_id']: if not form['currency_id']:
self.to_currency_id = self.from_currency_id self.to_currency_id = self.from_currency_id
else: else:
self.to_currency_id = form['currency_id'] and type(form['currency_id']) in (list, tuple) and form['currency_id'][0] or form['currency_id']
self.to_currency_id = form['currency_id'] and type(form['currency_id']) in (
list, tuple) and form['currency_id'][0] or form['currency_id']
return self.pool.get('res.currency').browse(self.cr, self.uid, self.to_currency_id).name return self.pool.get('res.currency').browse(self.cr, self.uid, self.to_currency_id).name
def exchange(self, from_amount): def exchange(self, from_amount):
@ -147,34 +157,34 @@ class account_balance(report_sxw.rml_parse):
return from_amount return from_amount
curr_obj = self.pool.get('res.currency') curr_obj = self.pool.get('res.currency')
return curr_obj.compute(self.cr, self.uid, self.from_currency_id, self.to_currency_id, from_amount) return curr_obj.compute(self.cr, self.uid, self.from_currency_id, self.to_currency_id, from_amount)
def get_company_currency(self, company_id): def get_company_currency(self, company_id):
rc_obj = self.pool.get('res.company') rc_obj = self.pool.get('res.company')
return rc_obj.browse(self.cr, self.uid, company_id).currency_id.id return rc_obj.browse(self.cr, self.uid, company_id).currency_id.id
def get_company_accounts(self, company_id, acc='credit'): def get_company_accounts(self, company_id, acc='credit'):
rc_obj = self.pool.get('res.company') rc_obj = self.pool.get('res.company')
if acc=='credit':
if acc == 'credit':
return [brw.id for brw in rc_obj.browse(self.cr, self.uid, company_id).credit_account_ids] return [brw.id for brw in rc_obj.browse(self.cr, self.uid, company_id).credit_account_ids]
else: else:
return [brw.id for brw in rc_obj.browse(self.cr, self.uid, company_id).debit_account_ids] return [brw.id for brw in rc_obj.browse(self.cr, self.uid, company_id).debit_account_ids]
def _get_analytic_ledger(self, account, ctx={}): def _get_analytic_ledger(self, account, ctx={}):
res = [] res = []
if account['type'] in ('other','liquidity','receivable','payable'):
if account['type'] in ('other', 'liquidity', 'receivable', 'payable'):
#~ TODO: CUANDO EL PERIODO ESTE VACIO LLENARLO CON LOS PERIODOS DEL EJERCICIO #~ TODO: CUANDO EL PERIODO ESTE VACIO LLENARLO CON LOS PERIODOS DEL EJERCICIO
#~ FISCAL, SIN LOS PERIODOS ESPECIALES #~ FISCAL, SIN LOS PERIODOS ESPECIALES
periods = ', '.join([str(i) for i in ctx['periods']]) periods = ', '.join([str(i) for i in ctx['periods']])
#~ periods = str(tuple(ctx['periods'])) #~ periods = str(tuple(ctx['periods']))
where = """where aml.period_id in (%s) and aa.id = %s and aml.state <> 'draft'"""%(periods,account['id'])
where = """where aml.period_id in (%s) and aa.id = %s and aml.state <> 'draft'""" % (
periods, account['id'])
sql_detalle = """select aml.id as id, aj.name as diario, aa.name as descripcion, sql_detalle = """select aml.id as id, aj.name as diario, aa.name as descripcion,
(select name from res_partner where aml.partner_id = id) as partner, (select name from res_partner where aml.partner_id = id) as partner,
aa.code as cuenta, aml.name as name, aa.code as cuenta, aml.name as name,
aml.ref as ref, aml.ref as ref,
case when aml.debit is null then 0.00 else aml.debit end as debit,
case when aml.debit is null then 0.00 else aml.debit end as debit,
case when aml.credit is null then 0.00 else aml.credit end as credit, case when aml.credit is null then 0.00 else aml.credit end as credit,
(select code from account_analytic_account where aml.analytic_account_id = id) as analitica, (select code from account_analytic_account where aml.analytic_account_id = id) as analitica,
aml.date as date, ap.name as periodo, aml.date as date, ap.name as periodo,
@ -194,10 +204,10 @@ class account_balance(report_sxw.rml_parse):
res.append({ res.append({
'id': det['id'], 'id': det['id'],
'date': det['date'], 'date': det['date'],
'journal':det['diario'],
'partner':det['partner'],
'name':det['name'],
'entry':det['asiento'],
'journal': det['diario'],
'partner': det['partner'],
'name': det['name'],
'entry': det['asiento'],
'ref': det['ref'], 'ref': det['ref'],
'debit': det['debit'], 'debit': det['debit'],
'credit': det['credit'], 'credit': det['credit'],
@ -216,105 +226,119 @@ class account_balance(report_sxw.rml_parse):
account_obj = self.pool.get('account.account') account_obj = self.pool.get('account.account')
period_obj = self.pool.get('account.period') period_obj = self.pool.get('account.period')
fiscalyear_obj = self.pool.get('account.fiscalyear') fiscalyear_obj = self.pool.get('account.fiscalyear')
def _get_children_and_consol(cr, uid, ids, level, context={},change_sign=False):
def _get_children_and_consol(cr, uid, ids, level, context={}, change_sign=False):
aa_obj = self.pool.get('account.account') aa_obj = self.pool.get('account.account')
ids2=[]
ids2 = []
for aa_brw in aa_obj.browse(cr, uid, ids, context): for aa_brw in aa_obj.browse(cr, uid, ids, context):
if aa_brw.child_id and aa_brw.level < level and aa_brw.type !='consolidation':
if aa_brw.child_id and aa_brw.level < level and aa_brw.type != 'consolidation':
if not change_sign: if not change_sign:
ids2.append([aa_brw.id,True, False,aa_brw])
ids2 += _get_children_and_consol(cr, uid, [x.id for x in aa_brw.child_id], level, context,change_sign=change_sign)
ids2.append([aa_brw.id, True, False, aa_brw])
ids2 += _get_children_and_consol(cr, uid, [
x.id for x in aa_brw.child_id], level, context, change_sign=change_sign)
if change_sign: if change_sign:
ids2.append(aa_brw.id)
ids2.append(aa_brw.id)
else: else:
ids2.append([aa_brw.id,False,True,aa_brw])
ids2.append([aa_brw.id, False, True, aa_brw])
else: else:
if change_sign: if change_sign:
ids2.append(aa_brw.id)
ids2.append(aa_brw.id)
else: else:
ids2.append([aa_brw.id,True,True,aa_brw])
ids2.append([aa_brw.id, True, True, aa_brw])
return ids2 return ids2
############################################################################# #############################################################################
# CONTEXT FOR ENDIND BALANCE # # CONTEXT FOR ENDIND BALANCE #
#############################################################################
#######################################################################
def _ctx_end(ctx): def _ctx_end(ctx):
ctx_end = ctx ctx_end = ctx
ctx_end['filter'] = form.get('filter','all')
ctx_end['filter'] = form.get('filter', 'all')
ctx_end['fiscalyear'] = fiscalyear.id ctx_end['fiscalyear'] = fiscalyear.id
#~ ctx_end['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('special','=',False)]) #~ ctx_end['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('special','=',False)])
if ctx_end['filter'] not in ['bydate','none']:
if ctx_end['filter'] not in ['bydate', 'none']:
special = self.special_period(form['periods']) special = self.special_period(form['periods'])
else: else:
special = False special = False
if form['filter'] in ['byperiod', 'all']: if form['filter'] in ['byperiod', 'all']:
if special: if special:
ctx_end['periods'] = period_obj.search(self.cr, self.uid, [('id','in',form['periods'] or ctx_end.get('periods',False))])
ctx_end['periods'] = period_obj.search(self.cr, self.uid, [(
'id', 'in', form['periods'] or ctx_end.get('periods', False))])
else: else:
ctx_end['periods'] = period_obj.search(self.cr, self.uid, [('id','in',form['periods'] or ctx_end.get('periods',False)),('special','=',False)])
if form['filter'] in ['bydate','all','none']:
ctx_end['periods'] = period_obj.search(self.cr, self.uid, [('id', 'in', form[
'periods'] or ctx_end.get('periods', False)), ('special', '=', False)])
if form['filter'] in ['bydate', 'all', 'none']:
ctx_end['date_from'] = form['date_from'] ctx_end['date_from'] = form['date_from']
ctx_end['date_to'] = form['date_to'] ctx_end['date_to'] = form['date_to']
return ctx_end.copy() return ctx_end.copy()
def missing_period(ctx_init): def missing_period(ctx_init):
ctx_init['fiscalyear'] = fiscalyear_obj.search(self.cr, self.uid, [('date_stop','<',fiscalyear.date_start)],order='date_stop') and \
fiscalyear_obj.search(self.cr, self.uid, [('date_stop','<',fiscalyear.date_start)],order='date_stop')[-1] or []
ctx_init['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',ctx_init['fiscalyear']),('date_stop','<',fiscalyear.date_start)])
ctx_init['fiscalyear'] = fiscalyear_obj.search(self.cr, self.uid, [('date_stop', '<', fiscalyear.date_start)], order='date_stop') and \
fiscalyear_obj.search(self.cr, self.uid, [(
'date_stop', '<', fiscalyear.date_start)], order='date_stop')[-1] or []
ctx_init['periods'] = period_obj.search(self.cr, self.uid, [(
'fiscalyear_id', '=', ctx_init['fiscalyear']), ('date_stop', '<', fiscalyear.date_start)])
return ctx_init return ctx_init
############################################################################# #############################################################################
# CONTEXT FOR INITIAL BALANCE # # CONTEXT FOR INITIAL BALANCE #
#############################################################################
#######################################################################
def _ctx_init(ctx): def _ctx_init(ctx):
ctx_init = self.context.copy() ctx_init = self.context.copy()
ctx_init['filter'] = form.get('filter','all')
ctx_init['filter'] = form.get('filter', 'all')
ctx_init['fiscalyear'] = fiscalyear.id ctx_init['fiscalyear'] = fiscalyear.id
if form['filter'] in ['byperiod', 'all']: if form['filter'] in ['byperiod', 'all']:
ctx_init['periods'] = form['periods'] ctx_init['periods'] = form['periods']
if not ctx_init['periods']: if not ctx_init['periods']:
ctx_init = missing_period(ctx_init.copy()) ctx_init = missing_period(ctx_init.copy())
date_start = min([period.date_start for period in period_obj.browse(self.cr, self.uid, ctx_init['periods'])])
ctx_init['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('date_stop','<=',date_start)])
date_start = min([period.date_start for period in period_obj.browse(
self.cr, self.uid, ctx_init['periods'])])
ctx_init['periods'] = period_obj.search(self.cr, self.uid, [(
'fiscalyear_id', '=', fiscalyear.id), ('date_stop', '<=', date_start)])
elif form['filter'] in ['bydate']: elif form['filter'] in ['bydate']:
ctx_init['date_from'] = fiscalyear.date_start ctx_init['date_from'] = fiscalyear.date_start
ctx_init['date_to'] = form['date_from'] ctx_init['date_to'] = form['date_from']
ctx_init['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('date_stop','<=',ctx_init['date_to'])])
ctx_init['periods'] = period_obj.search(self.cr, self.uid, [(
'fiscalyear_id', '=', fiscalyear.id), ('date_stop', '<=', ctx_init['date_to'])])
elif form['filter'] == 'none': elif form['filter'] == 'none':
ctx_init['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_init['periods'])])
ctx_init['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('date_start','<=',date_start),('special','=',True)])
ctx_init['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_init['periods'])])
ctx_init['periods'] = period_obj.search(self.cr, self.uid, [(
'fiscalyear_id', '=', fiscalyear.id), ('date_start', '<=', date_start), ('special', '=', True)])
return ctx_init.copy() return ctx_init.copy()
def z(n): def z(n):
return abs(n) < 0.005 and 0.0 or n return abs(n) < 0.005 and 0.0 or n
self.from_currency_id = self.get_company_currency(form['company_id'] and type(form['company_id']) in (list,tuple) and form['company_id'][0] or form['company_id'])
self.from_currency_id = self.get_company_currency(form['company_id'] and type(form[
'company_id']) in (list, tuple) and form['company_id'][0] or form['company_id'])
if not form['currency_id']: if not form['currency_id']:
self.to_currency_id = self.from_currency_id self.to_currency_id = self.from_currency_id
else: else:
self.to_currency_id = form['currency_id'] and type(form['currency_id']) in (list, tuple) and form['currency_id'][0] or form['currency_id']
self.to_currency_id = form['currency_id'] and type(form['currency_id']) in (
list, tuple) and form['currency_id'][0] or form['currency_id']
if form.has_key('account_list') and form['account_list']:
if 'account_list' in form and form['account_list']:
account_ids = form['account_list'] account_ids = form['account_list']
del form['account_list'] del form['account_list']
credit_account_ids = self.get_company_accounts(form['company_id'] and type(form['company_id']) in (list,tuple) and form['company_id'][0] or form['company_id'],'credit')
debit_account_ids = self.get_company_accounts(form['company_id'] and type(form['company_id']) in (list,tuple) and form['company_id'][0] or form['company_id'],'debit')
credit_account_ids = self.get_company_accounts(form['company_id'] and type(form[
'company_id']) in (list, tuple) and form['company_id'][0] or form['company_id'], 'credit')
debit_account_ids = self.get_company_accounts(form['company_id'] and type(form[
'company_id']) in (list, tuple) and form['company_id'][0] or form['company_id'], 'debit')
if form.get('fiscalyear'): if form.get('fiscalyear'):
if type(form.get('fiscalyear')) in (list,tuple):
if type(form.get('fiscalyear')) in (list, tuple):
fiscalyear = form['fiscalyear'] and form['fiscalyear'][0] fiscalyear = form['fiscalyear'] and form['fiscalyear'][0]
elif type(form.get('fiscalyear')) in (int,): elif type(form.get('fiscalyear')) in (int,):
fiscalyear = form['fiscalyear'] fiscalyear = form['fiscalyear']
@ -324,44 +348,52 @@ class account_balance(report_sxw.rml_parse):
# Get the accounts # # Get the accounts #
################################################################ ################################################################
account_ids = _get_children_and_consol(self.cr, self.uid, account_ids, form['display_account_level'] and form['display_account_level'] or 100,self.context)
credit_account_ids = _get_children_and_consol(self.cr, self.uid, credit_account_ids, 100,self.context,change_sign=True)
debit_account_ids = _get_children_and_consol(self.cr, self.uid, debit_account_ids, 100,self.context,change_sign=True)
credit_account_ids = list(set(credit_account_ids) - set(debit_account_ids))
account_ids = _get_children_and_consol(self.cr, self.uid, account_ids, form[
'display_account_level'] and form['display_account_level'] or 100, self.context)
credit_account_ids = _get_children_and_consol(
self.cr, self.uid, credit_account_ids, 100, self.context, change_sign=True)
debit_account_ids = _get_children_and_consol(
self.cr, self.uid, debit_account_ids, 100, self.context, change_sign=True)
credit_account_ids = list(set(
credit_account_ids) - set(debit_account_ids))
# #
# Generate the report lines (checking each account) # Generate the report lines (checking each account)
# #
tot_check = False tot_check = False
if not form['periods']: if not form['periods']:
form['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('special','=',False)],order='date_start asc')
form['periods'] = period_obj.search(self.cr, self.uid, [(
'fiscalyear_id', '=', fiscalyear.id), ('special', '=', False)], order='date_start asc')
if not form['periods']: if not form['periods']:
raise osv.except_osv(_('UserError'),_('The Selected Fiscal Year Does not have Regular Periods'))
raise osv.except_osv(_('UserError'), _(
'The Selected Fiscal Year Does not have Regular Periods'))
if form['columns'] == 'qtr': if form['columns'] == 'qtr':
period_ids = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('special','=',False)],order='date_start asc')
a=0
l=[]
p=[]
period_ids = period_obj.search(self.cr, self.uid, [(
'fiscalyear_id', '=', fiscalyear.id), ('special', '=', False)], order='date_start asc')
a = 0
l = []
p = []
for x in period_ids: for x in period_ids:
a+=1
if a<3:
a += 1
if a < 3:
l.append(x) l.append(x)
else: else:
l.append(x) l.append(x)
p.append(l) p.append(l)
l=[]
a=0
l = []
a = 0
#~ period_ids = p #~ period_ids = p
elif form['columns'] == 'thirteen': elif form['columns'] == 'thirteen':
period_ids = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('special','=',False)],order='date_start asc')
period_ids = period_obj.search(self.cr, self.uid, [(
'fiscalyear_id', '=', fiscalyear.id), ('special', '=', False)], order='date_start asc')
if form['columns'] == 'qtr': if form['columns'] == 'qtr':
tot_bal1 = 0.0 tot_bal1 = 0.0
@ -386,7 +418,7 @@ class account_balance(report_sxw.rml_parse):
tot_bal13 = 0.0 tot_bal13 = 0.0
else: else:
ctx_init = _ctx_init(self.context.copy()) ctx_init = _ctx_init(self.context.copy())
ctx_end = _ctx_end(self.context.copy()) ctx_end = _ctx_end(self.context.copy())
@ -395,11 +427,10 @@ class account_balance(report_sxw.rml_parse):
tot_crd = 0.0 tot_crd = 0.0
tot_ytd = 0.0 tot_ytd = 0.0
tot_eje = 0.0 tot_eje = 0.0
res = {} res = {}
result_acc = [] result_acc = []
tot = {}
tot = {}
for aa_id in account_ids: for aa_id in account_ids:
id = aa_id[0] id = aa_id[0]
@ -409,129 +440,148 @@ class account_balance(report_sxw.rml_parse):
# #
if not form['display_account_level'] or aa_id[3].level <= form['display_account_level']: if not form['display_account_level'] or aa_id[3].level <= form['display_account_level']:
res = { res = {
'id' : id,
'type' : aa_id[3].type,
'code' : aa_id[3].code,
'name' : (aa_id[2] and not aa_id[1]) and 'TOTAL %s'%(aa_id[3].name.upper()) or aa_id[3].name,
'parent_id' : aa_id[3].parent_id and aa_id[3].parent_id.id,
'level' : aa_id[3].level,
'label' : aa_id[1],
'total' : aa_id[2],
'change_sign' : credit_account_ids and (id in credit_account_ids and -1 or 1) or 1
'id': id,
'type': aa_id[3].type,
'code': aa_id[3].code,
'name': (aa_id[2] and not aa_id[1]) and 'TOTAL %s' % (aa_id[3].name.upper()) or aa_id[3].name,
'parent_id': aa_id[3].parent_id and aa_id[3].parent_id.id,
'level': aa_id[3].level,
'label': aa_id[1],
'total': aa_id[2],
'change_sign': credit_account_ids and (id in credit_account_ids and -1 or 1) or 1
} }
if form['columns'] == 'qtr': if form['columns'] == 'qtr':
pn = 1 pn = 1
for p_id in p: for p_id in p:
form['periods'] = p_id form['periods'] = p_id
ctx_init = _ctx_init(self.context.copy()) ctx_init = _ctx_init(self.context.copy())
aa_brw_init = account_obj.browse(self.cr, self.uid, id, ctx_init)
aa_brw_init = account_obj.browse(
self.cr, self.uid, id, ctx_init)
ctx_end = _ctx_end(self.context.copy()) ctx_end = _ctx_end(self.context.copy())
aa_brw_end = account_obj.browse(self.cr, self.uid, id, ctx_end)
aa_brw_end = account_obj.browse(
self.cr, self.uid, id, ctx_end)
if form['inf_type'] == 'IS': if form['inf_type'] == 'IS':
d,c,b = map(z,[aa_brw_end.debit,aa_brw_end.credit,aa_brw_end.balance])
d, c, b = map(z, [
aa_brw_end.debit, aa_brw_end.credit, aa_brw_end.balance])
res.update({ res.update({
'dbr%s'%pn: self.exchange(d),
'cdr%s'%pn: self.exchange(c),
'bal%s'%pn: self.exchange(b),
'dbr%s' % pn: self.exchange(d),
'cdr%s' % pn: self.exchange(c),
'bal%s' % pn: self.exchange(b),
}) })
else: else:
i,d,c = map(z,[aa_brw_init.balance,aa_brw_end.debit,aa_brw_end.credit])
i, d, c = map(z, [
aa_brw_init.balance, aa_brw_end.debit, aa_brw_end.credit])
b = z(i+d-c) b = z(i+d-c)
res.update({ res.update({
'dbr%s'%pn: self.exchange(d),
'cdr%s'%pn: self.exchange(c),
'bal%s'%pn: self.exchange(b),
'dbr%s' % pn: self.exchange(d),
'cdr%s' % pn: self.exchange(c),
'bal%s' % pn: self.exchange(b),
}) })
pn +=1
pn += 1
form['periods'] = period_ids form['periods'] = period_ids
ctx_init = _ctx_init(self.context.copy()) ctx_init = _ctx_init(self.context.copy())
aa_brw_init = account_obj.browse(self.cr, self.uid, id, ctx_init)
aa_brw_init = account_obj.browse(
self.cr, self.uid, id, ctx_init)
ctx_end = _ctx_end(self.context.copy()) ctx_end = _ctx_end(self.context.copy())
aa_brw_end = account_obj.browse(self.cr, self.uid, id, ctx_end)
aa_brw_end = account_obj.browse(
self.cr, self.uid, id, ctx_end)
if form['inf_type'] == 'IS': if form['inf_type'] == 'IS':
d,c,b = map(z,[aa_brw_end.debit,aa_brw_end.credit,aa_brw_end.balance])
d, c, b = map(z, [
aa_brw_end.debit, aa_brw_end.credit, aa_brw_end.balance])
res.update({ res.update({
'dbr5': self.exchange(d), 'dbr5': self.exchange(d),
'cdr5': self.exchange(c), 'cdr5': self.exchange(c),
'bal5': self.exchange(b), 'bal5': self.exchange(b),
}) })
else: else:
i,d,c = map(z,[aa_brw_init.balance,aa_brw_end.debit,aa_brw_end.credit])
i, d, c = map(z, [
aa_brw_init.balance, aa_brw_end.debit, aa_brw_end.credit])
b = z(i+d-c) b = z(i+d-c)
res.update({ res.update({
'dbr5': self.exchange(d), 'dbr5': self.exchange(d),
'cdr5': self.exchange(c), 'cdr5': self.exchange(c),
'bal5': self.exchange(b), 'bal5': self.exchange(b),
}) })
elif form['columns'] == 'thirteen': elif form['columns'] == 'thirteen':
pn = 1 pn = 1
for p_id in period_ids: for p_id in period_ids:
form['periods'] = [p_id] form['periods'] = [p_id]
ctx_init = _ctx_init(self.context.copy()) ctx_init = _ctx_init(self.context.copy())
aa_brw_init = account_obj.browse(self.cr, self.uid, id, ctx_init)
aa_brw_init = account_obj.browse(
self.cr, self.uid, id, ctx_init)
ctx_end = _ctx_end(self.context.copy()) ctx_end = _ctx_end(self.context.copy())
aa_brw_end = account_obj.browse(self.cr, self.uid, id, ctx_end)
aa_brw_end = account_obj.browse(
self.cr, self.uid, id, ctx_end)
if form['inf_type'] == 'IS': if form['inf_type'] == 'IS':
d,c,b = map(z,[aa_brw_end.debit,aa_brw_end.credit,aa_brw_end.balance])
d, c, b = map(z, [
aa_brw_end.debit, aa_brw_end.credit, aa_brw_end.balance])
res.update({ res.update({
'dbr%s'%pn: self.exchange(d),
'cdr%s'%pn: self.exchange(c),
'bal%s'%pn: self.exchange(b),
'dbr%s' % pn: self.exchange(d),
'cdr%s' % pn: self.exchange(c),
'bal%s' % pn: self.exchange(b),
}) })
else: else:
i,d,c = map(z,[aa_brw_init.balance,aa_brw_end.debit,aa_brw_end.credit])
i, d, c = map(z, [
aa_brw_init.balance, aa_brw_end.debit, aa_brw_end.credit])
b = z(i+d-c) b = z(i+d-c)
res.update({ res.update({
'dbr%s'%pn: self.exchange(d),
'cdr%s'%pn: self.exchange(c),
'bal%s'%pn: self.exchange(b),
'dbr%s' % pn: self.exchange(d),
'cdr%s' % pn: self.exchange(c),
'bal%s' % pn: self.exchange(b),
}) })
pn +=1
pn += 1
form['periods'] = period_ids form['periods'] = period_ids
ctx_init = _ctx_init(self.context.copy()) ctx_init = _ctx_init(self.context.copy())
aa_brw_init = account_obj.browse(self.cr, self.uid, id, ctx_init)
aa_brw_init = account_obj.browse(
self.cr, self.uid, id, ctx_init)
ctx_end = _ctx_end(self.context.copy()) ctx_end = _ctx_end(self.context.copy())
aa_brw_end = account_obj.browse(self.cr, self.uid, id, ctx_end)
aa_brw_end = account_obj.browse(
self.cr, self.uid, id, ctx_end)
if form['inf_type'] == 'IS': if form['inf_type'] == 'IS':
d,c,b = map(z,[aa_brw_end.debit,aa_brw_end.credit,aa_brw_end.balance])
d, c, b = map(z, [
aa_brw_end.debit, aa_brw_end.credit, aa_brw_end.balance])
res.update({ res.update({
'dbr13': self.exchange(d), 'dbr13': self.exchange(d),
'cdr13': self.exchange(c), 'cdr13': self.exchange(c),
'bal13': self.exchange(b), 'bal13': self.exchange(b),
}) })
else: else:
i,d,c = map(z,[aa_brw_init.balance,aa_brw_end.debit,aa_brw_end.credit])
i, d, c = map(z, [
aa_brw_init.balance, aa_brw_end.debit, aa_brw_end.credit])
b = z(i+d-c) b = z(i+d-c)
res.update({ res.update({
'dbr13': self.exchange(d), 'dbr13': self.exchange(d),
'cdr13': self.exchange(c), 'cdr13': self.exchange(c),
'bal13': self.exchange(b), 'bal13': self.exchange(b),
}) })
else: else:
aa_brw_init = account_obj.browse(self.cr, self.uid, id, ctx_init)
aa_brw_end = account_obj.browse(self.cr, self.uid, id, ctx_end)
aa_brw_init = account_obj.browse(
self.cr, self.uid, id, ctx_init)
aa_brw_end = account_obj.browse(
self.cr, self.uid, id, ctx_end)
i,d,c = map(z,[aa_brw_init.balance,aa_brw_end.debit,aa_brw_end.credit])
i, d, c = map(z, [
aa_brw_init.balance, aa_brw_end.debit, aa_brw_end.credit])
b = z(i+d-c) b = z(i+d-c)
res.update({ res.update({
'balanceinit': self.exchange(i), 'balanceinit': self.exchange(i),
@ -539,8 +589,8 @@ class account_balance(report_sxw.rml_parse):
'credit': self.exchange(c), 'credit': self.exchange(c),
'ytd': self.exchange(d-c), 'ytd': self.exchange(d-c),
}) })
if form['inf_type'] == 'IS' and form['columns'] == 'one':
if form['inf_type'] == 'IS' and form['columns'] == 'one':
res.update({ res.update({
'balance': self.exchange(d-c), 'balance': self.exchange(d-c),
}) })
@ -553,36 +603,42 @@ class account_balance(report_sxw.rml_parse):
# Check whether we must include this line in the report or not # Check whether we must include this line in the report or not
# #
to_include = False to_include = False
if form['columns'] in ('thirteen', 'qtr'): if form['columns'] in ('thirteen', 'qtr'):
to_test = [False] to_test = [False]
if form['display_account'] == 'mov' and aa_id[3].parent_id: if form['display_account'] == 'mov' and aa_id[3].parent_id:
# Include accounts with movements # Include accounts with movements
for x in range(pn-1): for x in range(pn-1):
to_test.append(res.get('dbr%s'%x,0.0) >= 0.005 and True or False)
to_test.append(res.get('cdr%s'%x,0.0) >= 0.005 and True or False)
to_test.append(res.get(
'dbr%s' % x, 0.0) >= 0.005 and True or False)
to_test.append(res.get(
'cdr%s' % x, 0.0) >= 0.005 and True or False)
if any(to_test): if any(to_test):
to_include = True to_include = True
elif form['display_account'] == 'bal' and aa_id[3].parent_id: elif form['display_account'] == 'bal' and aa_id[3].parent_id:
# Include accounts with balance # Include accounts with balance
for x in range(pn-1): for x in range(pn-1):
to_test.append(res.get('bal%s'%x,0.0) >= 0.005 and True or False)
to_test.append(res.get(
'bal%s' % x, 0.0) >= 0.005 and True or False)
if any(to_test): if any(to_test):
to_include = True to_include = True
elif form['display_account'] == 'bal_mov' and aa_id[3].parent_id: elif form['display_account'] == 'bal_mov' and aa_id[3].parent_id:
# Include accounts with balance or movements # Include accounts with balance or movements
for x in range(pn-1): for x in range(pn-1):
to_test.append(res.get('bal%s'%x,0.0) >= 0.005 and True or False)
to_test.append(res.get('dbr%s'%x,0.0) >= 0.005 and True or False)
to_test.append(res.get('cdr%s'%x,0.0) >= 0.005 and True or False)
to_test.append(res.get(
'bal%s' % x, 0.0) >= 0.005 and True or False)
to_test.append(res.get(
'dbr%s' % x, 0.0) >= 0.005 and True or False)
to_test.append(res.get(
'cdr%s' % x, 0.0) >= 0.005 and True or False)
if any(to_test): if any(to_test):
to_include = True to_include = True
else: else:
# Include all accounts # Include all accounts
to_include = True to_include = True
else: else:
if form['display_account'] == 'mov' and aa_id[3].parent_id: if form['display_account'] == 'mov' and aa_id[3].parent_id:
@ -600,14 +656,13 @@ class account_balance(report_sxw.rml_parse):
else: else:
# Include all accounts # Include all accounts
to_include = True to_include = True
#~ ANALYTIC LEDGER #~ ANALYTIC LEDGER
if to_include and form['analytic_ledger'] and form['columns']=='four' and form['inf_type'] == 'BS' and res['type'] in ('other','liquidity','receivable','payable'):
res['mayor'] = self._get_analytic_ledger(res,ctx=ctx_end)
if to_include and form['analytic_ledger'] and form['columns'] == 'four' and form['inf_type'] == 'BS' and res['type'] in ('other', 'liquidity', 'receivable', 'payable'):
res['mayor'] = self._get_analytic_ledger(res, ctx=ctx_end)
else: else:
res['mayor'] = [] res['mayor'] = []
if to_include: if to_include:
result_acc.append(res) result_acc.append(res)
# #
@ -618,28 +673,28 @@ class account_balance(report_sxw.rml_parse):
if form['columns'] == 'qtr': if form['columns'] == 'qtr':
tot_check = True tot_check = True
#~ tot[res['id']] = True #~ tot[res['id']] = True
tot_bal1 += res.get('bal1',0.0)
tot_bal2 += res.get('bal2',0.0)
tot_bal3 += res.get('bal3',0.0)
tot_bal4 += res.get('bal4',0.0)
tot_bal5 += res.get('bal5',0.0)
tot_bal1 += res.get('bal1', 0.0)
tot_bal2 += res.get('bal2', 0.0)
tot_bal3 += res.get('bal3', 0.0)
tot_bal4 += res.get('bal4', 0.0)
tot_bal5 += res.get('bal5', 0.0)
elif form['columns'] == 'thirteen': elif form['columns'] == 'thirteen':
tot_check = True tot_check = True
#~ tot[res['id']] = True #~ tot[res['id']] = True
tot_bal1 += res.get('bal1',0.0)
tot_bal2 += res.get('bal2',0.0)
tot_bal3 += res.get('bal3',0.0)
tot_bal4 += res.get('bal4',0.0)
tot_bal5 += res.get('bal5',0.0)
tot_bal6 += res.get('bal6',0.0)
tot_bal7 += res.get('bal7',0.0)
tot_bal8 += res.get('bal8',0.0)
tot_bal9 += res.get('bal9',0.0)
tot_bal10 += res.get('bal10',0.0)
tot_bal11 += res.get('bal11',0.0)
tot_bal12 += res.get('bal12',0.0)
tot_bal13 += res.get('bal13',0.0)
tot_bal1 += res.get('bal1', 0.0)
tot_bal2 += res.get('bal2', 0.0)
tot_bal3 += res.get('bal3', 0.0)
tot_bal4 += res.get('bal4', 0.0)
tot_bal5 += res.get('bal5', 0.0)
tot_bal6 += res.get('bal6', 0.0)
tot_bal7 += res.get('bal7', 0.0)
tot_bal8 += res.get('bal8', 0.0)
tot_bal9 += res.get('bal9', 0.0)
tot_bal10 += res.get('bal10', 0.0)
tot_bal11 += res.get('bal11', 0.0)
tot_bal12 += res.get('bal12', 0.0)
tot_bal13 += res.get('bal13', 0.0)
else: else:
tot_check = True tot_check = True
@ -653,84 +708,84 @@ class account_balance(report_sxw.rml_parse):
if tot_check: if tot_check:
str_label = form['lab_str'] str_label = form['lab_str']
res2 = { res2 = {
'type' : 'view',
'name': 'TOTAL %s'%(str_label),
'label': False,
'total': True,
'type': 'view',
'name': 'TOTAL %s' % (str_label),
'label': False,
'total': True,
} }
if form['columns'] == 'qtr': if form['columns'] == 'qtr':
res2.update(dict( res2.update(dict(
bal1 = tot_bal1,
bal2 = tot_bal2,
bal3 = tot_bal3,
bal4 = tot_bal4,
bal5 = tot_bal5,))
bal1=tot_bal1,
bal2=tot_bal2,
bal3=tot_bal3,
bal4=tot_bal4,
bal5=tot_bal5,))
elif form['columns'] == 'thirteen': elif form['columns'] == 'thirteen':
res2.update(dict( res2.update(dict(
bal1 = tot_bal1,
bal2 = tot_bal2,
bal3 = tot_bal3,
bal4 = tot_bal4,
bal5 = tot_bal5,
bal6 = tot_bal6,
bal7 = tot_bal7,
bal8 = tot_bal8,
bal9 = tot_bal9,
bal10 = tot_bal10,
bal11 = tot_bal11,
bal12 = tot_bal12,
bal13 = tot_bal13,))
bal1=tot_bal1,
bal2=tot_bal2,
bal3=tot_bal3,
bal4=tot_bal4,
bal5=tot_bal5,
bal6=tot_bal6,
bal7=tot_bal7,
bal8=tot_bal8,
bal9=tot_bal9,
bal10=tot_bal10,
bal11=tot_bal11,
bal12=tot_bal12,
bal13=tot_bal13,))
else: else:
res2.update({ res2.update({
'balanceinit': tot_bin,
'debit': tot_deb,
'credit': tot_crd,
'ytd': tot_ytd,
'balance': tot_eje,
'balanceinit': tot_bin,
'debit': tot_deb,
'credit': tot_crd,
'ytd': tot_ytd,
'balance': tot_eje,
}) })
result_acc.append(res2) result_acc.append(res2)
return result_acc return result_acc
report_sxw.report_sxw('report.afr.1cols',
'wizard.report',
report_sxw.report_sxw('report.afr.1cols',
'wizard.report',
'account_financial_report/report/balance_full.rml', 'account_financial_report/report/balance_full.rml',
parser=account_balance,
header=False)
parser=account_balance,
header=False)
report_sxw.report_sxw('report.afr.2cols',
'wizard.report',
report_sxw.report_sxw('report.afr.2cols',
'wizard.report',
'account_financial_report/report/balance_full_2_cols.rml', 'account_financial_report/report/balance_full_2_cols.rml',
parser=account_balance,
header=False)
parser=account_balance,
header=False)
report_sxw.report_sxw('report.afr.4cols',
'wizard.report',
report_sxw.report_sxw('report.afr.4cols',
'wizard.report',
'account_financial_report/report/balance_full_4_cols.rml', 'account_financial_report/report/balance_full_4_cols.rml',
parser=account_balance,
header=False)
parser=account_balance,
header=False)
report_sxw.report_sxw('report.afr.analytic.ledger',
'wizard.report',
report_sxw.report_sxw('report.afr.analytic.ledger',
'wizard.report',
'account_financial_report/report/balance_full_4_cols_analytic_ledger.rml', 'account_financial_report/report/balance_full_4_cols_analytic_ledger.rml',
parser=account_balance,
header=False)
report_sxw.report_sxw('report.afr.5cols',
'wizard.report',
parser=account_balance,
header=False)
report_sxw.report_sxw('report.afr.5cols',
'wizard.report',
'account_financial_report/report/balance_full_5_cols.rml', 'account_financial_report/report/balance_full_5_cols.rml',
parser=account_balance,
header=False)
report_sxw.report_sxw('report.afr.qtrcols',
'wizard.report',
parser=account_balance,
header=False)
report_sxw.report_sxw('report.afr.qtrcols',
'wizard.report',
'account_financial_report/report/balance_full_qtr_cols.rml', 'account_financial_report/report/balance_full_qtr_cols.rml',
parser=account_balance,
header=False)
parser=account_balance,
header=False)
report_sxw.report_sxw('report.afr.13cols',
'wizard.report',
report_sxw.report_sxw('report.afr.13cols',
'wizard.report',
'account_financial_report/report/balance_full_13_cols.rml', 'account_financial_report/report/balance_full_13_cols.rml',
parser=account_balance,
header=False)
parser=account_balance,
header=False)

23
account_financial_report/view/account_view.xml

@ -1,23 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!--
=====================================================
Vista para agregar ala vista en lista de la lista de
cuentas contables el campo padre.
=====================================================
-->
<record id="view_account_search_padre" model="ir.ui.view">
<field name="name">account.account.search.padre</field>
<field name="model">account.account</field>
<field name="type">search</field>
<field name="inherit_id" ref="account.view_account_search"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='code']" position="after">
<field name="parent_id"/>
</xpath>
</field>
</record>
</data>
</openerp>
Loading…
Cancel
Save