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.

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