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.

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