[FIX] sale_timesheet: handle error of giving default value if no sale order line

This traceback raises when user changes the product type to 'consumable' in a
sale order and clicks the 'recorded' stat button.

To reproduce this issue:

1) Install 'sale_timesheet'
2) Create a new 'sale order'
3) Select any customer > Select a product with the 'service' type.
4) Click Confirm, then proceed to click the Create Project button.
5) Give any name to the project > Return to that sale order.
6) Now a 'recorded' stat button is visible > Click on that and create a record.
7) Return to that sale order > Go to the order lines, and for the previously
   selected product, change the product type to 'consumable'
8) Once again, go to that 'sale order' and click on the 'recorded' stat button.

Error: "StopIteration: null"

[1] On the 'action_view_timesheet' method 'default_sale_line' variable is
getting a record with a condition of 'sale.order.line' is_service must be true
and 'service_policy' in 'order_prepaid' or 'delivered_timesheet' .

[2] But 'is_service' is getting value through a compute method in which
product type is equal to 'service'.

Because the user changed the type to 'consumable', the iteration ends with no
records and there is no default value. So it leads to the above traceback.

[1]
https://github.com/odoo/odoo/blob/69fca30bb4fb66e6d979ce5ddc1bff4db963ca71/addons/sale_timesheet/models/sale_order.py#L105-L111

[2]
https://github.com/odoo/odoo/blob/69fca30bb4fb66e6d979ce5ddc1bff4db963ca71/addons/sale_service/models/sale_order_line.py#L18-L20

sentry-4396433586

closes odoo/odoo#133903

X-original-commit: 062cec2175e5b22126b5c3be5acef5039ca1e804
Signed-off-by: Xavier Bol (xbo) <xbo@odoo.com>
This commit is contained in:
alsh-odoo
2023-09-04 08:03:39 +00:00
parent 46178afee0
commit 4c54dde9e0
+1 -1
View File
@@ -108,7 +108,7 @@ class SaleOrder(models.Model):
return {'type': 'ir.actions.act_window_close'}
action = self.env["ir.actions.actions"]._for_xml_id("sale_timesheet.timesheet_action_from_sales_order")
default_sale_line = next(sale_line for sale_line in self.order_line if sale_line.is_service and sale_line.product_id.service_policy in ['ordered_prepaid', 'delivered_timesheet'])
default_sale_line = next((sale_line for sale_line in self.order_line if sale_line.is_service and sale_line.product_id.service_policy in ['ordered_prepaid', 'delivered_timesheet']), self.env['sale.order.line'])
context = {
'search_default_billable_timesheet': True,
'default_is_so_line_edited': True,