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.company,
  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. )
  23. filter_negative_balances = fields.Boolean("Exclude Negative Balances", default=True)
  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"), ("payable", "Payable")],
  32. string="Account type",
  33. default="receivable",
  34. )
  35. @api.onchange("aging_type")
  36. def onchange_aging_type(self):
  37. if self.aging_type == "months":
  38. self.date_end = fields.Date.context_today(self).replace(
  39. day=1
  40. ) - relativedelta(days=1)
  41. else:
  42. self.date_end = fields.Date.context_today(self)
  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