From 800960376926df8325c8ac2e07cbeaf1d513640e Mon Sep 17 00:00:00 2001 From: Vincent Renaville Date: Wed, 30 Oct 2013 17:01:10 +0100 Subject: [PATCH] [IMP] add departmeent on hours block and add hours block button on project form view --- analytic_hours_block/__init__.py | 1 + analytic_hours_block/__openerp__.py | 4 ++- analytic_hours_block/hours_block.py | 8 ++++++ analytic_hours_block/hours_block_menu.xml | 1 + analytic_hours_block/hours_block_view.xml | 5 ++++ analytic_hours_block/project.py | 33 +++++++++++++++++++++++ analytic_hours_block/project_view.xml | 19 +++++++++++++ 7 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 analytic_hours_block/project.py create mode 100644 analytic_hours_block/project_view.xml diff --git a/analytic_hours_block/__init__.py b/analytic_hours_block/__init__.py index 93f4db71..5a0df9a6 100644 --- a/analytic_hours_block/__init__.py +++ b/analytic_hours_block/__init__.py @@ -20,3 +20,4 @@ ############################################################################## import hours_block import report +import project \ No newline at end of file diff --git a/analytic_hours_block/__openerp__.py b/analytic_hours_block/__openerp__.py index 09c78ad7..5cd3c4a2 100644 --- a/analytic_hours_block/__openerp__.py +++ b/analytic_hours_block/__openerp__.py @@ -40,11 +40,13 @@ you can track and follow how much has been used. "depends": [ "account", "hr_timesheet_invoice", - "analytic" + "analytic", + "project", ], "data": [ "hours_block_view.xml", "hours_block_menu.xml", + "project_view.xml", "report.xml", "security/hours_block_security.xml", "security/ir.model.access.csv", diff --git a/analytic_hours_block/hours_block.py b/analytic_hours_block/hours_block.py index b341702a..bc879d17 100644 --- a/analytic_hours_block/hours_block.py +++ b/analytic_hours_block/hours_block.py @@ -294,6 +294,14 @@ class AccountHoursBlock(orm.Model): string="Total", store=True, readonly=True), + 'department_id': fields.related( + 'invoice_id', 'department_id', + type='many2one', + relation='hr.department', + string='Department', + store=True, + readonly=True), + 'state': fields.related( 'invoice_id', 'state', type='selection', diff --git a/analytic_hours_block/hours_block_menu.xml b/analytic_hours_block/hours_block_menu.xml index c4969041..7b32b14b 100644 --- a/analytic_hours_block/hours_block_menu.xml +++ b/analytic_hours_block/hours_block_menu.xml @@ -6,6 +6,7 @@ Hours block menu --> + {'search_default_running': 1, 'search_default_group_department_id': 1} Hours Blocks account.hours.block form diff --git a/analytic_hours_block/hours_block_view.xml b/analytic_hours_block/hours_block_view.xml index a81bc136..33c3d084 100644 --- a/analytic_hours_block/hours_block_view.xml +++ b/analytic_hours_block/hours_block_view.xml @@ -18,15 +18,18 @@ + + + @@ -68,6 +71,7 @@ + @@ -101,6 +105,7 @@ + diff --git a/analytic_hours_block/project.py b/analytic_hours_block/project.py new file mode 100644 index 00000000..8c014ca5 --- /dev/null +++ b/analytic_hours_block/project.py @@ -0,0 +1,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, + } diff --git a/analytic_hours_block/project_view.xml b/analytic_hours_block/project_view.xml new file mode 100644 index 00000000..0b503a84 --- /dev/null +++ b/analytic_hours_block/project_view.xml @@ -0,0 +1,19 @@ + + + + + + project.project.form.hours.block.link + project.project + + form + + +