From b000d6cfaa1d90425a88641057eb07772f268e2f Mon Sep 17 00:00:00 2001 From: "rpa (Open ERP)" Date: Thu, 22 Oct 2009 18:12:16 +0530 Subject: [PATCH 1/2] [IMP]: Improvement in planning, changes in report according to new development, added planning reference in analytic account, Improvement in views, added constraint so planning cant overlap for a same responsible bzr revid: rpa@tinyerp.com-20091022124216-zbhkxqsjrzqvjw7w --- .../report/report_planning.rml | 260 +++++++++--------- .../report_analytic_planning.py | 60 +++- .../report_analytic_planning_view.xml | 98 ++++++- 3 files changed, 275 insertions(+), 143 deletions(-) diff --git a/addons/report_analytic_planning/report/report_planning.rml b/addons/report_analytic_planning/report/report_planning.rml index 829d8b689b6..976af76e9d6 100644 --- a/addons/report_analytic_planning/report/report_planning.rml +++ b/addons/report_analytic_planning/report/report_planning.rml @@ -12,209 +12,215 @@ - - - - - - - - - - - - - - - - - - + + + + - - - + + + - - - - - - + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + + + - [[ repeatIn(objects, 'o') ]] + [[ repeatIn(objects, 'o') ]] + + + + + + + HR Planning + + + - [[ company.name ]] + Responsible: [[ o.user_id.name ]] - HR Planning + [[ o.name]] - - - + From: [[ o.date_from ]] + To: [[ o.date_to ]] + + + + + + + + + + + + + Summary by user + + + + + + + + + + User + + + Total Planned Tasks + + + Remaining tasks + + + Time without + tasks + + + Timesheet - Responsible: [[ o.user_id.name ]] + [[ repeatIn(o.planning_user_ids , 'u') ]] [[ u.user_id.name ]] - [[ o.name]] + [[ formatLang(u.plan_tasks) ]] - From: [[ o.date_from ]] - To: [[ o.date_to ]] + [[ formatLang(u.tasks) ]] + + + [[ formatLang(u.free) ]] + + + [[ formatLang(u.timesheet) ]] - - - - Summary by project - - - - - - - Project - - - Quantities - - - - - [[ repeatIn(o.stat_account_ids , 'p') ]] [ [[ p.account_id.code ]] ] [[ p.account_id.complete_name ]] - - - [[ p.quantity ]] - - - - - - - - - - Summary by user - - - - - - - User - - - Quantities - - - - - [[ repeatIn(o.stat_user_ids, 'u') ]] [[ u.user_id.name ]] - - - [[ u.quantity ]] - - - - - - - Details of user's time by projects + Summary by project + + + - + - User + Project - Project + Total Planned Tasks - Planned + Remaining tasks - Tasks + Time without + tasks - Real + Timesheet - [[ repeatIn(o.stat_ids, 'l') ]] [[ l.user_id.name ]] + [[ repeatIn(o.planning_account , 'l') ]] [ [[ l.account_id.code ]] ] [[ l.account_id.name ]] - [ [[ l.account_id.code ]] ] [[ l.account_id.name ]] + [[ formatLang(l.plan_tasks) ]] - [[ l.sum_amount ]] + [[ formatLang(l.tasks) ]] - [[ l.sum_amount_tasks ]] + [[ formatLang(l.plan_open) ]] - [[ l.sum_amount_real ]] + [[ formatLang(l.timesheet) ]] - + - diff --git a/addons/report_analytic_planning/report_analytic_planning.py b/addons/report_analytic_planning/report_analytic_planning.py index f265442a1c5..b150fb32f99 100644 --- a/addons/report_analytic_planning/report_analytic_planning.py +++ b/addons/report_analytic_planning/report_analytic_planning.py @@ -1,8 +1,9 @@ # -*- coding: utf-8 -*- ############################################################################## # -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2009 Tiny SPRL (). +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2009 Tiny SPRL (). All Rights Reserved +# $Id$ # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -64,23 +65,33 @@ class report_account_analytic_planning(osv.osv): total_free = total_free + p.free result[plan.id] = total_free return result - + + def _check_planning_responsible(self, cr, uid, ids, context={}): + for obj_plan in self.browse(cr,uid,ids): + cr.execute(""" + SELECT id FROM report_account_analytic_planning plan + WHERE ( user_id = %(uid)s + AND id <> %(id)s )""" % ({"uid": obj_plan.user_id.id,"id" : obj_plan.id})) + res = cr.fetchone() + if res: + return False + return True + _columns = { - 'name': fields.char('Planning Name', size=32, required=True, readonly=True, states={'draft':[('readonly', False)]}), - 'user_id': fields.many2one('res.users', 'Responsible', required=True, readonly=True, states={'draft':[('readonly', False)]}), - 'date_from':fields.date('Start Date', required=True, readonly=True, states={'draft':[('readonly', False)]}), - 'date_to':fields.date('End Date', required=True, readonly=True, states={'draft':[('readonly', False)]}), - 'line_ids': fields.one2many('report_account_analytic.planning.line', 'planning_id', 'Planning lines', readonly=True, states={'draft':[('readonly', False)]}), + 'name': fields.char('Planning Name', size=32, states={'done':[('readonly', True)]}), + 'user_id': fields.many2one('res.users', 'Responsible', required=True, states={'done':[('readonly', True)]}), + 'date_from':fields.date('Start Date', required=True, states={'done':[('readonly', True)]}), + 'date_to':fields.date('End Date', required=True, states={'done':[('readonly', True)]}), + 'line_ids': fields.one2many('report_account_analytic.planning.line', 'planning_id', 'Planning lines', states={'done':[('readonly', True)]}), 'stat_ids': fields.one2many('report_account_analytic.planning.stat', 'planning_id', 'Planning analysis', readonly=True), 'state': fields.selection([('draft','Draft'),('open', 'Open'), ('done', 'Done'),('cancel','Cancelled')], 'Status', required=True), - 'business_days' : fields.integer('Business Days', required=True, readonly=True, states={'draft':[('readonly', False)]}, help='Set here the number of working days within this planning for one person full time'), + 'business_days' : fields.integer('Business Days', required=True, states={'done':[('readonly', True)]}, help='Set here the number of working days within this planning for one person full time'), 'planning_user_ids': one2many_mod3('report_account_analytic.planning.user', 'planning_id', 'Planning By User'), 'planning_account': fields.one2many('report_account_analytic.planning.account', 'planning_id', 'Planning By Account'), 'total_planned' : fields.function(_get_total_planned, method=True, string='Total Planned'), 'total_free' : fields.function(_get_total_free, method=True, string='Total Free'), } _defaults = { - 'name': lambda *a: time.strftime('%B-%y'), 'date_from': lambda *a: time.strftime('%Y-%m-01'), 'date_to': lambda *a: (mx.DateTime.now()+mx.DateTime.RelativeDateTime(months=1, day=1, days=-1)).strftime('%Y-%m-%d'), 'user_id': lambda self, cr, uid, c: uid, @@ -89,6 +100,10 @@ class report_account_analytic_planning(osv.osv): } _order = 'date_from desc' + _constraints = [ + (_check_planning_responsible, 'Invalid planning ! Planning can\'t overlap for the same responsible. ', ['user_id']) + ] + def action_open(self, cr, uid, id, context={}): self.write(cr, uid, id, {'state' : 'open'}) return True @@ -104,7 +119,7 @@ class report_account_analytic_planning(osv.osv): def action_done(self, cr, uid, id, context={}): self.write(cr, uid, id, {'state' : 'done'}) return True - + report_account_analytic_planning() class report_account_analytic_planning_line(osv.osv): @@ -141,15 +156,36 @@ class report_account_analytic_planning_line(osv.osv): 'task_ids': fields.one2many('project.task', 'planning_line_id', 'Planning Tasks'), } _order = 'user_id,account_id' + report_account_analytic_planning_line() - +class account_analytic_account(osv.osv): + _name = 'account.analytic.account' + _inherit = 'account.analytic.account' + _description = 'Analytic Accounts' + _columns = { + 'planning_ids': fields.one2many('report_account_analytic.planning.line', 'account_id', 'Plannings'), + } + +account_analytic_account() + class project_task(osv.osv): _name = "project.task" _inherit = "project.task" _columns = { 'planning_line_id': fields.many2one('report_account_analytic.planning.line', 'Planning', ondelete='cascade'), } + + def search(self, cr, user, args, offset=0, limit=None, order=None, context=None, count=False): + if not context.get('planning'): + return super(project_task,self).search(cr, user, args, offset, limit, order, context) + cr.execute(" SELECT t.id, t.name \ + from project_task t \ + join report_account_analytic_planning_line l on (l.id = t.planning_line_id )\ + where l.planning_id=%s" % context.get('planning')) + ids = map(lambda x: x[0], cr.fetchall()) + return ids + project_task() diff --git a/addons/report_analytic_planning/report_analytic_planning_view.xml b/addons/report_analytic_planning/report_analytic_planning_view.xml index 755bad51320..78fb258c093 100644 --- a/addons/report_analytic_planning/report_analytic_planning_view.xml +++ b/addons/report_analytic_planning/report_analytic_planning_view.xml @@ -82,7 +82,55 @@ - + +
+ + + + + + + + + + + + + + +