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.

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