From 05aa12bd4e2e1b91b6ae55d23ebf2452247d6a98 Mon Sep 17 00:00:00 2001 From: Kartik Chavda Date: Thu, 20 Apr 2023 12:54:39 +0530 Subject: [PATCH] [FIX] sale_timesheet: fix threshold ratio for unit Before this commit service threshold value for 'unit' unit of measure display (1 unit = 8.00 hours) but since https://github.com/odoo/odoo/pull/99785 PR we take 1 unit equals to 1 hours not 8 hours. This commit display (1 unit = 1.00 hour) to dispay proper value according to calculation. task-3282848 closes odoo/odoo#141039 X-original-commit: d27209ef9bc4f57a8f7401e5271915763df5eeb1 Signed-off-by: Xavier Bol (xbo) --- addons/sale_timesheet/models/product.py | 13 +++++++++---- addons/sale_timesheet/models/sale_order.py | 3 ++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/addons/sale_timesheet/models/product.py b/addons/sale_timesheet/models/product.py index 0e22a3d9631..a19daf7022c 100644 --- a/addons/sale_timesheet/models/product.py +++ b/addons/sale_timesheet/models/product.py @@ -24,15 +24,20 @@ class ProductTemplate(models.Model): service_upsell_threshold = fields.Float('Threshold', default=1, help="Percentage of time delivered compared to the prepaid amount that must be reached for the upselling opportunity activity to be triggered.") service_upsell_threshold_ratio = fields.Char(compute='_compute_service_upsell_threshold_ratio') - @api.depends('uom_id') + @api.depends('uom_id', 'company_id') def _compute_service_upsell_threshold_ratio(self): product_uom_hour = self.env.ref('uom.product_uom_hour') + uom_unit = self.env.ref('uom.product_uom_unit') + company_uom = self.env.company.timesheet_encode_uom_id for record in self: - if not record.uom_id or product_uom_hour.factor == record.uom_id.factor: + if not record.uom_id or record.uom_id != uom_unit or\ + product_uom_hour.factor == record.uom_id.factor or\ + record.uom_id.category_id not in [product_uom_hour.category_id, uom_unit.category_id]: record.service_upsell_threshold_ratio = False continue - if product_uom_hour.factor != record.uom_id.factor: - record.service_upsell_threshold_ratio = f"(1 {record.uom_id.name} = {product_uom_hour.factor / record.uom_id.factor:.2f} Hours)" + else: + timesheet_encode_uom = record.company_id.timesheet_encode_uom_id or company_uom + record.service_upsell_threshold_ratio = f'(1 {record.uom_id.name} = {timesheet_encode_uom.factor / product_uom_hour.factor:.2f} {timesheet_encode_uom.name})' def _compute_visible_expense_policy(self): visibility = self.user_has_groups('project.group_project_user') diff --git a/addons/sale_timesheet/models/sale_order.py b/addons/sale_timesheet/models/sale_order.py index d25aa6981ad..1e97e8a4b64 100644 --- a/addons/sale_timesheet/models/sale_order.py +++ b/addons/sale_timesheet/models/sale_order.py @@ -264,6 +264,7 @@ class SaleOrderLine(models.Model): def _timesheet_create_project(self): project = super()._timesheet_create_project() project_uom = project.timesheet_encode_uom_id + timesheet_uom = self.company_id.timesheet_encode_uom_id uom_ids = set(project_uom + self.order_id.order_line.mapped('product_uom')) uom_unit = self.env.ref('uom.product_uom_unit') uom_hour = self.env.ref('uom.product_uom_hour') @@ -280,7 +281,7 @@ class SaleOrderLine(models.Model): product_type = line.product_id.service_tracking if line.is_service and (product_type == 'task_in_project' or product_type == 'project_only') and line.product_id.project_template_id == self.product_id.project_template_id: if uom_per_id.get(line.product_uom.id) or line.product_uom.id == uom_unit.id: - allocated_hours += line.product_uom_qty * uom_per_id.get(line.product_uom.id, project_uom).factor_inv * uom_hour.factor + allocated_hours += line.product_uom_qty * uom_per_id.get(line.product_uom.id, project_uom).factor_inv * timesheet_uom.factor project.write({ 'allocated_hours': allocated_hours,