[FIX] sale_timesheet : display uom and plan hours correctly

- Steps :
Create 4 Services :
	> Product Type : Service
	> Create on Order : Project & Task
	> Unit of Measure -respectively- :
		>> Hours (H),
		>> Days  (D),
		>> Units (U),
		>> g     (Other).
Create a SO with the for of them (1 uom_qty for each) and confirm.

- Expected :
For both the 'Planned Hours' on the Tasks
and the section 'Sold' of the Project Updates,
the conversion to time should be processed as follows :
H     : qty =     uom_qty [Hours]
D     : qty = uom_qty * 8 [Hours]
U     : qty =     uom_qty [Hours]
Other : qty =           0 [Hours] or uom_qty [uom]

- Issues :
The Task linked to SOL (Other) has 1 Planned Hour i/o 0.
In Project Updates, uom (U) is Units i/o Hours
and uom (Other) is Hours i/o g.

- Fix :
This fix corrects everything as expected.

opw-2784992

closes odoo/odoo#87884

X-original-commit: 3cae83635067707a99141aad3cf6b0b6081e8159
Signed-off-by: Xavier <xbo@odoo.com>
This commit is contained in:
Audric Onockx (auon)
2022-04-05 14:14:05 +02:00
parent 340c80d30a
commit 81a5bcdba9
2 changed files with 56 additions and 4 deletions
+9 -4
View File
@@ -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):
@@ -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])