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.

185 lines
8.3 KiB

  1. # -*- encoding: utf-8 -*-
  2. ###########################################################################
  3. # Module Writen to OpenERP, Open Source Management Solution
  4. # Copyright (C) OpenERP Venezuela (<http://openerp.com.ve>).
  5. # All Rights Reserved
  6. # Credits######################################################
  7. # Coded by: Humberto Arocha humberto@openerp.com.ve
  8. # Angelica Barrios angelicaisabelb@gmail.com
  9. # Jordi Esteve <jesteve@zikzakmedia.com>
  10. # Javier Duran <javieredm@gmail.com>
  11. # Planified by: Humberto Arocha
  12. # Finance by: LUBCAN COL S.A.S http://www.lubcancol.com
  13. # Audited by: Humberto Arocha humberto@openerp.com.ve
  14. #############################################################################
  15. # This program is free software: you can redistribute it and/or modify
  16. # it under the terms of the GNU General Public License as published by
  17. # the Free Software Foundation, either version 3 of the License, or
  18. # (at your option) any later version.
  19. #
  20. # This program is distributed in the hope that it will be useful,
  21. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. # GNU General Public License for more details.
  24. #
  25. # You should have received a copy of the GNU General Public License
  26. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  27. ##############################################################################
  28. from osv import osv, fields
  29. #~ import pooler
  30. import time
  31. from tools.translate import _
  32. class account_financial_report(osv.osv):
  33. _name = "afr"
  34. _columns = {
  35. 'name': fields.char('Name', size=128, required=True),
  36. 'company_id': fields.many2one('res.company', 'Company', required=True),
  37. 'currency_id': fields.many2one(
  38. 'res.currency', 'Currency', help="Currency at which this report will be expressed. If not selected will be used the one set in the company"),
  39. 'inf_type': fields.selection(
  40. [('BS', 'Balance Sheet'), ('IS', 'Income Statement')], 'Type', required=True),
  41. 'columns': fields.selection([('one', 'End. Balance'), ('two', 'Debit | Credit'), ('four', 'Initial | Debit | Credit | YTD'),
  42. ('five', 'Initial | Debit | Credit | Period | YTD'), ('qtr', "4 QTR's | YTD"), ('thirteen', '12 Months | YTD')], 'Columns', required=True),
  43. 'display_account': fields.selection([('all', 'All Accounts'), ('bal', 'With Balance'),
  44. ('mov', 'With movements'), ('bal_mov', 'With Balance / Movements')], 'Display accounts'),
  45. 'display_account_level': fields.integer(
  46. 'Up to level', help='Display accounts up to this level (0 to show all)'),
  47. 'account_ids': fields.many2many(
  48. 'account.account', 'afr_account_rel', 'afr_id', 'account_id', 'Root accounts', required=True),
  49. 'fiscalyear_id': fields.many2one(
  50. 'account.fiscalyear', 'Fiscal year', help='Fiscal Year for this report', required=True),
  51. 'period_ids': fields.many2many('account.period', 'afr_period_rel', 'afr_id',
  52. 'period_id', 'Periods', help='All periods in the fiscal year if empty'),
  53. 'analytic_ledger': fields.boolean(
  54. 'Analytic Ledger', help="Allows to Generate an Analytic Ledger for accounts with moves. Available when Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"),
  55. 'journal_ledger': fields.boolean(
  56. 'journal Ledger', help="Allows to Generate an journal Ledger for accounts with moves. Available when Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"),
  57. 'partner_balance': fields.boolean('Partner Balance', help="Allows to "
  58. "Generate a Partner Balance for accounts with moves. Available when "
  59. "Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"),
  60. 'tot_check': fields.boolean(
  61. 'Summarize?', help='Checking will add a new line at the end of the Report which will Summarize Columns in Report'),
  62. 'lab_str':
  63. fields.char(
  64. 'Description',
  65. help='Description for the Summary',
  66. size=128),
  67. 'target_move': fields.selection([('posted', 'All Posted Entries'),
  68. ('all', 'All Entries'),
  69. ], 'Entries to Include', required=True,
  70. help='Print All Accounting Entries or just Posted Accounting Entries'),
  71. 'narration': fields.text('Notes'),
  72. #~ Deprecated fields
  73. 'filter': fields.selection([('bydate', 'By Date'), ('byperiod', 'By Period'),
  74. ('all', 'By Date and Period'), ('none', 'No Filter')], 'Date/Period Filter'),
  75. 'date_to': fields.date('End date'),
  76. 'date_from': fields.date('Start date'),
  77. }
  78. _defaults = {
  79. 'display_account_level': lambda *a: 0,
  80. 'inf_type': lambda *a: 'BS',
  81. 'company_id': lambda self, cr, uid, c:
  82. self.pool.get(
  83. 'res.company')._company_default_get(
  84. cr,
  85. uid,
  86. 'account.invoice',
  87. context=c),
  88. 'fiscalyear_id': lambda self, cr, uid, c:
  89. self.pool.get('account.fiscalyear').find(cr, uid),
  90. 'display_account': lambda *a: 'bal_mov',
  91. 'columns': lambda *a: 'five',
  92. 'date_from': lambda *a: time.strftime('%Y-%m-%d'),
  93. 'date_to': lambda *a: time.strftime('%Y-%m-%d'),
  94. 'filter': lambda *a: 'byperiod',
  95. 'target_move': 'posted',
  96. }
  97. def copy(self, cr, uid, id, defaults, context=None):
  98. if context is None:
  99. context = {}
  100. previous_name = self.browse(cr, uid, id, context=context).name
  101. new_name = _('Copy of %s') % previous_name
  102. lst = self.search(cr, uid, [(
  103. 'name', 'like', new_name)], context=context)
  104. if lst:
  105. new_name = '%s (%s)' % (new_name, len(lst) + 1)
  106. defaults['name'] = new_name
  107. return (
  108. super(
  109. account_financial_report,
  110. self).copy(
  111. cr,
  112. uid,
  113. id,
  114. defaults,
  115. context=context)
  116. )
  117. def onchange_inf_type(self, cr, uid, ids, inf_type, context=None):
  118. if context is None:
  119. context = {}
  120. res = {'value': {}}
  121. if inf_type != 'BS':
  122. res['value'].update({'analytic_ledger': False})
  123. return res
  124. def onchange_columns(self, cr, uid, ids, columns,
  125. fiscalyear_id, period_ids, context=None):
  126. if context is None:
  127. context = {}
  128. res = {'value': {}}
  129. if columns != 'four':
  130. res['value'].update({'analytic_ledger': False})
  131. if columns in ('qtr', 'thirteen'):
  132. p_obj = self.pool.get("account.period")
  133. period_ids = p_obj.search(cr, uid, [('fiscalyear_id', '=', fiscalyear_id), (
  134. 'special', '=', False)], context=context)
  135. res['value'].update({'period_ids': period_ids})
  136. else:
  137. res['value'].update({'period_ids': []})
  138. return res
  139. def onchange_analytic_ledger(
  140. self, cr, uid, ids, company_id, analytic_ledger, context=None):
  141. if context is None:
  142. context = {}
  143. context['company_id'] = company_id
  144. res = {'value': {}}
  145. cur_id = self.pool.get('res.company').browse(
  146. cr, uid, company_id, context=context).currency_id.id
  147. res['value'].update({'currency_id': cur_id})
  148. return res
  149. def onchange_company_id(self, cr, uid, ids, company_id, context=None):
  150. if context is None:
  151. context = {}
  152. context['company_id'] = company_id
  153. res = {'value': {}}
  154. if not company_id:
  155. return res
  156. cur_id = self.pool.get('res.company').browse(
  157. cr, uid, company_id, context=context).currency_id.id
  158. fy_id = self.pool.get('account.fiscalyear').find(
  159. cr, uid, context=context)
  160. res['value'].update({'fiscalyear_id': fy_id})
  161. res['value'].update({'currency_id': cur_id})
  162. res['value'].update({'account_ids': []})
  163. res['value'].update({'period_ids': []})
  164. return res
  165. account_financial_report()