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.

71 lines
2.3 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. name = fields.Char()
  9. company_id = fields.Many2one(
  10. comodel_name='res.company',
  11. default=lambda self: self.env.user.company_id,
  12. string='Company',
  13. required=True,
  14. )
  15. date_end = fields.Date(required=True, default=fields.Date.context_today)
  16. show_aging_buckets = fields.Boolean(default=True)
  17. number_partner_ids = fields.Integer(
  18. default=lambda self: len(self._context['active_ids'])
  19. )
  20. filter_partners_non_due = fields.Boolean(
  21. string="Don't show partners with no due entries", default=True)
  22. filter_negative_balances = fields.Boolean(
  23. "Exclude Negative Balances", default=True
  24. )
  25. aging_type = fields.Selection(
  26. [("days", "Age by Days"), ("months", "Age by Months")],
  27. string="Aging Method",
  28. default="days",
  29. required=True,
  30. )
  31. account_type = fields.Selection(
  32. [('receivable', 'Receivable'),
  33. ('payable', 'Payable')], string='Account type', default='receivable')
  34. @api.onchange('aging_type')
  35. def onchange_aging_type(self):
  36. if self.aging_type == 'months':
  37. self.date_end = (
  38. fields.Date.context_today(self).replace(day=1) -
  39. relativedelta(days=1)
  40. )
  41. else:
  42. self.date_end = fields.Date.context_today(self)
  43. @api.multi
  44. def button_export_pdf(self):
  45. self.ensure_one()
  46. return self._export()
  47. def _prepare_statement(self):
  48. self.ensure_one()
  49. return {
  50. 'date_end': self.date_end,
  51. 'company_id': self.company_id.id,
  52. 'partner_ids': self._context['active_ids'],
  53. 'show_aging_buckets': self.show_aging_buckets,
  54. 'filter_non_due_partners': self.filter_partners_non_due,
  55. 'account_type': self.account_type,
  56. 'aging_type': self.aging_type,
  57. 'filter_negative_balances': self.filter_negative_balances,
  58. }
  59. def _export(self):
  60. raise NotImplementedError