From bfd6375508eeec7d19bce1904c8f3689e6632b01 Mon Sep 17 00:00:00 2001 From: l0gesh29 Date: Sun, 11 Jan 2026 13:52:46 +0530 Subject: [PATCH] fix: add validation for direct return (cherry picked from commit 8379b39aaf7a40ec416f64ee74f618d44cdadb05) --- .../accounts/doctype/sales_invoice/sales_invoice.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 53eb92a9b3f..059da953470 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -353,6 +353,9 @@ class SalesInvoice(SellingController): self.set_against_income_account() + if self.is_return and not self.return_against and self.timesheets: + frappe.throw(_("Direct return is not allowed for Timesheet.")) + if not self.is_return: self.validate_time_sheets_are_submitted() @@ -360,10 +363,10 @@ class SalesInvoice(SellingController): if self.is_return and self.return_against: for row in self.timesheets: - if row.billing_hours > 0: - row.billing_hours *= -1 - if row.billing_amount > 0: - row.billing_amount *= -1 + if row.billing_hours: + row.billing_hours = -abs(row.billing_hours) + if row.billing_amount: + row.billing_amount = -abs(row.billing_amount) self.update_packing_list() self.set_billing_hours_and_amount()