diff --git a/addons/sale_timesheet/models/sale_order.py b/addons/sale_timesheet/models/sale_order.py index 4f466a75be0..02769cc7597 100644 --- a/addons/sale_timesheet/models/sale_order.py +++ b/addons/sale_timesheet/models/sale_order.py @@ -238,10 +238,15 @@ class SaleOrderLine(models.Model): def _convert_qty_company_hours(self, dest_company): company_time_uom_id = dest_company.project_time_mode_id - if self.product_uom.id != company_time_uom_id.id and self.product_uom.category_id.id == company_time_uom_id.category_id.id: - planned_hours = self.product_uom._compute_quantity(self.product_uom_qty, company_time_uom_id) - else: - planned_hours = self.product_uom_qty + planned_hours = 0.0 + product_uom = self.product_uom + if product_uom == self.env.ref('uom.product_uom_unit'): + product_uom = self.env.ref('uom.product_uom_hour') + if product_uom.category_id == company_time_uom_id.category_id: + if product_uom != company_time_uom_id: + planned_hours = product_uom._compute_quantity(self.product_uom_qty, company_time_uom_id) + else: + planned_hours = self.product_uom_qty return planned_hours def _timesheet_create_project(self): diff --git a/addons/sale_timesheet/tests/test_sale_service.py b/addons/sale_timesheet/tests/test_sale_service.py index adef237694e..ddfb167ece2 100644 --- a/addons/sale_timesheet/tests/test_sale_service.py +++ b/addons/sale_timesheet/tests/test_sale_service.py @@ -598,3 +598,50 @@ class TestSaleService(TestCommonSaleTimesheet): }) self.assertEqual(timesheet.so_line, prepaid_service_sol, "The SOL should be the same than one containing the prepaid service product.") self.assertEqual(prepaid_service_sol.remaining_hours, 2, "The remaining hours should not change.") + + def test_several_uom_sol_to_planned_hours(self): + planned_hours_for_uom = { + 'day': 8.0, + 'hour': 1.0, + 'unit': 1.0, + 'gram': 0.0, + } + + Product = self.env['product.product'] + product_vals = { + 'type': 'service', + 'service_type': 'timesheet', + 'project_id': self.project_global.id, + 'service_tracking': 'task_global_project', + } + + SaleOrderLine = self.env['sale.order.line'] + sol_vals = { + 'product_uom_qty': 1, + 'price_unit': 100, + 'order_id': self.sale_order.id, + } + + self.project_global.task_ids = False + for uom_name in planned_hours_for_uom: + uom_id = self.env.ref('uom.product_uom_%s' % uom_name) + + product_vals.update({ + 'name': uom_name, + 'uom_id': uom_id.id, + 'uom_po_id': uom_id.id, + }) + product = Product.create(product_vals) + + sol_vals.update({ + 'name': uom_name, + 'product_id': product.id, + 'product_uom': uom_id.id, + }) + SaleOrderLine.create(sol_vals) + + self.sale_order.action_confirm() + + tasks = self.project_global.task_ids + for task in tasks: + self.assertEqual(task.planned_hours, planned_hours_for_uom[task.sale_line_id.name])