[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
This commit is contained in:
Xavier BOL (xbo)
2022-04-01 15:33:00 +02:00
committed by Laurent Stukkens (LTU)
parent 7c3e8cf963
commit 265a45a0c6
+6 -3
View File
@@ -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):