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.

64 lines
2.6 KiB

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