From 53356a5dcfefe11c185ae1443ca33949264a997e Mon Sep 17 00:00:00 2001 From: Thibault Francois Date: Fri, 31 Jul 2020 10:30:31 +0000 Subject: [PATCH] [FIX] sale_timesheet: Create invoice from SO with section Problem: When you try to create an invoice from a sale order that contains section and post paid service product. You set a date_invoice_timesheet in the wizard. You got a traceback excpected singleton product.product() This is cause by the filtering of so line with sol.product_id._is_delivered_timesheet() when the sale order line has no product for a section or a note Solution: Check there is a product on the line first closes odoo/odoo#55353 X-original-commit: b49e64d3b118c938154eeeeb85c5fd6d72561a82 Signed-off-by: Olivier Dony (odo) Signed-off-by: Thibault Francois --- addons/sale_timesheet/models/sale_order.py | 5 ++--- addons/sale_timesheet/tests/test_sale_timesheet.py | 6 ++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/addons/sale_timesheet/models/sale_order.py b/addons/sale_timesheet/models/sale_order.py index 2fbf310a615..365118bdeb0 100644 --- a/addons/sale_timesheet/models/sale_order.py +++ b/addons/sale_timesheet/models/sale_order.py @@ -126,7 +126,7 @@ class SaleOrderLine(models.Model): :param start_date: the start date of the period :param end_date: the end date of the period """ - lines_by_timesheet = self.filtered(lambda sol: sol.product_id._is_delivered_timesheet()) + lines_by_timesheet = self.filtered(lambda sol: sol.product_id and sol.product_id._is_delivered_timesheet()) domain = lines_by_timesheet._timesheet_compute_delivered_quantity_domain() domain = expression.AND([domain, [ '|', @@ -139,5 +139,4 @@ class SaleOrderLine(models.Model): mapping = lines_by_timesheet.sudo()._get_delivered_quantity_by_analytic(domain) for line in lines_by_timesheet: - if line.product_id._is_delivered_timesheet(): - line.qty_to_invoice = mapping.get(line.id, 0.0) + line.qty_to_invoice = mapping.get(line.id, 0.0) diff --git a/addons/sale_timesheet/tests/test_sale_timesheet.py b/addons/sale_timesheet/tests/test_sale_timesheet.py index 28c8a50abe3..8ba937d7121 100644 --- a/addons/sale_timesheet/tests/test_sale_timesheet.py +++ b/addons/sale_timesheet/tests/test_sale_timesheet.py @@ -393,6 +393,12 @@ class TestSaleTimesheet(TestCommonSaleTimesheet): 'partner_shipping_id': self.partner_a.id, 'pricelist_id': self.company_data['default_pricelist'].id, }) + # Section Line + so_line_ordered_project_only = self.env['sale.order.line'].create({ + 'name': "Section Name", + 'order_id': sale_order.id, + 'display_type': 'line_section', + }) so_line_deliver_global_project = self.env['sale.order.line'].create({ 'name': self.product_delivery_timesheet2.name, 'product_id': self.product_delivery_timesheet2.id,