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.

216 lines
9.0 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
  1. # -*- coding: 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 openerp.osv import osv, fields
  29. import time
  30. from openerp.tools.translate import _
  31. class account_financial_report(osv.osv):
  32. _name = "afr"
  33. _columns = {
  34. 'name': fields.char('Name', size=128, required=True),
  35. 'company_id': fields.many2one('res.company', 'Company', required=True),
  36. 'currency_id': fields.many2one('res.currency', 'Currency',
  37. help="Currency at which this report \
  38. will be expressed. If not selected \
  39. will be used the one set in the \
  40. company"),
  41. 'inf_type': fields.selection([('BS', 'Balance Sheet'),
  42. ('IS', 'Income Statement')],
  43. 'Type',
  44. required=True),
  45. 'columns': fields.selection(
  46. [('one', 'End. Balance'),
  47. ('two', 'Debit | Credit'),
  48. ('four', 'Initial | Debit | Credit | YTD'),
  49. ('five', 'Initial | Debit | Credit | Period | YTD'),
  50. ('qtr', "4 QTR's | YTD"),
  51. ('thirteen', '12 Months | YTD')], 'Columns', required=True),
  52. 'display_account': fields.selection(
  53. [('all', 'All Accounts'),
  54. ('bal', 'With Balance'),
  55. ('mov', 'With movements'),
  56. ('bal_mov', 'With Balance / Movements')], 'Display accounts'),
  57. 'display_account_level': fields.integer('Up to level',
  58. help='Display accounts up to \
  59. this level (0 to show all)'),
  60. 'account_ids': fields.many2many('account.account', 'afr_account_rel',
  61. 'afr_id', 'account_id',
  62. 'Root accounts', required=True),
  63. 'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscal year',
  64. help='Fiscal Year for this report',
  65. required=True),
  66. 'period_ids': fields.many2many(
  67. 'account.period', 'afr_period_rel', 'afr_id', 'period_id',
  68. 'Periods', help='All periods in the fiscal year if empty'),
  69. 'analytic_ledger': fields.boolean(
  70. 'Analytic Ledger',
  71. help="Allows to Generate an Analytic Ledger for accounts with \
  72. moves. Available when Balance Sheet and 'Initial | Debit \
  73. | Credit | YTD' are selected"),
  74. 'journal_ledger': fields.boolean(
  75. 'journal Ledger',
  76. help="Allows to Generate an journal Ledger for accounts with \
  77. moves. Available when Balance Sheet and 'Initial | Debit | \
  78. Credit | YTD' are selected"),
  79. 'partner_balance': fields.boolean(
  80. 'Partner Balance',
  81. help="Allows to Generate a Partner Balance for accounts with \
  82. moves. Available when Balance Sheet and 'Initial | Debit | \
  83. Credit | YTD' are selected"),
  84. 'tot_check': fields.boolean(
  85. 'Summarize?',
  86. help='Checking will add a new line at the end of the Report which \
  87. will Summarize Columns in Report'),
  88. 'lab_str': fields.char('Description',
  89. help='Description for the Summary',
  90. size=128),
  91. 'target_move': fields.selection(
  92. [('posted', 'All Posted Entries'),
  93. ('all', 'All Entries'), ],
  94. 'Entries to Include', required=True,
  95. help='Print All Accounting Entries or just Posted \
  96. Accounting Entries'),
  97. # ~ Deprecated fields
  98. 'filter': fields.selection([('bydate', 'By Date'),
  99. ('byperiod', 'By Period'),
  100. ('all', 'By Date and Period'),
  101. ('none', 'No Filter')],
  102. 'Date/Period Filter'),
  103. 'date_to': fields.date('End date'),
  104. 'date_from': fields.date('Start date'),
  105. }
  106. _defaults = {
  107. 'display_account_level': lambda *a: 0,
  108. 'inf_type': lambda *a: 'BS',
  109. 'company_id': lambda self, cr, uid, c:
  110. self.pool.get(
  111. 'res.company')._company_default_get(
  112. cr,
  113. uid,
  114. 'account.invoice',
  115. context=c),
  116. 'fiscalyear_id': lambda self, cr, uid, c:
  117. self.pool.get('account.fiscalyear').find(cr, uid),
  118. 'display_account': lambda *a: 'bal_mov',
  119. 'columns': lambda *a: 'five',
  120. 'date_from': lambda *a: time.strftime('%Y-%m-%d'),
  121. 'date_to': lambda *a: time.strftime('%Y-%m-%d'),
  122. 'filter': lambda *a: 'byperiod',
  123. 'target_move': 'posted',
  124. }
  125. def copy(self, cr, uid, id, defaults, context=None):
  126. if context is None:
  127. context = {}
  128. previous_name = self.browse(cr, uid, id, context=context).name
  129. new_name = _('Copy of %s') % previous_name
  130. lst = self.search(cr, uid, [(
  131. 'name', 'like', new_name)], context=context)
  132. if lst:
  133. new_name = '%s (%s)' % (new_name, len(lst) + 1)
  134. defaults['name'] = new_name
  135. return (
  136. super(
  137. account_financial_report,
  138. self).copy(
  139. cr,
  140. uid,
  141. id,
  142. defaults,
  143. context=context)
  144. )
  145. def onchange_inf_type(self, cr, uid, ids, inf_type, context=None):
  146. if context is None:
  147. context = {}
  148. res = {'value': {}}
  149. if inf_type != 'BS':
  150. res['value'].update({'analytic_ledger': False})
  151. return res
  152. def onchange_columns(self, cr, uid, ids, columns,
  153. fiscalyear_id, period_ids, context=None):
  154. if context is None:
  155. context = {}
  156. res = {'value': {}}
  157. if columns != 'four':
  158. res['value'].update({'analytic_ledger': False})
  159. if columns in ('qtr', 'thirteen'):
  160. p_obj = self.pool.get("account.period")
  161. period_ids = p_obj.search(cr, uid,
  162. [('fiscalyear_id', '=', fiscalyear_id),
  163. ('special', '=', False)],
  164. context=context)
  165. res['value'].update({'period_ids': period_ids})
  166. else:
  167. res['value'].update({'period_ids': []})
  168. return res
  169. def onchange_analytic_ledger(
  170. self, cr, uid, ids, company_id, analytic_ledger, context=None):
  171. if context is None:
  172. context = {}
  173. context['company_id'] = company_id
  174. res = {'value': {}}
  175. cur_id = self.pool.get('res.company').browse(
  176. cr, uid, company_id, context=context).currency_id.id
  177. res['value'].update({'currency_id': cur_id})
  178. return res
  179. def onchange_company_id(self, cr, uid, ids, company_id, context=None):
  180. if context is None:
  181. context = {}
  182. context['company_id'] = company_id
  183. res = {'value': {}}
  184. if not company_id:
  185. return res
  186. cur_id = self.pool.get('res.company').browse(
  187. cr, uid, company_id, context=context).currency_id.id
  188. fy_id = self.pool.get('account.fiscalyear').find(
  189. cr, uid, context=context)
  190. res['value'].update({'fiscalyear_id': fy_id})
  191. res['value'].update({'currency_id': cur_id})
  192. res['value'].update({'account_ids': []})
  193. res['value'].update({'period_ids': []})
  194. return res
  195. account_financial_report()