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.

79 lines
2.8 KiB

5 years ago
  1. # Copyright 2016 Lorenzo Battistini - Agile Business Group
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo import _, api, fields, models
  4. class WizardOpenTaxBalances(models.TransientModel):
  5. _name = "wizard.open.tax.balances"
  6. _description = "Wizard Open Tax Balances"
  7. company_id = fields.Many2one(
  8. "res.company", required=True, default=lambda self: self.env.user.company_id
  9. )
  10. from_date = fields.Date(
  11. required=True, store=True, readonly=False, compute="_compute_date_range"
  12. )
  13. to_date = fields.Date(
  14. required=True, store=True, readonly=False, compute="_compute_date_range"
  15. )
  16. date_range_id = fields.Many2one("date.range")
  17. target_move = fields.Selection(
  18. [("posted", "All Posted Entries"), ("all", "All Entries")],
  19. "Target Moves",
  20. required=True,
  21. default="posted",
  22. )
  23. @api.depends("date_range_id")
  24. def _compute_date_range(self):
  25. for wizard in self:
  26. if wizard.date_range_id:
  27. wizard.from_date = wizard.date_range_id.date_start
  28. wizard.to_date = wizard.date_range_id.date_end
  29. else:
  30. wizard.from_date = wizard.to_date = None
  31. def open_taxes(self):
  32. self.ensure_one()
  33. action = self.env.ref("account_tax_balance.action_tax_balances_tree")
  34. act_vals = action.read()[0]
  35. # override action name doesn't work in v12 or v10
  36. # we need to build a dynamic action on main keys
  37. vals = {
  38. x: act_vals[x]
  39. for x in act_vals
  40. if x
  41. in (
  42. "res_model",
  43. "view_mode",
  44. "domain",
  45. "view_id",
  46. "search_view_id",
  47. "name",
  48. "type",
  49. )
  50. }
  51. lang = self.env["res.lang"].search(
  52. [("code", "=", self.env.user.lang or "en_US")]
  53. )
  54. date_format = lang and lang.date_format or "%m/%d/%Y"
  55. infos = {
  56. "name": vals["name"],
  57. "target": _(self.target_move),
  58. "from": self.from_date.strftime(date_format),
  59. "to": self.to_date.strftime(date_format),
  60. "company": self.company_id.name,
  61. }
  62. # name of action which is displayed in breacrumb
  63. vals["name"] = _("%(name)s: %(target)s from %(from)s to %(to)s") % infos
  64. multi_cpny_grp = self.env.ref("base.group_multi_company")
  65. if multi_cpny_grp in self.env.user.groups_id:
  66. vals["name"] = "{} ({})".format(vals["name"], self.company_id.name)
  67. vals["context"] = {
  68. "from_date": self.from_date,
  69. "to_date": self.to_date,
  70. "target_move": self.target_move,
  71. "company_id": self.company_id.id,
  72. }
  73. return vals