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.

143 lines
6.9 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
11 years ago
11 years ago
  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('res.currency', 'Currency', help="Currency at which this report will be expressed. If not selected will be used the one set in the company"),
  38. 'inf_type': fields.selection([('BS', 'Balance Sheet'), ('IS', 'Income Statement')], 'Type', required=True),
  39. '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),
  40. 'display_account': fields.selection([('all', 'All Accounts'), ('bal', 'With Balance'), ('mov', 'With movements'), ('bal_mov', 'With Balance / Movements')], 'Display accounts'),
  41. 'display_account_level': fields.integer('Up to level', help='Display accounts up to this level (0 to show all)'),
  42. 'account_ids': fields.many2many('account.account', 'afr_account_rel', 'afr_id', 'account_id', 'Root accounts', required=True),
  43. 'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscal year', help='Fiscal Year for this report', required=True),
  44. 'period_ids': fields.many2many('account.period', 'afr_period_rel', 'afr_id', 'period_id', 'Periods', help='All periods in the fiscal year if empty'),
  45. '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"),
  46. 'tot_check': fields.boolean('Summarize?', help='Checking will add a new line at the end of the Report which will Summarize Columns in Report'),
  47. 'lab_str': fields.char('Description', help='Description for the Summary', size=128),
  48. #~ Deprecated fields
  49. 'filter': fields.selection([('bydate', 'By Date'), ('byperiod', 'By Period'), ('all', 'By Date and Period'), ('none', 'No Filter')], 'Date/Period Filter'),
  50. 'date_to': fields.date('End date'),
  51. 'date_from': fields.date('Start date'),
  52. }
  53. _defaults = {
  54. 'display_account_level': lambda *a: 0,
  55. 'inf_type': lambda *a: 'BS',
  56. 'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.invoice', context=c),
  57. 'fiscalyear_id': lambda self, cr, uid, c: self.pool.get('account.fiscalyear').find(cr, uid),
  58. 'display_account': lambda *a: 'bal_mov',
  59. 'columns': lambda *a: 'five',
  60. 'date_from': lambda *a: time.strftime('%Y-%m-%d'),
  61. 'date_to': lambda *a: time.strftime('%Y-%m-%d'),
  62. 'filter': lambda *a: 'byperiod',
  63. }
  64. def copy(self, cr, uid, id, defaults, context=None):
  65. if context is None:
  66. context = {}
  67. previous_name = self.browse(cr, uid, id, context=context).name
  68. new_name = _('Copy of %s') % previous_name
  69. lst = self.search(cr, uid, [(
  70. 'name', 'like', new_name)], context=context)
  71. if lst:
  72. new_name = '%s (%s)' % (new_name, len(lst)+1)
  73. defaults['name'] = new_name
  74. return super(account_financial_report, self).copy(cr, uid, id, defaults, context=context)
  75. def onchange_inf_type(self, cr, uid, ids, inf_type, context=None):
  76. if context is None:
  77. context = {}
  78. res = {'value': {}}
  79. if inf_type != 'BS':
  80. res['value'].update({'analytic_ledger': False})
  81. return res
  82. def onchange_columns(self, cr, uid, ids, columns, fiscalyear_id, period_ids, context=None):
  83. if context is None:
  84. context = {}
  85. res = {'value': {}}
  86. if columns != 'four':
  87. res['value'].update({'analytic_ledger': False})
  88. if columns in ('qtr', 'thirteen'):
  89. p_obj = self.pool.get("account.period")
  90. period_ids = p_obj.search(cr, uid, [('fiscalyear_id', '=', fiscalyear_id), (
  91. 'special', '=', False)], context=context)
  92. res['value'].update({'period_ids': period_ids})
  93. else:
  94. res['value'].update({'period_ids': []})
  95. return res
  96. def onchange_analytic_ledger(self, cr, uid, ids, company_id, analytic_ledger, context=None):
  97. if context is None:
  98. context = {}
  99. context['company_id'] = company_id
  100. res = {'value': {}}
  101. cur_id = self.pool.get('res.company').browse(
  102. cr, uid, company_id, context=context).currency_id.id
  103. res['value'].update({'currency_id': cur_id})
  104. return res
  105. def onchange_company_id(self, cr, uid, ids, company_id, context=None):
  106. if context is None:
  107. context = {}
  108. context['company_id'] = company_id
  109. res = {'value': {}}
  110. if not company_id:
  111. return res
  112. cur_id = self.pool.get('res.company').browse(
  113. cr, uid, company_id, context=context).currency_id.id
  114. fy_id = self.pool.get('account.fiscalyear').find(
  115. cr, uid, context=context)
  116. res['value'].update({'fiscalyear_id': fy_id})
  117. res['value'].update({'currency_id': cur_id})
  118. res['value'].update({'account_ids': []})
  119. res['value'].update({'period_ids': []})
  120. return res
  121. account_financial_report()