diff --git a/analytic_hours_block/__init__.py b/analytic_hours_block/__init__.py index 42354634..81ba8d05 100644 --- a/analytic_hours_block/__init__.py +++ b/analytic_hours_block/__init__.py @@ -21,3 +21,4 @@ import hours_block import report import product +import project diff --git a/analytic_hours_block/__openerp__.py b/analytic_hours_block/__openerp__.py index c107ef9c..6dc08a38 100644 --- a/analytic_hours_block/__openerp__.py +++ b/analytic_hours_block/__openerp__.py @@ -21,7 +21,7 @@ { "name": "Project Hours Blocks Management", - "version": "1.4", + "version": "1.5", "category": "Generic Modules/Projects & Services", "description": """ Project Hours Blocks Management @@ -40,7 +40,8 @@ you can track and follow how much has been used. "depends": [ "account", "hr_timesheet_invoice", - "analytic" + "analytic", + "project", ], "data": [ "report.xml", @@ -48,6 +49,7 @@ you can track and follow how much has been used. "hours_block_data.xml", "hours_block_menu.xml", "product_view.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 3ce24384..e29c5a6b 100644 --- a/analytic_hours_block/hours_block.py +++ b/analytic_hours_block/hours_block.py @@ -267,74 +267,130 @@ class AccountHoursBlock(orm.Model): 'invoice_id', 'date_invoice', type="date", string="Invoice Date", - store=True, + store={ + 'account.hours.block': (lambda self, cr, uid, ids, c=None: ids, + ['invoice_id'], 10), + 'account.invoice': (_get_invoice, ['date_invoice'], 10), + }, readonly=True), 'user_id': fields.related( 'invoice_id', 'user_id', type="many2one", relation="res.users", string="Salesman", - store=True, + store={ + 'account.hours.block': (lambda self, cr, uid, ids, c=None: ids, + ['invoice_id'], 10), + 'account.invoice': (_get_invoice, ['user_id'], 10), + }, readonly=True), 'partner_id': fields.related( 'invoice_id', 'partner_id', type="many2one", relation="res.partner", string="Partner", - store=True, + store={ + 'account.hours.block': (lambda self, cr, uid, ids, c=None: ids, + ['invoice_id'], 10), + 'account.invoice': (_get_invoice, ['partner_id'], 10), + }, readonly=True), 'name': fields.related( 'invoice_id', 'name', type="char", string="Description", - store=True, + store={ + 'account.hours.block': (lambda self, cr, uid, ids, c=None: ids, + ['invoice_id'], 10), + 'account.invoice': (_get_invoice, ['name'], 10), + }, readonly=True), 'number': fields.related( 'invoice_id', 'number', type="char", string="Number", - store=True, + store={ + 'account.hours.block': (lambda self, cr, uid, ids, c=None: ids, + ['invoice_id'], 10), + 'account.invoice': (_get_invoice, ['number'], 10), + }, readonly=True), 'journal_id': fields.related( 'invoice_id', 'journal_id', type="many2one", relation="account.journal", string="Journal", - store=True, + store={ + 'account.hours.block': (lambda self, cr, uid, ids, c=None: ids, + ['invoice_id'], 10), + 'account.invoice': (_get_invoice, ['journal_id'], 10), + }, readonly=True), 'period_id': fields.related( 'invoice_id', 'period_id', type="many2one", relation="account.period", string="Period", - store=True, + store={ + 'account.hours.block': (lambda self, cr, uid, ids, c=None: ids, + ['invoice_id'], 10), + 'account.invoice': (_get_invoice, ['period_id'], 10), + }, readonly=True), 'company_id': fields.related( 'invoice_id', 'company_id', type="many2one", relation="res.company", string="Company", - store=True, + store={ + 'account.hours.block': (lambda self, cr, uid, ids, c=None: ids, + ['invoice_id'], 10), + 'account.invoice': (_get_invoice, ['company_id'], 10), + }, readonly=True), 'currency_id': fields.related( 'invoice_id', 'currency_id', type="many2one", relation="res.currency", string="Currency", - store=True, + store={ + 'account.hours.block': (lambda self, cr, uid, ids, c=None: ids, + ['invoice_id'], 10), + 'account.invoice': (_get_invoice, ['currency_id'], 10), + }, readonly=True), 'residual': fields.related( 'invoice_id', 'residual', type="float", string="Residual", - store=True, + store={ + 'account.hours.block': (lambda self, cr, uid, ids, c=None: ids, + ['invoice_id'], 10), + 'account.invoice': (_get_invoice, ['residual'], 10), + }, readonly=True), 'amount_total': fields.related( 'invoice_id', 'amount_total', type="float", string="Total", - store=True, + store={ + 'account.hours.block': (lambda self, cr, uid, ids, c=None: ids, + ['invoice_id'], 10), + 'account.invoice': (_get_invoice, ['amount_total'], 10), + }, readonly=True), + 'department_id': fields.related( + 'invoice_id', 'department_id', + type='many2one', + relation='hr.department', + string='Department', + store={ + 'account.hours.block': (lambda self, cr, uid, ids, c=None: ids, + ['invoice_id'], 10), + 'account.invoice': (_get_invoice, ['department_id'], 10), + }, + readonly=True), + 'state': fields.related( 'invoice_id', 'state', type='selection', @@ -348,7 +404,11 @@ class AccountHoursBlock(orm.Model): ], string='State', readonly=True, - store=True), + store={ + 'account.hours.block': (lambda self, cr, uid, ids, c=None: ids, + ['invoice_id'], 10), + 'account.invoice': (_get_invoice, ['state'], 10), + }), } 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 3c6da3a5..118f914e 100644 --- a/analytic_hours_block/hours_block_view.xml +++ b/analytic_hours_block/hours_block_view.xml @@ -18,15 +18,18 @@ + + + @@ -71,6 +74,7 @@ + @@ -108,6 +112,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 + + +