fix(timesheet): handle empty allowed projects (backport #58745) (#58746)

Co-authored-by: Krishna Pramod Shirsath <91021227+krishna-254@users.noreply.github.com>
Co-authored-by: Diptanil Saha <diptanil@frappe.io>
This commit is contained in:
mergify[bot]
2026-09-04 07:02:33 +00:00
committed by GitHub
parent a1c8dc878d
commit f75601e9b1
2 changed files with 15 additions and 3 deletions

View File

@@ -1,7 +1,7 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
import datetime
import unittest
from unittest.mock import patch
import frappe
from frappe.utils import add_to_date, now_datetime, nowdate
@@ -9,12 +9,20 @@ from frappe.utils import add_to_date, now_datetime, nowdate
from erpnext.accounts.doctype.sales_invoice.sales_invoice import make_sales_return
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
from erpnext.projects.doctype.task.test_task import create_task
from erpnext.projects.doctype.timesheet.timesheet import OverlapError, make_sales_invoice
from erpnext.projects.doctype.timesheet.timesheet import (
OverlapError,
get_projectwise_timesheet_data,
make_sales_invoice,
)
from erpnext.setup.doctype.employee.test_employee import make_employee
from erpnext.tests.utils import ERPNextTestSuite
class TestTimesheet(ERPNextTestSuite):
def test_get_projectwise_timesheet_data_without_allowed_projects(self):
with patch("frappe.get_list", side_effect=[["TS-0001"], []]):
self.assertEqual(get_projectwise_timesheet_data(), [])
def test_timesheet_post_update(self):
frappe.get_doc(
{

View File

@@ -335,10 +335,14 @@ def get_projectwise_timesheet_data(project=None, parent=None, from_time=None, to
& (tsd.is_billable == 1)
& tsd.sales_invoice.isnull()
& (tsd.parent.isin(allowed_timesheets))
& ((tsd.project.isin(allowed_projects)) | (tsd.project.isnull()))
)
)
if allowed_projects:
query = query.where((tsd.project.isin(allowed_projects)) | (tsd.project.isnull()))
else:
query = query.where(tsd.project.isnull())
if project:
query = query.where(tsd.project == project)
if parent: