hr_expense_sheet.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import fields, models, _
  4. class HrExpenseSheet(models.Model):
  5. _inherit = "hr.expense.sheet"
  6. sale_order_count = fields.Integer(compute='_compute_sale_order_count')
  7. def _compute_sale_order_count(self):
  8. for sheet in self:
  9. sheet.sale_order_count = len(sheet.expense_line_ids.sale_order_id)
  10. def action_open_sale_orders(self):
  11. self.ensure_one()
  12. if self.sale_order_count == 1:
  13. return {
  14. 'type': 'ir.actions.act_window',
  15. 'res_model': 'sale.order',
  16. 'views': [(self.env.ref("sale.view_order_form").id, 'form')],
  17. 'view_mode': 'form',
  18. 'target': 'current',
  19. 'name': self.expense_line_ids.sale_order_id.display_name,
  20. 'res_id': self.expense_line_ids.sale_order_id.id,
  21. }
  22. return {
  23. 'type': 'ir.actions.act_window',
  24. 'res_model': 'sale.order',
  25. 'views': [(self.env.ref('sale.view_order_tree').id, 'list'), (self.env.ref("sale.view_order_form").id, 'form')],
  26. 'view_mode': 'list,form',
  27. 'target': 'current',
  28. 'name': _('Reinvoiced Sales Orders'),
  29. 'domain': [('id', 'in', self.expense_line_ids.sale_order_id.ids)],
  30. }