From 320956aa2563536f183b8a280ddf6931e94c5976 Mon Sep 17 00:00:00 2001 From: Pawan Kumar Date: Wed, 13 Jan 2021 12:33:59 +0530 Subject: [PATCH] update code for manual price calculation --- cor_custom/models/project.py | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/cor_custom/models/project.py b/cor_custom/models/project.py index 0398c86..0e5b42d 100755 --- a/cor_custom/models/project.py +++ b/cor_custom/models/project.py @@ -183,7 +183,7 @@ class InheritProjectProductEmployeeMap(models.Model): currency_id = fields.Many2one('res.currency', string="Currency", compute='_compute_price_unit', store=True, readonly=False) sale_line_id = fields.Many2one('sale.order.line', "Service", domain=[('is_service', '=', True)]) - cost = fields.Float("Cost", default=0.0, store=True) + cost = fields.Float("Cost", default=0.0) consultant_cost = fields.Float("Actual Cost", compute='_compute_timesheet_hour', default=0.0) hour_distribution = fields.Selection(related='project_id.hour_distribution') @@ -213,22 +213,25 @@ class InheritProjectProductEmployeeMap(models.Model): @api.onchange('project_id.budgeted_revenue', 'price_unit', 'distribution_per', 'employee_id', 'role') def _compute_total_cost(self): - for val in self: - if val.project_id.project_type == 'hours_in_consultant': - 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) - else: - val.cost = val.project_id.budgeted_revenue * (val.project_id.employee_per / 100) * ( - val.distribution_per / 100) - if val.price_unit > 0.0: - val.budgeted_qty = val.cost / val.price_unit + if self.project_id.project_type == 'hours_in_consultant': + if self.hour_distribution == 'Percentage': + if self.role == 'Manager': + self.cost = self.project_id.budgeted_revenue * (self.project_id.manager_per / 100) * ( + self.distribution_per / 100) 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() + self.cost = self.project_id.budgeted_revenue * (self.project_id.employee_per / 100) * ( + self.distribution_per / 100) + if self.price_unit > 0.0: + self.budgeted_qty = self.cost / self.price_unit + # val.cost = val.budgeted_qty * val.price_unit + # val.consultant_cost = val.timesheet_hour * val.employee_price + # self.project_id.onchange_budgeted_hour() + + @api.onchange('price_unit', 'budgeted_qty') + def _calculate_total_cost(self): + if self.project_id.project_type == 'hours_in_consultant': + if self.hour_distribution == 'Manual': + self.cost = self.price_unit * self.budgeted_qty @api.depends('sale_line_id', 'sale_line_id.price_unit', 'timesheet_product_id') def _compute_price_unit(self):