From e5b3900d63ce37b308dae6511aee29dcdafac834 Mon Sep 17 00:00:00 2001 From: projectsodoo Date: Mon, 18 Jan 2021 22:48:33 +0530 Subject: [PATCH] Added file --- cor_custom/views/project_hours_view.xml | 80 +++++++++++ .../wizard/project_multi_budget_assign.py | 127 ++++++++++++++++++ .../project_multi_budget_assign_view.xml | 47 +++++++ 3 files changed, 254 insertions(+) create mode 100755 cor_custom/views/project_hours_view.xml create mode 100755 cor_custom/wizard/project_multi_budget_assign.py create mode 100755 cor_custom/wizard/project_multi_budget_assign_view.xml diff --git a/cor_custom/views/project_hours_view.xml b/cor_custom/views/project_hours_view.xml new file mode 100755 index 0000000..46c1057 --- /dev/null +++ b/cor_custom/views/project_hours_view.xml @@ -0,0 +1,80 @@ + + + + + project.consultant.hrs.form + project.consultant.hrs + +
+ + + + + + + + + +
+ + + project.consultant.hrs.tree + project.consultant.hrs + + + + + + + + + + + + + + + project.consultant.hrs.search + project.consultant.hrs + + + + + + + + + + + + + + + + Consultant Allocation + ir.actions.act_window + project.consultant.hrs + tree,form + + { + 'search_default_project': 1, + 'search_default_consultant': 1, + } + + + + + + Project Consul Hours + project.project + + +
+ +
+
+
+ +
diff --git a/cor_custom/wizard/project_multi_budget_assign.py b/cor_custom/wizard/project_multi_budget_assign.py new file mode 100755 index 0000000..1b511ab --- /dev/null +++ b/cor_custom/wizard/project_multi_budget_assign.py @@ -0,0 +1,127 @@ +# -*- coding: utf-8 -*- +from odoo import api, fields, models, _ +from odoo.exceptions import UserError, ValidationError +from dateutil.relativedelta import relativedelta + +class ProjectMultiBudgetAssign(models.TransientModel): + _name = 'project.multi.budget.assign' + _description = 'Project multi budget assign' + + project_id = fields.Many2one('project.project', string="Project", required=True) + start_date = fields.Date('Start Date', required=True, default=fields.Date.context_today) + end_date = fields.Date('End Date', required=True) + project_multi_line = fields.One2many('project.multi.budget.assign.line', 'line_id', 'Consultant Details') + + @api.model + def default_get(self, fields): + res = super(ProjectMultiBudgetAssign, self).default_get(fields) + res_id = self._context.get('active_id') + record = self.env['project.project'].browse(res_id) + lines = [] + print("record.sale_line_employee_ids", record.sale_line_employee_ids) + for rec in record.sale_line_employee_ids: + cons = {} + all_cons = self.env['project.consultant.hrs'].search([('employee_id','=',rec.employee_id.id),('project_id','=',rec.project_id.id)]) + all_per = [v.percentage for v in all_cons] + if sum(all_per) < 100: + cons.update({'employee_id': rec.employee_id.id, 'emp_map_id':rec.id, 'project_id':res_id}) + lines.append((0, 0, cons)) + if record and (not record.pricing_type == 'employee_rate' or not record.project_type == 'hours_in_consultant'): + raise ValidationError(_('Not applicable for this project type ')) + if not lines: + raise ValidationError(_('Not applicable, Please assign or check consultant')) + if record and not record.date_start or not record.date: + raise UserError(_('Project start date and end date should not be blank')) + res.update({'project_id':res_id, 'project_multi_line': lines}) + return res + + @api.constrains('start_date', 'end_date') + def _check_dates(self): + for rec in self: + if rec.end_date < rec.start_date: + raise ValidationError(_('Start date must be earlier than end date.')) + + @api.onchange('start_date') + def onchange_start_date(self): + if self.start_date: + self.end_date = self.start_date + relativedelta(days=6) + + def action_create_budgeted_hrs(self): + record = self.env['project.consultant.hrs'] + res_id = self._context.get('active_id') + for val in self: + for line in val.project_multi_line: + record.create({'project_id':res_id, + 'employee_id':line.employee_id.id, + 'start_date':val.start_date, + 'end_date':val.end_date, + 'budgeted_hours':line.budgeted_hours, + 'percentage':line.percentage}) + return True + + +class ProjectMultiBudgetAssignLine(models.TransientModel): + _name = 'project.multi.budget.assign.line' + _description = 'Project multi budget assign line' + + """domain = lambda self: self._get_employee_id_domain(), + @api.model + def _get_employee_id_domain(self): + project_id = self._context.get('active_id') + record = self.env['project.project'].browse(project_id) + emp_ids = [emp.employee_id.id for emp in record.sale_line_employee_ids] + return [('id','in', emp_ids)]""" + + line_id = fields.Many2one('project.multi.budget.assign', string="Line ID", required=True) + project_id = fields.Many2one('project.project', string="Project", required=True) + emp_map_id = fields.Many2one('project.sale.line.employee.map', string="Consultant Map", required=True) + employee_id = fields.Many2one('hr.employee', string="Consultant", required=True) + budgeted_qty = fields.Float(string='Budgeted Hours', related="emp_map_id.budgeted_qty") + all_percentage = fields.Float("Total Allocated (%)", compute='_compute_allocation') + rem_percentage = fields.Float("Total Unallocated (%)", compute='_compute_allocation') + percentage = fields.Float("Percentage (%)") + budgeted_hours = fields.Float("Budgeted Hours", compute='_compute_budgeted_hours', store=True) + + @api.depends('project_id', 'employee_id') + def _compute_allocation(self): + for val in self: + if val.project_id and val.employee_id: + cons = self.env['project.consultant.hrs'].search([('employee_id','=',val.employee_id.id),('project_id','=',val.project_id.id)]) + all_per = 0 + for res in cons: + all_per += res.percentage + #res = all_per - 100 + val.all_percentage = all_per + val.rem_percentage = 100 - all_per + else: + val.all_percentage = 0 + val.rem_percentage = 0 + + @api.depends('project_id', 'employee_id', 'project_id.sale_line_employee_ids', 'percentage') + def _compute_budgeted_hours(self): + for val in self: + if val.project_id and val.employee_id and val.percentage > 0: + budgeted = 0 + for emp in val.project_id.sale_line_employee_ids: + if emp.employee_id.id == val.employee_id.id: + budgeted = emp.budgeted_qty + val.budgeted_hours = (budgeted * val.percentage / 100) + else: + val.budgeted_hours = 0 + + """@api.onchange('employee_id', 'percentage') + def onchange_employee_id(self): + #res = {} + project_id = self._context.get('active_id') + record = self.env['project.project'].browse(project_id) + #emp_ids = [emp.employee_id.id for emp in record.sale_line_employee_ids] + #res['domain'] = {'employee_id': [('id', 'in', emp_ids)]} + if self.employee_id and self.percentage > 0: + print("self.employee_id", self.employee_id) + cons = [emp.budgeted_qty if emp.employee_id.id == self.employee_id.id else 0 for emp in record.sale_line_employee_ids] + budgeted = cons and cons[0] or 0 + if budgeted > 0: + self.budgeted_hours = (budgeted * self.percentage / 100) + else: + self.budgeted_hours = 0""" + #return res \ No newline at end of file diff --git a/cor_custom/wizard/project_multi_budget_assign_view.xml b/cor_custom/wizard/project_multi_budget_assign_view.xml new file mode 100755 index 0000000..9a023aa --- /dev/null +++ b/cor_custom/wizard/project_multi_budget_assign_view.xml @@ -0,0 +1,47 @@ + + + + + + Project Multi Budget + project.multi.budget.assign + +
+ + + + + + + + + + + + + + + + + +
+
+
+
+
+ + + Consultant Budget Hours Assign + project.multi.budget.assign + form + + new + + form + + +
+