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.

33 lines
1.2 KiB

  1. # -*- coding: utf-8 -*-
  2. from osv import orm
  3. from openerp.tools.translate import _
  4. class project_project(orm.Model):
  5. _inherit = 'project.project'
  6. def hours_block_tree_view(self, cr, uid, ids, context):
  7. invoice_line_obj = self.pool.get('account.invoice.line')
  8. hours_block_obj = self.pool.get('account.hours.block')
  9. project = self.browse(cr, uid , ids)[0]
  10. invoice_line_ids = invoice_line_obj.search(cr, uid, [('account_analytic_id', '=', project.analytic_account_id.id)])
  11. invoice_lines = invoice_line_obj.browse(cr, uid, invoice_line_ids)
  12. invoice_ids = [x.invoice_id.id for x in invoice_lines]
  13. res_ids = hours_block_obj.search(cr, uid, [('invoice_id','in',invoice_ids)])
  14. domain=False
  15. if res_ids:
  16. domain = [('id', 'in', res_ids)]
  17. else:
  18. raise orm.except_orm(_('Warning'), _("No Hours Block for this project"))
  19. return {
  20. 'name': _('Hours Blocks'),
  21. 'domain': domain,
  22. 'res_model': 'account.hours.block',
  23. 'type': 'ir.actions.act_window',
  24. 'view_id': False,
  25. 'view_mode': 'tree,form',
  26. 'view_type': 'form',
  27. 'limit': 80,
  28. 'res_id' : res_ids or False,
  29. }