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