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.

78 lines
2.5 KiB

  1. # Copyright 2018 Graeme Gellatly
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from dateutil.relativedelta import relativedelta
  4. from odoo import api, fields, models
  5. class StatementCommon(models.AbstractModel):
  6. _name = 'statement.common.wizard'
  7. _description = 'Statement Reports Common Wizard'
  8. def _get_company(self):
  9. return (
  10. self.env['res.company'].browse(
  11. self.env.context.get('force_company')) or
  12. self.env.user.company_id
  13. )
  14. name = fields.Char()
  15. company_id = fields.Many2one(
  16. comodel_name='res.company',
  17. default=_get_company,
  18. string='Company',
  19. required=True,
  20. )
  21. date_end = fields.Date(required=True, default=fields.Date.context_today)
  22. show_aging_buckets = fields.Boolean(default=True)
  23. number_partner_ids = fields.Integer(
  24. default=lambda self: len(self._context['active_ids'])
  25. )
  26. filter_partners_non_due = fields.Boolean(
  27. string="Don't show partners with no due entries", default=True)
  28. filter_negative_balances = fields.Boolean(
  29. "Exclude Negative Balances", default=True
  30. )
  31. aging_type = fields.Selection(
  32. [("days", "Age by Days"), ("months", "Age by Months")],
  33. string="Aging Method",
  34. default="days",
  35. required=True,
  36. )
  37. account_type = fields.Selection(
  38. [('receivable', 'Receivable'),
  39. ('payable', 'Payable')], string='Account type', default='receivable')
  40. @api.onchange('aging_type')
  41. def onchange_aging_type(self):
  42. if self.aging_type == 'months':
  43. self.date_end = (
  44. fields.Date.context_today(self).replace(day=1) -
  45. relativedelta(days=1)
  46. )
  47. else:
  48. self.date_end = fields.Date.context_today(self)
  49. @api.multi
  50. def button_export_pdf(self):
  51. self.ensure_one()
  52. return self._export()
  53. def _prepare_statement(self):
  54. self.ensure_one()
  55. return {
  56. 'date_end': self.date_end,
  57. 'company_id': self.company_id.id,
  58. 'partner_ids': self._context['active_ids'],
  59. 'show_aging_buckets': self.show_aging_buckets,
  60. 'filter_non_due_partners': self.filter_partners_non_due,
  61. 'account_type': self.account_type,
  62. 'aging_type': self.aging_type,
  63. 'filter_negative_balances': self.filter_negative_balances,
  64. }
  65. def _export(self):
  66. raise NotImplementedError