[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) <xbo@odoo.com>
This commit is contained in:
Kartik Chavda
2023-11-04 09:05:38 +00:00
committed by kcv-odoo
parent 3a76a9326e
commit 05aa12bd4e
2 changed files with 11 additions and 5 deletions
+9 -4
View File
@@ -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')
+2 -1
View File
@@ -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,