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.

58 lines
2.4 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. @api.onchange('date_range_id')
  18. def onchange_date_range_id(self):
  19. if self.date_range_id:
  20. self.from_date = self.date_range_id.date_start
  21. self.to_date = self.date_range_id.date_end
  22. else:
  23. self.from_date = self.to_date = None
  24. def open_taxes(self):
  25. self.ensure_one()
  26. action = self.env.ref('account_tax_balance.action_tax_balances_tree')
  27. act_vals = action.read()[0]
  28. # override action name doesn't work in v12 or v10
  29. # we need to build a dynamic action on main keys
  30. vals = {x: act_vals[x] for x in act_vals
  31. if x in ('res_model', 'view_mode', 'domain',
  32. 'view_id', 'search_view_id', 'name', 'type')}
  33. lang = self.env['res.lang'].search(
  34. [('code', '=', self.env.user.lang or 'en_US')])
  35. date_format = lang and lang.date_format or "%m/%d/%Y"
  36. infos = {'name': vals['name'], 'target': _(self.target_move),
  37. 'from': self.from_date.strftime(date_format),
  38. 'to': self.to_date.strftime(date_format),
  39. 'company': self.company_id.name}
  40. # name of action which is displayed in breacrumb
  41. vals["name"] = _(
  42. "%(name)s: %(target)s from %(from)s to %(to)s") % infos
  43. multi_cpny_grp = self.env.ref('base.group_multi_company')
  44. if multi_cpny_grp in self.env.user.groups_id:
  45. vals['name'] = '%s (%s)' % (vals['name'], self.company_id.name)
  46. vals['context'] = {
  47. 'from_date': self.from_date,
  48. 'to_date': self.to_date,
  49. 'target_move': self.target_move,
  50. 'company_id': self.company_id.id,
  51. }
  52. return vals