From 265a45a0c6a0aa9009e953faa3879e1f4c01ed08 Mon Sep 17 00:00:00 2001 From: "Xavier BOL (xbo)" Date: Mon, 17 Jan 2022 12:09:44 +0100 Subject: [PATCH] [FIX] sale_timesheet: fix timesheet_invoice_type compute when amount<0 Before this commit, when the user creates an expense for the project and reinvoice it. When this expense is approved and a post entry is generated. An SOL is created in the SO and also a AAL to take into account the cost. However, the `timesheet_invoice_type` for this AAL is equal to `service_revenues` even if the amount is less than 0. The reason is when the AAL is not a timesheet and linked to a SOL containing a service product than the AAL is considered as a service revenue even if the amount is less than 0 but in this case, the AAL is a cost and not a revenue. This commit fixes this issue by checking if the amount is greater or equal to 0 to set the `timesheet_invoice_type` to `service_revenues` otherwise we set to `other_costs`. task-2710808 --- addons/sale_timesheet/models/account.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/addons/sale_timesheet/models/account.py b/addons/sale_timesheet/models/account.py index 2ddcae9df9f..b2c0a737fef 100644 --- a/addons/sale_timesheet/models/account.py +++ b/addons/sale_timesheet/models/account.py @@ -50,10 +50,13 @@ class AccountAnalyticLine(models.Model): invoice_type = 'billable_fixed' timesheet.timesheet_invoice_type = invoice_type else: - if timesheet.so_line and timesheet.so_line.product_id.type == 'service': - timesheet.timesheet_invoice_type = 'service_revenues' + if timesheet.amount >= 0: + if timesheet.so_line and timesheet.so_line.product_id.type == 'service': + timesheet.timesheet_invoice_type = 'service_revenues' + else: + timesheet.timesheet_invoice_type = 'other_revenues' else: - timesheet.timesheet_invoice_type = 'other_revenues' if timesheet.amount >= 0 else 'other_costs' + timesheet.timesheet_invoice_type = 'other_costs' @api.depends('task_id.sale_line_id', 'project_id.sale_line_id', 'employee_id', 'project_id.allow_billable') def _compute_so_line(self):