[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) <odo@openerp.com>
Signed-off-by: Thibault Francois <tfr-odoo@users.noreply.github.com>
This commit is contained in:
Thibault Francois
2020-08-03 16:48:26 +00:00
parent 798fa36471
commit 53356a5dcf
2 changed files with 8 additions and 3 deletions
+2 -3
View File
@@ -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)
@@ -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,