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.

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