You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

282 lines
12 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # This module copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>),
  6. # Copyright (C) 2012 Therp BV (<http://therp.nl>),
  7. # Copyright (C) 2013 Agile Business Group sagl
  8. # (<http://www.agilebg.com>) (<lorenzo.battistini@agilebg.com>)
  9. #
  10. # This program is free software: you can redistribute it and/or modify
  11. # it under the terms of the GNU Affero General Public License as
  12. # published by the Free Software Foundation, either version 3 of the
  13. # License, or (at your option) any later version.
  14. #
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU Affero General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU Affero General Public License
  21. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. #
  23. ##############################################################################
  24. import time
  25. import pooler
  26. from report import report_sxw
  27. from openerp.addons.account_financial_report_horizontal.report import (
  28. account_profit_loss
  29. )
  30. from common_report_header import common_report_header
  31. from tools.translate import _
  32. class report_balancesheet_horizontal(
  33. report_sxw.rml_parse, common_report_header
  34. ):
  35. def __init__(self, cr, uid, name, context=None):
  36. super(report_balancesheet_horizontal, self).__init__(
  37. cr, uid, name, context=context)
  38. self.obj_pl = account_profit_loss.report_pl_account_horizontal(
  39. cr, uid, name, context=context)
  40. self.result_sum_dr = 0.0
  41. self.result_sum_cr = 0.0
  42. self.result = {}
  43. self.res_bl = {}
  44. self.result_temp = []
  45. self.localcontext.update({
  46. 'time': time,
  47. 'get_lines': self.get_lines,
  48. 'get_lines_another': self.get_lines_another,
  49. 'sum_dr': self.sum_dr,
  50. 'sum_cr': self.sum_cr,
  51. 'get_data': self.get_data,
  52. 'get_pl_balance': self.get_pl_balance,
  53. 'get_fiscalyear': self._get_fiscalyear,
  54. 'get_account': self._get_account,
  55. 'get_start_period': self.get_start_period,
  56. 'get_end_period': self.get_end_period,
  57. 'get_sortby': self._get_sortby,
  58. 'get_filter': self._get_filter,
  59. 'get_start_date': self._get_start_date,
  60. 'get_end_date': self._get_end_date,
  61. 'get_target_move': self._get_target_move,
  62. })
  63. self.context = context
  64. def set_context(self, objects, data, ids, report_type=None):
  65. new_ids = ids
  66. if (data['model'] == 'ir.ui.menu'):
  67. new_ids = 'chart_account_id' in data['form'] and data[
  68. 'form'
  69. ]['chart_account_id'] and [data[
  70. 'form'
  71. ]['chart_account_id'][0]] or []
  72. objects = self.pool.get('account.account').browse(
  73. self.cr, self.uid, new_ids)
  74. lang_dict = self.pool.get('res.users').read(
  75. self.cr, self.uid, self.uid, ['context_lang'])
  76. data['lang'] = lang_dict.get('context_lang') or False
  77. return super(
  78. report_balancesheet_horizontal, self
  79. ).set_context(objects, data, new_ids, report_type=report_type)
  80. def sum_dr(self):
  81. if self.res_bl['type'] == _('Net Profit'):
  82. self.result_sum_dr += self.res_bl['balance']
  83. return self.result_sum_dr
  84. def sum_cr(self):
  85. if self.res_bl['type'] == _('Net Loss'):
  86. self.result_sum_cr += self.res_bl['balance']
  87. return self.result_sum_cr
  88. def get_pl_balance(self):
  89. return self.res_bl
  90. def get_data(self, data):
  91. cr, uid = self.cr, self.uid
  92. db_pool = pooler.get_pool(self.cr.dbname)
  93. #Getting Profit or Loss Balance from profit and Loss report
  94. self.obj_pl.get_data(data)
  95. self.res_bl = self.obj_pl.final_result()
  96. account_pool = db_pool.get('account.account')
  97. currency_pool = db_pool.get('res.currency')
  98. types = [
  99. 'liability',
  100. 'asset'
  101. ]
  102. ctx = self.context.copy()
  103. ctx['fiscalyear'] = data['form'].get('fiscalyear_id', False)
  104. if ctx['fiscalyear']:
  105. ctx['fiscalyear'] = ctx['fiscalyear'][0]
  106. if data['form']['filter'] == 'filter_period':
  107. ctx['periods'] = data['form'].get('periods', False)
  108. elif data['form']['filter'] == 'filter_date':
  109. ctx['date_from'] = data['form'].get('date_from', False)
  110. ctx['date_to'] = data['form'].get('date_to', False)
  111. ctx['state'] = data['form'].get('target_move', 'all')
  112. cal_list = {}
  113. pl_dict = {}
  114. account_dict = {}
  115. account_id = data['form'].get('chart_account_id', False)
  116. if account_id:
  117. account_id = account_id[0]
  118. account_ids = account_pool._get_children_and_consol(
  119. cr, uid, account_id, context=ctx)
  120. accounts = account_pool.browse(cr, uid, account_ids, context=ctx)
  121. if not self.res_bl:
  122. self.res_bl['type'] = _('Net Profit')
  123. self.res_bl['balance'] = 0.0
  124. if self.res_bl['type'] == _('Net Profit'):
  125. self.res_bl['type'] = _('Net Profit')
  126. else:
  127. self.res_bl['type'] = _('Net Loss')
  128. pl_dict = {
  129. 'code': self.res_bl['type'],
  130. 'name': self.res_bl['type'],
  131. 'level': False,
  132. 'balance': self.res_bl['balance'],
  133. 'type': self.res_bl['type'],
  134. }
  135. for typ in types:
  136. accounts_temp = []
  137. for account in accounts:
  138. if (account.user_type.report_type) and (
  139. account.user_type.report_type == typ
  140. ):
  141. account_dict = {
  142. 'id': account.id,
  143. 'code': account.code,
  144. 'name': account.name,
  145. 'level': account.level,
  146. 'balance': (
  147. account.balance and typ == 'liability' and -1 or 1
  148. ) * account.balance,
  149. 'type': account.type,
  150. }
  151. currency = (
  152. account.currency_id and account.currency_id
  153. or account.company_id.currency_id
  154. )
  155. if typ == 'liability' and account.type != 'view' and (
  156. account.debit != account.credit
  157. ):
  158. self.result_sum_dr += account_dict['balance']
  159. if typ == 'asset' and account.type != 'view' and (
  160. account.debit != account.credit
  161. ):
  162. self.result_sum_cr += account_dict['balance']
  163. if data['form']['display_account'] == 'bal_movement':
  164. if (
  165. not currency_pool.is_zero(
  166. self.cr, self.uid, currency, account.credit
  167. )) or (
  168. not currency_pool.is_zero(
  169. self.cr, self.uid, currency, account.debit
  170. )
  171. ) or (
  172. not currency_pool.is_zero(
  173. self.cr, self.uid, currency,
  174. account.balance
  175. )
  176. ):
  177. accounts_temp.append(account_dict)
  178. elif data['form']['display_account'] == 'bal_solde':
  179. if not currency_pool.is_zero(
  180. self.cr, self.uid, currency, account.balance
  181. ):
  182. accounts_temp.append(account_dict)
  183. else:
  184. accounts_temp.append(account_dict)
  185. self.result[typ] = accounts_temp
  186. cal_list[typ] = self.result[typ]
  187. if pl_dict['code'] == _('Net Loss'):
  188. self.result['asset'].append(pl_dict)
  189. else:
  190. self.result['liability'].append(pl_dict)
  191. if cal_list:
  192. temp = {}
  193. for i in range(
  194. 0, max(len(cal_list['liability']), len(cal_list['asset']))
  195. ):
  196. if i < len(cal_list['liability']) and i < len(
  197. cal_list['asset']
  198. ):
  199. temp = {
  200. 'code': cal_list['liability'][i]['code'],
  201. 'name': cal_list['liability'][i]['name'],
  202. 'level': cal_list['liability'][i]['level'],
  203. 'balance': cal_list['liability'][i]['balance'],
  204. 'type': cal_list['liability'][i]['type'],
  205. 'code1': cal_list['asset'][i]['code'],
  206. 'name1': cal_list['asset'][i]['name'],
  207. 'level1': cal_list['asset'][i]['level'],
  208. 'balance1': cal_list['asset'][i]['balance'],
  209. 'type1': cal_list['asset'][i]['type'],
  210. }
  211. self.result_temp.append(temp)
  212. else:
  213. if i < len(cal_list['asset']):
  214. temp = {
  215. 'code': '',
  216. 'name': '',
  217. 'level': False,
  218. 'balance': False,
  219. 'type': False,
  220. 'code1': cal_list['asset'][i]['code'],
  221. 'name1': cal_list['asset'][i]['name'],
  222. 'level1': cal_list['asset'][i]['level'],
  223. 'balance1': cal_list['asset'][i]['balance'],
  224. 'type1': cal_list['asset'][i]['type'],
  225. }
  226. self.result_temp.append(temp)
  227. if i < len(cal_list['liability']):
  228. temp = {
  229. 'code': cal_list['liability'][i]['code'],
  230. 'name': cal_list['liability'][i]['name'],
  231. 'level': cal_list['liability'][i]['level'],
  232. 'balance': cal_list['liability'][i]['balance'],
  233. 'type': cal_list['liability'][i]['type'],
  234. 'code1': '',
  235. 'name1': '',
  236. 'level1': False,
  237. 'balance1': False,
  238. 'type1': False,
  239. }
  240. self.result_temp.append(temp)
  241. return None
  242. def get_lines(self):
  243. return self.result_temp
  244. def get_lines_another(self, group):
  245. return self.result.get(group, [])
  246. report_sxw.report_sxw(
  247. 'report.account.balancesheet.horizontal', 'account.account',
  248. 'addons/account_financial_report_horizontal/report/'
  249. 'account_balance_sheet_horizontal.rml',
  250. parser=report_balancesheet_horizontal,
  251. header='internal landscape')
  252. report_sxw.report_sxw(
  253. 'report.account.balancesheet', 'account.account',
  254. 'addons/account_financial_report_horizontal/report/'
  255. 'account_balance_sheet.rml',
  256. parser=report_balancesheet_horizontal,
  257. header='internal')
  258. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: