From 85f4c8f2ba05e6a1db1dc9f275253d8cc2efbd6d Mon Sep 17 00:00:00 2001 From: "Victor Piryns (pivi)" Date: Thu, 8 Sep 2022 08:38:25 +0000 Subject: [PATCH] [FIX] sale_timesheet: set correct invoice_state on timesheeted sol When generating an invoice for a SO with 2 SOL that have a timesheet service (1 SOL is timesheeted in August, the other is timesheeted in September) and we request the invoice for the period of August only, the SOL for September is incorrectly set to state "Nothing to Invoice", instead of staying in state "To Invoice". This is due to the fact that when we inspect the SOL to invoice, those that are not in the domain (here the SOL in September is not in the time domain of August), we set it's qty_to_invoice to 0, so it doesn't get invoiced, but this is a computed field, which sets the line invoice_state to "Nothing to invoice". The proposed fix is to reset the invoice_state of the lines that are not validated by the domain to the state before setting the field qty_to_invoice to 0. Affected versions: - 15.0 - saas-15.2 - saas-15.3 - master opw-2969641 closes odoo/odoo#100978 X-original-commit: 50b81adb3ea13db33bf1375b7038b6cc3546ec86 Signed-off-by: Laurent Stukkens (ltu) Signed-off-by: Piryns Victor (pivi) --- addons/sale_timesheet/models/sale_order.py | 8 +++++++- addons/sale_timesheet/tests/test_sale_timesheet.py | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) 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)