From 6a71b602b447fca9c88063c97d9cf6e231cb526b Mon Sep 17 00:00:00 2001 From: Pawan Kumar Date: Mon, 11 Jan 2021 15:15:46 +0530 Subject: [PATCH] update timesheet entry for fixex type --- cor_custom/__manifest__.py | 2 +- cor_custom/models/project.py | 55 ++++++++++++++++++++++--- cor_custom/security/ir.model.access.csv | 3 +- cor_custom/views/project_view.xml | 18 ++++++-- 4 files changed, 68 insertions(+), 10 deletions(-) diff --git a/cor_custom/__manifest__.py b/cor_custom/__manifest__.py index 5a94307..174941e 100755 --- a/cor_custom/__manifest__.py +++ b/cor_custom/__manifest__.py @@ -24,7 +24,7 @@ # always loaded 'data': [ - #'security/ir.model.access.csv', + 'security/ir.model.access.csv', #'security/cor_custom_security.xml', 'views/crm_view.xml', 'views/sale_views.xml', diff --git a/cor_custom/models/project.py b/cor_custom/models/project.py index f6208cd..846ca0e 100755 --- a/cor_custom/models/project.py +++ b/cor_custom/models/project.py @@ -65,6 +65,9 @@ class Project(models.Model): manager_hour = fields.Float(string='Manager Hour') employee_hour = fields.Float(string='Employee Hour') + consultant_timesheet_hrs = fields.One2many('consultant.timesheet.hrs', 'project_id', "Timesheet Hrs", + copy=False, compute='_compute_consultant_timesheet_hour', + help="Consultant timesheet hours") @api.depends('cost', 'expenses_amt', 'budgeted_revenue') def _compute_calc(self): @@ -131,6 +134,48 @@ class Project(models.Model): record.cost = cost record.budgeted_hour_week = budgeted_hour_week + 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]}) + + + +class ProjectConsultantTimesheetHrs(models.Model): + _name = 'consultant.timesheet.hrs' + _description = 'Project Consultant Timesheet Hrs' + + project_id = fields.Many2one('project.project', "Project", required=True) + employee_id = fields.Many2one('hr.employee') + timesheet_hour = fields.Float("Timesheet Hour", default=0.0) + consultant_cost = fields.Float("Actual 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 + class InheritProjectProductEmployeeMap(models.Model): _inherit = 'project.sale.line.employee.map' @@ -180,17 +225,17 @@ class InheritProjectProductEmployeeMap(models.Model): if val.hour_distribution == 'Percentage': if val.role == 'Manager': val.cost = val.project_id.budgeted_revenue * (val.project_id.manager_per / 100) * ( - val.distribution_per / 100) + val.distribution_per / 100) else: val.cost = val.project_id.budgeted_revenue * (val.project_id.employee_per / 100) * ( - val.distribution_per / 100) + val.distribution_per / 100) if val.price_unit > 0.0: val.budgeted_qty = val.cost / val.price_unit else: val.cost = 0.0 # val.cost = val.budgeted_qty * val.price_unit - #val.consultant_cost = val.timesheet_hour * val.employee_price - #self.project_id.onchange_budgeted_hour() + # val.consultant_cost = val.timesheet_hour * val.employee_price + # self.project_id.onchange_budgeted_hour() @api.depends('sale_line_id', 'sale_line_id.price_unit', 'timesheet_product_id') def _compute_price_unit(self): @@ -203,4 +248,4 @@ class InheritProjectProductEmployeeMap(models.Model): line.currency_id = line.timesheet_product_id.currency_id else: # line.price_unit = 0 - line.currency_id = False \ No newline at end of file + line.currency_id = False diff --git a/cor_custom/security/ir.model.access.csv b/cor_custom/security/ir.model.access.csv index fdc1832..03fae5d 100755 --- a/cor_custom/security/ir.model.access.csv +++ b/cor_custom/security/ir.model.access.csv @@ -1,2 +1,3 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_cor_custom_cor_custom,cor_custom.cor_custom,model_cor_custom_cor_custom,base.group_user,1,1,1,1 \ No newline at end of file +access_consultant_timesheet_hrs_puser,consultant.timesheet.hrs,model_consultant_timesheet_hrs,project.group_project_user,1,0,0,0 +access_consultant_timesheet_hrs_pmanager,consultant.timesheet.hrs,model_consultant_timesheet_hrs,project.group_project_manager,1,1,1,1 \ No newline at end of file diff --git a/cor_custom/views/project_view.xml b/cor_custom/views/project_view.xml index 513c0bf..72d0481 100755 --- a/cor_custom/views/project_view.xml +++ b/cor_custom/views/project_view.xml @@ -45,8 +45,9 @@ widget="radio"/> - + + + @@ -60,8 +61,11 @@