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.

90 lines
3.5 KiB

10 years ago
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Author: Nicolas Bessi
  5. # Copyright 2014 Camptocamp SA
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. from datetime import date
  22. from openerp.osv import orm, fields
  23. from openerp.tools import DEFAULT_SERVER_DATE_FORMAT as DATE_FORMAT
  24. class AccountAgedTrialBalance(orm.TransientModel):
  25. """Will launch age partner balance report.
  26. This report is based on Open Invoice Report
  27. and share a lot of knowledge with him
  28. """
  29. _inherit = "open.invoices.webkit"
  30. _name = "account.aged.trial.balance.webkit"
  31. _description = "Aged partner balanced"
  32. def _get_current_fiscalyear(self, cr, uid, context=None):
  33. user_obj = self.pool['res.users']
  34. company = user_obj.browse(cr, uid, uid, context=context).company_id
  35. fyear_obj = self.pool['account.period']
  36. today = date.today().strftime(DATE_FORMAT)
  37. fyear_ids = fyear_obj.search(
  38. cr, uid,
  39. [('date_start', '>=', today),
  40. ('date_stop', '<=', today),
  41. ('company_id', '=', company.id)],
  42. limit=1,
  43. context=context)
  44. if fyear_ids:
  45. return fyear_ids[0]
  46. _columns = {
  47. 'filter': fields.selection(
  48. [('filter_period', 'Periods')],
  49. "Filter by",
  50. required=True),
  51. 'fiscalyear_id': fields.many2one(
  52. 'account.fiscalyear',
  53. 'Fiscal Year',
  54. required=True),
  55. 'period_to': fields.many2one('account.period', 'End Period',
  56. required=True),
  57. }
  58. _defaults = {
  59. 'filter': 'filter_period',
  60. 'fiscalyear_id': _get_current_fiscalyear,
  61. }
  62. def onchange_fiscalyear(self, cr, uid, ids, fiscalyear=False,
  63. period_id=False, date_to=False, until_date=False,
  64. context=None):
  65. res = super(AccountAgedTrialBalance, self).onchange_fiscalyear(
  66. cr, uid, ids, fiscalyear=fiscalyear, period_id=period_id,
  67. date_to=date_to, until_date=until_date, context=context
  68. )
  69. filters = self.onchange_filter(cr, uid, ids, filter='filter_period',
  70. fiscalyear_id=fiscalyear,
  71. context=context)
  72. res['value'].update({
  73. 'period_from': filters['value']['period_from'],
  74. 'period_to': filters['value']['period_to'],
  75. })
  76. return res
  77. def _print_report(self, cr, uid, ids, data, context=None):
  78. # we update form with display account value
  79. data = self.pre_print_report(cr, uid, ids, data, context=context)
  80. return {'type': 'ir.actions.report.xml',
  81. 'report_name': 'account.account_aged_trial_balance_webkit',
  82. 'datas': data}