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.

124 lines
4.8 KiB

  1. # Author: Damien Crier, Andrea Stirpe, Kevin Graveman, Dennis Sluijk
  2. # Author: Julien Coux
  3. # Copyright 2016 Camptocamp SA, Onestein B.V.
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  5. from odoo import api, fields, models
  6. class AgedPartnerBalanceWizard(models.TransientModel):
  7. """Aged partner balance report wizard."""
  8. _name = 'aged.partner.balance.report.wizard'
  9. _description = 'Aged Partner Balance Wizard'
  10. _inherit = 'account_financial_report_abstract_wizard'
  11. company_id = fields.Many2one(
  12. comodel_name='res.company',
  13. default=lambda self: self.env.user.company_id,
  14. required=False,
  15. string='Company'
  16. )
  17. date_at = fields.Date(required=True,
  18. default=fields.Date.context_today)
  19. target_move = fields.Selection([('posted', 'All Posted Entries'),
  20. ('all', 'All Entries')],
  21. string='Target Moves',
  22. required=True,
  23. default='all')
  24. account_ids = fields.Many2many(
  25. comodel_name='account.account',
  26. string='Filter accounts',
  27. )
  28. receivable_accounts_only = fields.Boolean()
  29. payable_accounts_only = fields.Boolean()
  30. partner_ids = fields.Many2many(
  31. comodel_name='res.partner',
  32. string='Filter partners',
  33. )
  34. show_move_line_details = fields.Boolean()
  35. @api.onchange('company_id')
  36. def onchange_company_id(self):
  37. """Handle company change."""
  38. if self.company_id and self.partner_ids:
  39. self.partner_ids = self.partner_ids.filtered(
  40. lambda p: p.company_id == self.company_id or
  41. not p.company_id)
  42. if self.company_id and self.account_ids:
  43. if self.receivable_accounts_only or self.payable_accounts_only:
  44. self.onchange_type_accounts_only()
  45. else:
  46. self.account_ids = self.account_ids.filtered(
  47. lambda a: a.company_id == self.company_id)
  48. res = {'domain': {'account_ids': [],
  49. 'partner_ids': []}}
  50. if not self.company_id:
  51. return res
  52. else:
  53. res['domain']['account_ids'] += [
  54. ('company_id', '=', self.company_id.id)]
  55. res['domain']['partner_ids'] += self._get_partner_ids_domain()
  56. return res
  57. @api.onchange('receivable_accounts_only', 'payable_accounts_only')
  58. def onchange_type_accounts_only(self):
  59. """Handle receivable/payable accounts only change."""
  60. domain = [('company_id', '=', self.company_id.id)]
  61. if self.receivable_accounts_only or self.payable_accounts_only:
  62. if self.receivable_accounts_only and self.payable_accounts_only:
  63. domain += [('internal_type', 'in', ('receivable', 'payable'))]
  64. elif self.receivable_accounts_only:
  65. domain += [('internal_type', '=', 'receivable')]
  66. elif self.payable_accounts_only:
  67. domain += [('internal_type', '=', 'payable')]
  68. elif not self.receivable_accounts_only and not self.payable_accounts_only:
  69. domain += [('reconcile', '=', True)]
  70. self.account_ids = self.env['account.account'].search(domain)
  71. @api.multi
  72. def _print_report(self, report_type):
  73. self.ensure_one()
  74. data = self._prepare_report_aged_partner_balance()
  75. if report_type == 'xlsx':
  76. report_name = 'a_f_r.report_aged_partner_balance_xlsx'
  77. else:
  78. report_name = 'account_financial_report.aged_partner_balance'
  79. return self.env['ir.actions.report'].search(
  80. [('report_name', '=', report_name),
  81. ('report_type', '=', report_type)], limit=1).report_action(
  82. self, data=data)
  83. @api.multi
  84. def button_export_html(self):
  85. self.ensure_one()
  86. report_type = 'qweb-html'
  87. return self._export(report_type)
  88. @api.multi
  89. def button_export_pdf(self):
  90. self.ensure_one()
  91. report_type = 'qweb-pdf'
  92. return self._export(report_type)
  93. @api.multi
  94. def button_export_xlsx(self):
  95. self.ensure_one()
  96. report_type = 'xlsx'
  97. return self._export(report_type)
  98. def _prepare_report_aged_partner_balance(self):
  99. self.ensure_one()
  100. return {
  101. 'wizard_id': self.id,
  102. 'date_at': self.date_at,
  103. 'only_posted_moves': self.target_move == 'posted',
  104. 'company_id': self.company_id.id,
  105. 'account_ids': self.account_ids.ids,
  106. 'partner_ids': self.partner_ids.ids,
  107. 'show_move_line_details': self.show_move_line_details,
  108. }
  109. def _export(self, report_type):
  110. """Default export is PDF."""
  111. return self._print_report(report_type)