From 10c8c9bd23e53b257541ee28b66543b0a16b946f Mon Sep 17 00:00:00 2001 From: projectsodoo Date: Wed, 6 Jan 2021 10:55:21 +0530 Subject: [PATCH] Export data and budgeted hours forecast added --- cor_custom/models/analytic.py | 35 ++++++++++++++++++++- project_forecast/models/project_forecast.py | 18 ++++++++++- project_forecast/views/planning_views.xml | 1 + 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/cor_custom/models/analytic.py b/cor_custom/models/analytic.py index efb1be5..8d4c801 100755 --- a/cor_custom/models/analytic.py +++ b/cor_custom/models/analytic.py @@ -1,9 +1,13 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details -from odoo import api, exceptions, fields, models, _ +from odoo import api, exceptions, fields, models, tools, _ from odoo.exceptions import UserError, AccessError, ValidationError from odoo.osv import expression +import math +from datetime import datetime, time, timedelta +from odoo.tools.float_utils import float_round +from odoo.tools import DEFAULT_SERVER_DATE_FORMAT, ustr class AccountAnalyticLine(models.Model): _inherit = 'account.analytic.line' @@ -34,6 +38,35 @@ class AccountAnalyticLine(models.Model): raise ValidationError(_("End time cannot be earlier than Start time")) self.unit_amount = res + @api.model + def export_data(self, fields): + index = range(len(fields)) + fields_name = dict(zip(fields, index)) + res = super(AccountAnalyticLine, self).export_data(fields) + for index, val in enumerate(res['datas']): + if fields_name.get('date') >=0: + tdateindex = fields_name.get('date') + tdate = res['datas'][index][tdateindex] + if tdate: + res['datas'][index][tdateindex] = datetime.strftime(tdate, "%d/%m/%Y") + if fields_name.get('task_id') >=0: + taskindex = fields_name.get('task_id') + ttask = res['datas'][index][taskindex] + if type(ttask)==bool: + res['datas'][index][taskindex] = '' + if fields_name.get('start_time') >=0: + starttimeindex = fields_name.get('start_time') + starttime = float(res['datas'][index][starttimeindex]) + if starttime: + start_time = tools.format_duration(starttime) + res['datas'][index][starttimeindex] = start_time + if fields_name.get('end_time') >=0: + endtimeindex = fields_name.get('end_time') + endtime = float(res['datas'][index][endtimeindex]) + if endtime: + end_time = tools.format_duration(endtime) + res['datas'][index][endtimeindex] = end_time + return res @api.model def create(self, vals): diff --git a/project_forecast/models/project_forecast.py b/project_forecast/models/project_forecast.py index f86a465..93d93d9 100755 --- a/project_forecast/models/project_forecast.py +++ b/project_forecast/models/project_forecast.py @@ -16,12 +16,26 @@ class PlanningShift(models.Model): _inherit = 'planning.slot' project_id = fields.Many2one('project.project', string="Project", domain="[('company_id', '=', company_id), ('allow_forecast', '=', True)]", check_company=True) + budgeted_hours = fields.Float("Budgeted hours", default=0, compute='_compute_budgeted_hours', store=True) task_id = fields.Many2one('project.task', string="Task", domain="[('company_id', '=', company_id), ('project_id', '=', project_id)]", check_company=True) _sql_constraints = [ ('project_required_if_task', "CHECK( (task_id IS NOT NULL AND project_id IS NOT NULL) OR (task_id IS NULL) )", "If the planning is linked to a task, the project must be set too."), ] + @api.depends('project_id', 'employee_id') + def _compute_budgeted_hours(self): + for slot in self: + if slot.project_id and slot.employee_id: + if slot.project_id.project_type == 'hours_no_limit': + slot.budgeted_hours = slot.project_id.budgeted_hours + #print("slot.project_id.project_type", slot.project_id.project_type) + if slot.project_id.project_type == 'hours_in_consultant': + cons = self.env['project.sale.line.employee.map'].search([('employee_id','=',slot.employee_id.id),('project_id','=',slot.project_id.id)], limit=1) + slot.budgeted_hours = cons and cons.budgeted_qty or 0 + else: + slot.budgeted_hours = 0 + @api.onchange('task_id') def _onchange_task_id(self): if not self.project_id: @@ -46,7 +60,9 @@ class PlanningShift(models.Model): project_ids = self.env['project.project'].search( [('privacy_visibility', '=', 'followers'), ('allow_forecast', '=', True), ('allowed_internal_user_ids', 'in', self.employee_id.user_id.id)]).ids - emp_all_project_ids = manager_id + emp_project_ids + project_ids + consul_ids = self.env['project.sale.line.employee.map'].search([('employee_id', '=', self.employee_id.id)]) + consul_project_ids = [val.project_id.id for val in consul_ids] + emp_all_project_ids = manager_id + emp_project_ids + project_ids + consul_project_ids domain = [('id', 'in', list(set(emp_all_project_ids)))] result = { 'domain': {'project_id': domain}, diff --git a/project_forecast/views/planning_views.xml b/project_forecast/views/planning_views.xml index 779f613..199e15c 100755 --- a/project_forecast/views/planning_views.xml +++ b/project_forecast/views/planning_views.xml @@ -21,6 +21,7 @@ +