From 4c54dde9e0cc8d5f527fb18e1e79b3c8e0f72c1b Mon Sep 17 00:00:00 2001 From: alsh-odoo Date: Mon, 28 Aug 2023 18:31:56 +0530 Subject: [PATCH] [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) --- addons/sale_timesheet/models/sale_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/sale_timesheet/models/sale_order.py b/addons/sale_timesheet/models/sale_order.py index 662e106170a..d25aa6981ad 100644 --- a/addons/sale_timesheet/models/sale_order.py +++ b/addons/sale_timesheet/models/sale_order.py @@ -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,