From 52037fce7f3febfaffee998dbc95863d25ce3b96 Mon Sep 17 00:00:00 2001 From: Pawan Kumar Date: Mon, 11 Jan 2021 17:25:19 +0530 Subject: [PATCH] update null value issue --- cor_custom/models/project.py | 44 +++++++++++++------------------ cor_custom/views/project_view.xml | 1 + 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/cor_custom/models/project.py b/cor_custom/models/project.py index 846ca0e..ef336eb 100755 --- a/cor_custom/models/project.py +++ b/cor_custom/models/project.py @@ -136,17 +136,15 @@ class Project(models.Model): def _compute_consultant_timesheet_hour(self): for val in self: - print('1111111111111', val._origin.id) - print('222222222222') self._cr.execute('''SELECT project_id, employee_id, SUM(unit_amount) FROM account_analytic_line where project_id = %(project_id)s GROUP BY project_id, employee_id''', {'project_id': val._origin.id}) res = self._cr.fetchone() - print('RESSSSSSS', res) - print('55555555', res[0], type(res[0]), res[1], type(res[1]), res[2], type(res[2])) - val.consultant_timesheet_hrs.create({'project_id': res[0], - 'employee_id': res[1], - 'timesheet_hour': res[2]}) - + if res: + val.consultant_timesheet_hrs.create({'project_id': res[0], + 'employee_id': res[1], + 'timesheet_hour': res[2]}) + else: + val.consultant_timesheet_hrs = False class ProjectConsultantTimesheetHrs(models.Model): @@ -155,26 +153,20 @@ class ProjectConsultantTimesheetHrs(models.Model): project_id = fields.Many2one('project.project', "Project", required=True) employee_id = fields.Many2one('hr.employee') + employee_price = fields.Float(string="Consultant Price", compute='_compute_consultant_timesheet_cost', default=0.0) timesheet_hour = fields.Float("Timesheet Hour", default=0.0) - consultant_cost = fields.Float("Actual Cost", default=0.0) + consultant_cost = fields.Float("Actual Cost", compute='_compute_consultant_timesheet_cost', default=0.0) - # def _compute_consultant_timesheet_hour(self): - # for val in self: - # print('1111111111111', val.project_id._origin.id) - # print('222222222222') - # self._cr.execute('''SELECT project_id, employee_id, SUM(unit_amount) FROM account_analytic_line where project_id = %(project_id)s - # GROUP BY project_id, employee_id''', {'project_id': val.project_id._origin.id}) - # res = self._cr.fetchone() - # print('RESSSSSSS', res) - # val.create((0, 0, {'project_id': res[0], - # 'employee_id': res[1], - # 'timesheet_hour': res[2]})) - - # if res and res[1] and res[2]: - # val.employee_id = res[1] - # val.timesheet_hour = res[2] - # else: - # val.timesheet_hour = 0.0 + def _compute_consultant_timesheet_cost(self): + for val in self: + if val.employee_id.timesheet_cost: + val.employee_price = val.employee_id.timesheet_cost + else: + val.employee_price = 0.0 + if val.timesheet_hour and val.employee_id.timesheet_cost: + val.consultant_cost = val.timesheet_hour * val.employee_id.timesheet_cost + else: + val.consultant_cost = 0.0 class InheritProjectProductEmployeeMap(models.Model): diff --git a/cor_custom/views/project_view.xml b/cor_custom/views/project_view.xml index 72d0481..72b66df 100755 --- a/cor_custom/views/project_view.xml +++ b/cor_custom/views/project_view.xml @@ -110,6 +110,7 @@ +