2010-05-19 10:49:20 +00:00
|
|
|
# -*- encoding: utf-8 -*-
|
|
|
|
##############################################################################
|
2010-07-14 10:55:46 +00:00
|
|
|
#
|
2010-05-19 10:49:20 +00:00
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
2010-07-14 10:55:46 +00:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2010-05-19 10:49:20 +00:00
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
import time
|
2010-07-14 10:55:46 +00:00
|
|
|
|
|
|
|
import pooler
|
2010-05-19 10:49:20 +00:00
|
|
|
import rml_parse
|
|
|
|
from report import report_sxw
|
2010-08-02 13:44:42 +00:00
|
|
|
from account.report import account_profit_loss
|
2010-07-14 12:54:18 +00:00
|
|
|
from common_report_header import common_report_header
|
2010-05-19 10:49:20 +00:00
|
|
|
|
2010-07-14 12:54:18 +00:00
|
|
|
class report_balancesheet_horizontal(rml_parse.rml_parse, common_report_header):
|
2010-07-14 10:55:46 +00:00
|
|
|
def __init__(self, cr, uid, name, context=None):
|
|
|
|
super(report_balancesheet_horizontal, self).__init__(cr, uid, name, context=context)
|
2010-08-03 05:19:25 +00:00
|
|
|
self.obj_pl = account_profit_loss.report_pl_account_horizontal(cr, uid, name, context=context)
|
2010-07-14 10:55:46 +00:00
|
|
|
self.result_sum_dr = 0.0
|
|
|
|
self.result_sum_cr = 0.0
|
2010-05-19 10:49:20 +00:00
|
|
|
self.result = {}
|
2010-08-02 04:42:43 +00:00
|
|
|
self.res_bl = {}
|
2010-07-14 10:55:46 +00:00
|
|
|
self.result_temp = []
|
2010-05-19 10:49:20 +00:00
|
|
|
self.localcontext.update({
|
|
|
|
'time': time,
|
2010-10-08 12:49:22 +00:00
|
|
|
'get_lines': self.get_lines,
|
|
|
|
'get_lines_another': self.get_lines_another,
|
2010-07-14 10:55:46 +00:00
|
|
|
'get_company': self._get_company,
|
2010-05-19 10:49:20 +00:00
|
|
|
'get_currency': self._get_currency,
|
2010-10-08 12:49:22 +00:00
|
|
|
'sum_dr': self.sum_dr,
|
|
|
|
'sum_cr': self.sum_cr,
|
2010-05-19 10:49:20 +00:00
|
|
|
'get_data':self.get_data,
|
|
|
|
'get_pl_balance':self.get_pl_balance,
|
2010-07-22 05:36:54 +00:00
|
|
|
'get_fiscalyear': self._get_fiscalyear,
|
|
|
|
'get_account': self._get_account,
|
|
|
|
'get_start_period': self.get_start_period,
|
|
|
|
'get_end_period': self.get_end_period,
|
|
|
|
'get_sortby': self._get_sortby,
|
|
|
|
'get_filter': self._get_filter,
|
|
|
|
'get_journal': self._get_journal,
|
|
|
|
'get_start_date':self._get_start_date,
|
2010-08-02 04:42:43 +00:00
|
|
|
'get_end_date':self._get_end_date,
|
|
|
|
'get_company':self._get_company,
|
2010-10-04 11:31:09 +00:00
|
|
|
'get_target_move': self._get_target_move,
|
2010-05-19 10:49:20 +00:00
|
|
|
})
|
|
|
|
self.context = context
|
2010-08-02 04:42:43 +00:00
|
|
|
|
2010-05-19 10:49:20 +00:00
|
|
|
def sum_dr(self):
|
2010-08-02 04:42:43 +00:00
|
|
|
if self.res_bl['type'] == 'Net Profit':
|
2010-10-04 12:58:11 +00:00
|
|
|
self.result_sum_dr += self.res_bl['balance']*-1
|
2010-09-06 13:52:05 +00:00
|
|
|
return self.result_sum_dr
|
2010-07-14 10:55:46 +00:00
|
|
|
|
2010-05-19 10:49:20 +00:00
|
|
|
def sum_cr(self):
|
2010-08-02 04:42:43 +00:00
|
|
|
if self.res_bl['type'] == 'Net Loss':
|
|
|
|
self.result_sum_cr += self.res_bl['balance']
|
2010-09-06 13:52:05 +00:00
|
|
|
return self.result_sum_cr
|
2010-05-19 10:49:20 +00:00
|
|
|
|
|
|
|
def get_pl_balance(self):
|
2010-09-06 13:52:05 +00:00
|
|
|
return self.res_bl
|
2010-07-14 10:55:46 +00:00
|
|
|
|
2010-07-22 10:22:42 +00:00
|
|
|
def get_data(self,data):
|
2010-05-19 10:49:20 +00:00
|
|
|
cr, uid = self.cr, self.uid
|
|
|
|
db_pool = pooler.get_pool(self.cr.dbname)
|
2010-07-14 10:55:46 +00:00
|
|
|
|
2010-05-19 10:49:20 +00:00
|
|
|
#Getting Profit or Loss Balance from profit and Loss report
|
2010-10-20 05:43:57 +00:00
|
|
|
self.obj_pl.get_data(data)
|
2010-08-02 04:42:43 +00:00
|
|
|
self.res_bl = self.obj_pl.final_result()
|
2010-07-14 10:55:46 +00:00
|
|
|
|
2010-05-19 10:49:20 +00:00
|
|
|
account_pool = db_pool.get('account.account')
|
|
|
|
|
|
|
|
types = [
|
|
|
|
'liability',
|
|
|
|
'asset'
|
|
|
|
]
|
|
|
|
|
|
|
|
ctx = self.context.copy()
|
2010-08-02 04:42:43 +00:00
|
|
|
ctx['fiscalyear'] = data['form'].get('fiscalyear_id', False)
|
2010-07-14 10:55:46 +00:00
|
|
|
|
2010-10-08 12:49:22 +00:00
|
|
|
if data['form']['filter'] == 'filter_period':
|
2010-08-02 04:42:43 +00:00
|
|
|
ctx['periods'] = data['form'].get('periods', False)
|
|
|
|
elif data['form']['filter'] == 'filter_date':
|
|
|
|
ctx['date_from'] = data['form'].get('date_from', False)
|
|
|
|
ctx['date_to'] = data['form'].get('date_to', False)
|
2010-09-16 09:05:06 +00:00
|
|
|
ctx['state'] = data['form'].get('target_move', 'all')
|
2010-08-02 04:42:43 +00:00
|
|
|
cal_list = {}
|
2010-05-19 10:49:20 +00:00
|
|
|
pl_dict = {}
|
|
|
|
account_dict = {}
|
2010-08-02 04:42:43 +00:00
|
|
|
account_id = data['form'].get('chart_account_id', False)
|
2010-05-19 10:49:20 +00:00
|
|
|
account_ids = account_pool._get_children_and_consol(cr, uid, account_id, context=ctx)
|
|
|
|
accounts = account_pool.browse(cr, uid, account_ids, context=ctx)
|
|
|
|
|
2010-10-21 11:31:12 +00:00
|
|
|
if self.res_bl['type'] == 'Net Profit':
|
2010-08-02 04:42:43 +00:00
|
|
|
self.res_bl['type'] = 'Net Profit'
|
2010-05-19 10:49:20 +00:00
|
|
|
else:
|
2010-08-02 04:42:43 +00:00
|
|
|
self.res_bl['type'] = 'Net Loss'
|
2010-05-19 10:49:20 +00:00
|
|
|
pl_dict = {
|
2010-10-13 07:32:33 +00:00
|
|
|
'code': self.res_bl['type'],
|
2010-10-08 12:49:22 +00:00
|
|
|
'name': self.res_bl['type'],
|
2010-05-20 15:26:15 +00:00
|
|
|
'level': False,
|
2010-08-02 04:42:43 +00:00
|
|
|
'balance':self.res_bl['balance'],
|
2010-05-20 15:26:15 +00:00
|
|
|
}
|
2010-05-19 10:49:20 +00:00
|
|
|
for typ in types:
|
|
|
|
accounts_temp = []
|
|
|
|
for account in accounts:
|
|
|
|
if (account.user_type.report_type) and (account.user_type.report_type == typ):
|
|
|
|
account_dict = {
|
2010-10-08 12:49:22 +00:00
|
|
|
'id': account.id,
|
|
|
|
'code': account.code,
|
|
|
|
'name': account.name,
|
2010-05-20 15:26:15 +00:00
|
|
|
'level': account.level,
|
|
|
|
'balance':account.balance,
|
|
|
|
}
|
2010-05-19 10:49:20 +00:00
|
|
|
if typ == 'liability' and account.type <> 'view' and (account.debit <> account.credit):
|
2010-10-04 12:58:11 +00:00
|
|
|
self.result_sum_dr += account.balance
|
2010-05-19 10:49:20 +00:00
|
|
|
if typ == 'asset' and account.type <> 'view' and (account.debit <> account.credit):
|
2010-10-04 12:58:11 +00:00
|
|
|
self.result_sum_cr += account.balance
|
2010-07-27 04:44:18 +00:00
|
|
|
if data['form']['display_account'] == 'bal_movement':
|
2010-10-08 12:49:22 +00:00
|
|
|
if account.credit > 0 or account.debit > 0 or account.balance > 0:
|
2010-05-19 10:49:20 +00:00
|
|
|
accounts_temp.append(account_dict)
|
2010-07-22 10:22:42 +00:00
|
|
|
elif data['form']['display_account'] == 'bal_solde':
|
2010-08-02 04:42:43 +00:00
|
|
|
if account.balance != 0:
|
2010-05-19 10:49:20 +00:00
|
|
|
accounts_temp.append(account_dict)
|
|
|
|
else:
|
|
|
|
accounts_temp.append(account_dict)
|
2010-07-22 10:22:42 +00:00
|
|
|
if account.id == data['form']['reserve_account_id']:
|
2010-05-19 10:49:20 +00:00
|
|
|
pl_dict['level'] = account['level'] + 1
|
|
|
|
accounts_temp.append(pl_dict)
|
2010-07-14 10:55:46 +00:00
|
|
|
|
2010-05-19 10:49:20 +00:00
|
|
|
self.result[typ] = accounts_temp
|
|
|
|
cal_list[typ]=self.result[typ]
|
2010-05-20 17:59:46 +00:00
|
|
|
|
2010-05-19 10:49:20 +00:00
|
|
|
if cal_list:
|
2010-08-02 04:42:43 +00:00
|
|
|
temp = {}
|
2010-05-19 10:49:20 +00:00
|
|
|
for i in range(0,max(len(cal_list['liability']),len(cal_list['asset']))):
|
|
|
|
if i < len(cal_list['liability']) and i < len(cal_list['asset']):
|
|
|
|
temp={
|
2010-10-08 12:49:22 +00:00
|
|
|
'code': cal_list['liability'][i]['code'],
|
|
|
|
'name': cal_list['liability'][i]['name'],
|
2010-05-19 10:49:20 +00:00
|
|
|
'level': cal_list['liability'][i]['level'],
|
|
|
|
'balance':cal_list['liability'][i]['balance'],
|
2010-10-08 12:49:22 +00:00
|
|
|
'code1': cal_list['asset'][i]['code'],
|
|
|
|
'name1': cal_list['asset'][i]['name'],
|
2010-05-19 10:49:20 +00:00
|
|
|
'level1': cal_list['asset'][i]['level'],
|
|
|
|
'balance1':cal_list['asset'][i]['balance'],
|
|
|
|
}
|
|
|
|
self.result_temp.append(temp)
|
|
|
|
else:
|
|
|
|
if i < len(cal_list['asset']):
|
|
|
|
temp={
|
2010-10-08 12:49:22 +00:00
|
|
|
'code': '',
|
|
|
|
'name': '',
|
2010-05-19 10:49:20 +00:00
|
|
|
'level': False,
|
|
|
|
'balance':False,
|
2010-10-08 12:49:22 +00:00
|
|
|
'code1': cal_list['asset'][i]['code'],
|
|
|
|
'name1': cal_list['asset'][i]['name'],
|
2010-05-19 10:49:20 +00:00
|
|
|
'level1': cal_list['asset'][i]['level'],
|
|
|
|
'balance1':cal_list['asset'][i]['balance'],
|
2010-05-20 15:26:15 +00:00
|
|
|
}
|
2010-05-19 10:49:20 +00:00
|
|
|
self.result_temp.append(temp)
|
2010-07-14 10:55:46 +00:00
|
|
|
if i < len(cal_list['liability']):
|
2010-05-19 10:49:20 +00:00
|
|
|
temp={
|
2010-10-08 12:49:22 +00:00
|
|
|
'code': cal_list['liability'][i]['code'],
|
|
|
|
'name': cal_list['liability'][i]['name'],
|
2010-05-19 10:49:20 +00:00
|
|
|
'level': cal_list['liability'][i]['level'],
|
|
|
|
'balance':cal_list['liability'][i]['balance'],
|
2010-10-08 12:49:22 +00:00
|
|
|
'code1': '',
|
|
|
|
'name1': '',
|
2010-05-19 10:49:20 +00:00
|
|
|
'level1': False,
|
|
|
|
'balance1':False,
|
2010-05-20 15:26:15 +00:00
|
|
|
}
|
2010-05-19 10:49:20 +00:00
|
|
|
self.result_temp.append(temp)
|
|
|
|
return None
|
2010-07-14 10:55:46 +00:00
|
|
|
|
2010-05-19 10:49:20 +00:00
|
|
|
def get_lines(self):
|
|
|
|
return self.result_temp
|
|
|
|
|
|
|
|
def get_lines_another(self, group):
|
|
|
|
return self.result.get(group, [])
|
2010-07-14 10:55:46 +00:00
|
|
|
|
2010-05-19 10:49:20 +00:00
|
|
|
report_sxw.report_sxw('report.account.balancesheet.horizontal', 'account.account',
|
2010-08-02 12:53:48 +00:00
|
|
|
'addons/account/report/account_balance_sheet_horizontal.rml',parser=report_balancesheet_horizontal,
|
2010-08-24 12:37:11 +00:00
|
|
|
header='internal landscape')
|
2010-05-19 10:49:20 +00:00
|
|
|
|
|
|
|
report_sxw.report_sxw('report.account.balancesheet', 'account.account',
|
2010-08-02 12:53:48 +00:00
|
|
|
'addons/account/report/account_balance_sheet.rml',parser=report_balancesheet_horizontal,
|
2010-07-27 09:00:53 +00:00
|
|
|
header='internal')
|
2010-08-02 04:42:43 +00:00
|
|
|
|
2010-10-20 07:00:04 +00:00
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|