diff --git a/addons/sale_timesheet/models/sale_order.py b/addons/sale_timesheet/models/sale_order.py index 4a739abd654..04e88373efd 100644 --- a/addons/sale_timesheet/models/sale_order.py +++ b/addons/sale_timesheet/models/sale_order.py @@ -271,7 +271,13 @@ class SaleOrderLine(models.Model): mapping = lines_by_timesheet.sudo()._get_delivered_quantity_by_analytic(domain) for line in lines_by_timesheet: - line.qty_to_invoice = mapping.get(line.id, 0.0) + qty_to_invoice = mapping.get(line.id, 0.0) + if qty_to_invoice: + line.qty_to_invoice = qty_to_invoice + else: + prev_inv_status = line.invoice_status + line.qty_to_invoice = qty_to_invoice + line.invoice_status = prev_inv_status def _get_action_per_item(self): """ Get action per Sales Order Item diff --git a/addons/sale_timesheet/tests/test_sale_timesheet.py b/addons/sale_timesheet/tests/test_sale_timesheet.py index 0443290b720..bc4a5ba7172 100644 --- a/addons/sale_timesheet/tests/test_sale_timesheet.py +++ b/addons/sale_timesheet/tests/test_sale_timesheet.py @@ -455,6 +455,8 @@ class TestSaleTimesheet(TestCommonSaleTimesheet): wizard.create_invoices() self.assertTrue(sale_order.invoice_ids, 'One invoice should be created because the timesheet logged is between the period defined in wizard') + self.assertTrue(all(line.invoice_status == "to invoice" for line in sale_order.order_line if line.qty_delivered != line.qty_invoiced), + "All lines that still have some quantity to be invoiced should have an invoice status of 'to invoice', regardless if they were considered for previous invoicing, but didn't belong to the timesheet domain") invoice = sale_order.invoice_ids[0] self.assertEqual(so_line_deliver_global_project.qty_invoiced, timesheet1.unit_amount)