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.

83 lines
2.9 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_ids = fields.Many2many(
  8. comodel_name="res.company",
  9. string="Companies",
  10. required=True,
  11. domain=lambda self: [("id", "in", self.env.companies.ids)],
  12. default=lambda self: self.env.companies.ids,
  13. )
  14. from_date = fields.Date(
  15. required=True, store=True, readonly=False, compute="_compute_date_range"
  16. )
  17. to_date = fields.Date(
  18. required=True, store=True, readonly=False, compute="_compute_date_range"
  19. )
  20. date_range_id = fields.Many2one("date.range")
  21. target_move = fields.Selection(
  22. [("posted", "All Posted Entries"), ("all", "All Entries")],
  23. "Target Moves",
  24. required=True,
  25. default="posted",
  26. )
  27. @api.depends("date_range_id")
  28. def _compute_date_range(self):
  29. for wizard in self:
  30. if wizard.date_range_id:
  31. wizard.from_date = wizard.date_range_id.date_start
  32. wizard.to_date = wizard.date_range_id.date_end
  33. else:
  34. wizard.from_date = wizard.to_date = None
  35. def open_taxes(self):
  36. self.ensure_one()
  37. action = self.env.ref("account_tax_balance.action_tax_balances_tree")
  38. act_vals = action.read()[0]
  39. # override action name doesn't work in v12 or v10
  40. # we need to build a dynamic action on main keys
  41. vals = {
  42. x: act_vals[x]
  43. for x in act_vals
  44. if x
  45. in (
  46. "res_model",
  47. "view_mode",
  48. "domain",
  49. "view_id",
  50. "search_view_id",
  51. "name",
  52. "type",
  53. )
  54. }
  55. lang = self.env["res.lang"].search(
  56. [("code", "=", self.env.user.lang or "en_US")]
  57. )
  58. date_format = lang and lang.date_format or "%m/%d/%Y"
  59. infos = {
  60. "name": vals["name"],
  61. "target": _(self.target_move),
  62. "from": self.from_date.strftime(date_format),
  63. "to": self.to_date.strftime(date_format),
  64. }
  65. # name of action which is displayed in breacrumb
  66. vals["name"] = _("%(name)s: %(target)s from %(from)s to %(to)s") % infos
  67. multi_cpny_grp = self.env.ref("base.group_multi_company")
  68. if multi_cpny_grp in self.env.user.groups_id:
  69. company_names = self.company_ids.mapped("name")
  70. vals["name"] = "{} ({})".format(vals["name"], ", ".join(company_names))
  71. vals["context"] = {
  72. "from_date": self.from_date,
  73. "to_date": self.to_date,
  74. "target_move": self.target_move,
  75. "company_ids": self.company_ids.ids,
  76. }
  77. return vals