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.

99 lines
3.6 KiB

  1. # -*- coding: utf-8 -*-
  2. # Author: Damien Crier
  3. # Copyright 2016 Camptocamp SA
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  5. from openerp import models, fields, api
  6. class LedgerReportWizard(models.TransientModel):
  7. _name = "ledger.report.wizard"
  8. _description = "Ledger Report Wizard"
  9. company_id = fields.Many2one(comodel_name='res.company')
  10. date_range_id = fields.Many2one(comodel_name='date.range', required=True)
  11. date_from = fields.Date()
  12. date_to = fields.Date()
  13. target_move = fields.Selection([('posted', 'All Posted Entries'),
  14. ('all', 'All Entries')],
  15. string='Target Moves',
  16. required=True,
  17. default='posted')
  18. account_ids = fields.Many2many(
  19. comodel_name='account.account',
  20. string='Filter accounts',
  21. )
  22. amount_currency = fields.Boolean(string='With currency',
  23. default=False)
  24. centralize = fields.Boolean(string='Activate centralization',
  25. default=False)
  26. result_selection = fields.Selection(
  27. [('customer', 'Receivable Accounts'),
  28. ('supplier', 'Payable Accounts'),
  29. ('customer_supplier', 'Receivable and Payable Accounts')
  30. ],
  31. string="Partner's",
  32. default='customer')
  33. partner_ids = fields.Many2many(
  34. comodel_name='res.partner',
  35. string='Filter partners',
  36. )
  37. @api.multi
  38. def pre_print_report(self, data):
  39. data = {'form': {}}
  40. # will be used to attach the report on the main account
  41. vals = self.read(['amount_currency',
  42. 'account_ids',
  43. 'journal_ids',
  44. 'centralize',
  45. 'target_move',
  46. 'date_from',
  47. 'date_to',
  48. 'fiscalyear'])[0]
  49. data['form'].update(vals)
  50. return data
  51. @api.multi
  52. def _print_report(self, data):
  53. # we update form with display account value
  54. data = self.pre_print_report(data)
  55. Report = self.env['report'].with_context(landscape=True)
  56. return Report.get_action(
  57. self, 'account.report_generalledger_qweb',
  58. data=data)
  59. def _build_contexts(self, data):
  60. result = {}
  61. result['journal_ids'] = (
  62. 'journal_ids' in data['form'] and
  63. data['form']['journal_ids'] or False
  64. )
  65. result['state'] = (
  66. 'target_move' in data['form'] and
  67. data['form']['target_move'] or ''
  68. )
  69. result['date_from'] = data['form']['date_from'] or False
  70. result['date_to'] = data['form']['date_to'] or False
  71. result['strict_range'] = True if result['date_from'] else False
  72. return result
  73. @api.multi
  74. def check_report(self):
  75. self.ensure_one()
  76. data = {}
  77. data['ids'] = self.env.context.get('active_ids', [])
  78. data['model'] = self.env.context.get('active_model', 'ir.ui.menu')
  79. data['form'] = self.read(['date_from', 'date_to',
  80. 'journal_ids', 'target_move'])[0]
  81. used_context = self._build_contexts(data)
  82. data['form']['used_context'] = dict(
  83. used_context,
  84. lang=self.env.context.get('lang', 'en_US'))
  85. return self._print_report(data)
  86. @api.onchange('date_range_id')
  87. def onchange_date_range_id(self):
  88. self.date_from = self.date_range_id.date_start
  89. self.date_to = self.date_range_id.date_end