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.

276 lines
11 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
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. from openerp.report import report_sxw
  26. from openerp.addons.account_financial_report_horizontal.report import (
  27. account_profit_loss
  28. )
  29. from common_report_header import common_report_header
  30. from openerp.tools.translate import _
  31. class report_balancesheet_horizontal(
  32. report_sxw.rml_parse, common_report_header
  33. ):
  34. def __init__(self, cr, uid, name, context=None):
  35. super(report_balancesheet_horizontal, self).__init__(
  36. cr, uid, name, context=context)
  37. self.obj_pl = account_profit_loss.report_pl_account_horizontal(
  38. cr, uid, name, context=context)
  39. self.result_sum_dr = 0.0
  40. self.result_sum_cr = 0.0
  41. self.result = {}
  42. self.res_bl = {}
  43. self.result_temp = []
  44. self.localcontext.update({
  45. 'time': time,
  46. 'get_lines': self.get_lines,
  47. 'get_lines_another': self.get_lines_another,
  48. 'sum_dr': self.sum_dr,
  49. 'sum_cr': self.sum_cr,
  50. 'get_data': self.get_data,
  51. 'get_pl_balance': self.get_pl_balance,
  52. 'get_fiscalyear': self._get_fiscalyear,
  53. 'get_account': self._get_account,
  54. 'get_start_period': self.get_start_period,
  55. 'get_end_period': self.get_end_period,
  56. 'get_sortby': self._get_sortby,
  57. 'get_filter': self._get_filter,
  58. 'get_start_date': self._get_start_date,
  59. 'get_end_date': self._get_end_date,
  60. 'get_target_move': self._get_target_move,
  61. })
  62. self.context = context
  63. def set_context(self, objects, data, ids, report_type=None):
  64. new_ids = ids
  65. if (data['model'] == 'ir.ui.menu'):
  66. new_ids = 'chart_account_id' in data['form']\
  67. and data['form']['chart_account_id']\
  68. and [data['form']['chart_account_id'][0]] or []
  69. objects = self.pool.get('account.account').browse(
  70. self.cr, self.uid, new_ids)
  71. lang_dict = self.pool.get('res.users').read(
  72. self.cr, self.uid, self.uid, ['context_lang'])
  73. data['lang'] = lang_dict.get('context_lang') or False
  74. return super(
  75. report_balancesheet_horizontal, self
  76. ).set_context(objects, data, new_ids, report_type=report_type)
  77. def sum_dr(self):
  78. if self.res_bl['type'] == _('Net Profit'):
  79. self.result_sum_dr += self.res_bl['balance']
  80. return self.result_sum_dr
  81. def sum_cr(self):
  82. if self.res_bl['type'] == _('Net Loss'):
  83. self.result_sum_cr += self.res_bl['balance']
  84. return self.result_sum_cr
  85. def get_pl_balance(self):
  86. return self.res_bl
  87. def get_data(self, data):
  88. cr, uid = self.cr, self.uid
  89. # Getting Profit or Loss Balance from profit and Loss report
  90. self.obj_pl.get_data(data)
  91. self.res_bl = self.obj_pl.final_result()
  92. account_pool = self.pool['account.account']
  93. currency_pool = self.pool['res.currency']
  94. types = [
  95. 'liability',
  96. 'asset'
  97. ]
  98. ctx = self.context.copy()
  99. ctx['fiscalyear'] = data['form'].get('fiscalyear_id', False)
  100. if ctx['fiscalyear']:
  101. ctx['fiscalyear'] = ctx['fiscalyear'][0]
  102. if data['form']['filter'] == 'filter_period':
  103. ctx['periods'] = data['form'].get('periods', False)
  104. elif data['form']['filter'] == 'filter_date':
  105. ctx['date_from'] = data['form'].get('date_from', False)
  106. ctx['date_to'] = data['form'].get('date_to', False)
  107. ctx['state'] = data['form'].get('target_move', 'all')
  108. cal_list = {}
  109. account_dict = {}
  110. account_id = data['form'].get('chart_account_id', False)
  111. if account_id:
  112. account_id = account_id[0]
  113. account_ids = account_pool._get_children_and_consol(
  114. cr, uid, account_id, context=ctx)
  115. accounts = account_pool.browse(cr, uid, account_ids, context=ctx)
  116. if not self.res_bl:
  117. self.res_bl['type'] = _('Net Profit')
  118. self.res_bl['balance'] = 0.0
  119. if self.res_bl['type'] == _('Net Profit'):
  120. self.res_bl['type'] = _('Net Profit')
  121. else:
  122. self.res_bl['type'] = _('Net Loss')
  123. pl_dict = {
  124. 'code': self.res_bl['type'],
  125. 'name': self.res_bl['type'],
  126. 'level': False,
  127. 'balance': self.res_bl['balance'],
  128. 'type': self.res_bl['type'],
  129. }
  130. for typ in types:
  131. accounts_temp = []
  132. for account in accounts:
  133. if (account.user_type.report_type) and (
  134. account.user_type.report_type == typ
  135. ):
  136. account_dict = {
  137. 'id': account.id,
  138. 'code': account.code,
  139. 'name': account.name,
  140. 'level': account.level,
  141. 'balance': (
  142. account.balance and typ == 'liability' and -1 or 1
  143. ) * account.balance,
  144. 'type': account.type,
  145. }
  146. currency = (
  147. account.currency_id and account.currency_id
  148. or account.company_id.currency_id
  149. )
  150. if typ == 'liability' and account.type != 'view' and (
  151. account.debit != account.credit
  152. ):
  153. self.result_sum_dr += account_dict['balance']
  154. if typ == 'asset' and account.type != 'view' and (
  155. account.debit != account.credit
  156. ):
  157. self.result_sum_cr += account_dict['balance']
  158. if data['form']['display_account'] == 'bal_movement':
  159. if (
  160. not currency_pool.is_zero(
  161. self.cr, self.uid, currency, account.credit
  162. )) or (
  163. not currency_pool.is_zero(
  164. self.cr, self.uid, currency, account.debit
  165. )
  166. ) or (
  167. not currency_pool.is_zero(
  168. self.cr, self.uid, currency,
  169. account.balance
  170. )
  171. ):
  172. accounts_temp.append(account_dict)
  173. elif data['form']['display_account'] == 'bal_solde':
  174. if not currency_pool.is_zero(
  175. self.cr, self.uid, currency, account.balance
  176. ):
  177. accounts_temp.append(account_dict)
  178. else:
  179. accounts_temp.append(account_dict)
  180. self.result[typ] = accounts_temp
  181. cal_list[typ] = self.result[typ]
  182. if pl_dict['code'] == _('Net Loss'):
  183. self.result['asset'].append(pl_dict)
  184. else:
  185. self.result['liability'].append(pl_dict)
  186. if cal_list:
  187. temp = {}
  188. for i in range(
  189. 0, max(len(cal_list['liability']), len(cal_list['asset']))
  190. ):
  191. if i < len(cal_list['liability']) and i < len(
  192. cal_list['asset']
  193. ):
  194. temp = {
  195. 'code': cal_list['liability'][i]['code'],
  196. 'name': cal_list['liability'][i]['name'],
  197. 'level': cal_list['liability'][i]['level'],
  198. 'balance': cal_list['liability'][i]['balance'],
  199. 'type': cal_list['liability'][i]['type'],
  200. 'code1': cal_list['asset'][i]['code'],
  201. 'name1': cal_list['asset'][i]['name'],
  202. 'level1': cal_list['asset'][i]['level'],
  203. 'balance1': cal_list['asset'][i]['balance'],
  204. 'type1': cal_list['asset'][i]['type'],
  205. }
  206. self.result_temp.append(temp)
  207. else:
  208. if i < len(cal_list['asset']):
  209. temp = {
  210. 'code': '',
  211. 'name': '',
  212. 'level': False,
  213. 'balance': False,
  214. 'type': False,
  215. 'code1': cal_list['asset'][i]['code'],
  216. 'name1': cal_list['asset'][i]['name'],
  217. 'level1': cal_list['asset'][i]['level'],
  218. 'balance1': cal_list['asset'][i]['balance'],
  219. 'type1': cal_list['asset'][i]['type'],
  220. }
  221. self.result_temp.append(temp)
  222. if i < len(cal_list['liability']):
  223. temp = {
  224. 'code': cal_list['liability'][i]['code'],
  225. 'name': cal_list['liability'][i]['name'],
  226. 'level': cal_list['liability'][i]['level'],
  227. 'balance': cal_list['liability'][i]['balance'],
  228. 'type': cal_list['liability'][i]['type'],
  229. 'code1': '',
  230. 'name1': '',
  231. 'level1': False,
  232. 'balance1': False,
  233. 'type1': False,
  234. }
  235. self.result_temp.append(temp)
  236. return None
  237. def get_lines(self):
  238. return self.result_temp
  239. def get_lines_another(self, group):
  240. return self.result.get(group, [])
  241. report_sxw.report_sxw(
  242. 'report.account.balancesheet.horizontal', 'account.account',
  243. 'addons/account_financial_report_horizontal/report/'
  244. 'account_balance_sheet_horizontal.rml',
  245. parser=report_balancesheet_horizontal,
  246. header='internal landscape')
  247. report_sxw.report_sxw(
  248. 'report.account.balancesheet', 'account.account',
  249. 'addons/account_financial_report_horizontal/report/'
  250. 'account_balance_sheet.rml',
  251. parser=report_balancesheet_horizontal,
  252. header='internal')