From fb1420cf5b4a04789529a175f4368f82cc6bd656 Mon Sep 17 00:00:00 2001 From: projectsodoo Date: Tue, 19 Jan 2021 16:03:43 +0530 Subject: [PATCH] Label, rem and compute changed --- cor_custom/models/project_hours.py | 7 ++++--- .../wizard/project_multi_budget_assign.py | 19 ++++++++++++++----- .../project_multi_budget_assign_view.xml | 3 ++- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/cor_custom/models/project_hours.py b/cor_custom/models/project_hours.py index 92eccec..41a76fe 100755 --- a/cor_custom/models/project_hours.py +++ b/cor_custom/models/project_hours.py @@ -19,8 +19,8 @@ class ProjectConsultantHrs(models.Model): start_date = fields.Date('Start Date', required=True) end_date = fields.Date('End Date', required=True) percentage = fields.Float("Percentage (%)") - budgeted_hours = fields.Float("Budgeted Hours", compute='_compute_budgeted_hours', store=True) - actual_hours = fields.Float("Actual Hours", compute='_compute_actual_hours', store=True) + budgeted_hours = fields.Float("Budgeted Hours for period", compute='_compute_budgeted_hours', store=True) + actual_hours = fields.Float("Actual Hours for period", compute='_compute_actual_hours', store=True) #hours_type = fields.Selection([('Budgeted Hours', 'Budgeted Hours'), ('Actual Hours', 'Actual Hours')], default="Budgeted Hours", string="Type") @api.constrains('start_date', 'end_date') @@ -75,7 +75,8 @@ class ProjectConsultantHrs(models.Model): else: val.budgeted_hours = 0 - @api.depends('project_id', 'start_date', 'end_date', 'project_id.timesheet_ids') + @api.depends('project_id', 'start_date', 'end_date', 'project_id.timesheet_ids', 'project_id.timesheet_ids.date', + 'project_id.timesheet_ids.project_id', 'project_id.timesheet_ids.employee_id', 'project_id.timesheet_ids.start_time', 'project_id.timesheet_ids.end_time') def _compute_actual_hours(self): Timesheet = self.env['account.analytic.line'] for val in self: diff --git a/cor_custom/wizard/project_multi_budget_assign.py b/cor_custom/wizard/project_multi_budget_assign.py index 1b511ab..ec3f768 100755 --- a/cor_custom/wizard/project_multi_budget_assign.py +++ b/cor_custom/wizard/project_multi_budget_assign.py @@ -18,7 +18,6 @@ class ProjectMultiBudgetAssign(models.TransientModel): 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)]) @@ -77,10 +76,18 @@ class ProjectMultiBudgetAssignLine(models.TransientModel): 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) + all_percentage = fields.Float("Total Allocated %", compute='_compute_allocation') + rem_percentage = fields.Float("Total Unallocated %", compute='_compute_allocation') + percentage = fields.Float("Percentage %") + remaining = fields.Float("Remaining Percentage %") + budgeted_hours = fields.Float("Budgeted Hours for period", compute='_compute_budgeted_hours', store=True) + + @api.onchange('percentage') + def onchange_employee_id(self): + res = self.rem_percentage - self.percentage + if res < 0: + raise ValidationError(_('Remaining percentage should not be negative')) + self.remaining = res @api.depends('project_id', 'employee_id') def _compute_allocation(self): @@ -93,9 +100,11 @@ class ProjectMultiBudgetAssignLine(models.TransientModel): #res = all_per - 100 val.all_percentage = all_per val.rem_percentage = 100 - all_per + val.remaining = 100 - all_per else: val.all_percentage = 0 val.rem_percentage = 0 + val.remaining = 0 @api.depends('project_id', 'employee_id', 'project_id.sale_line_employee_ids', 'percentage') def _compute_budgeted_hours(self): diff --git a/cor_custom/wizard/project_multi_budget_assign_view.xml b/cor_custom/wizard/project_multi_budget_assign_view.xml index 9a023aa..061b8ac 100755 --- a/cor_custom/wizard/project_multi_budget_assign_view.xml +++ b/cor_custom/wizard/project_multi_budget_assign_view.xml @@ -11,7 +11,7 @@ - + @@ -21,6 +21,7 @@ +