mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-24 15:39:20 +00:00
feat: Show timesheets related to customer's projects on customer portal (#19443)
* fix: Show timesheets related to customer's projects on customer portal * style: fix codacy
This commit is contained in:
@@ -353,17 +353,35 @@ def get_events(start, end, filters=None):
|
||||
def get_timesheets_list(doctype, txt, filters, limit_start, limit_page_length=20, order_by="modified"):
|
||||
user = frappe.session.user
|
||||
# find customer name from contact.
|
||||
customer = frappe.db.sql('''SELECT dl.link_name FROM `tabContact` AS c inner join \
|
||||
`tabDynamic Link` AS dl ON c.first_name=dl.link_name WHERE c.email_id=%s''',user)
|
||||
customer = ''
|
||||
timesheets = []
|
||||
|
||||
contact = frappe.db.exists('Contact', {'user': user})
|
||||
if contact:
|
||||
# find customer
|
||||
contact = frappe.get_doc('Contact', contact)
|
||||
customer = contact.get_link_for('Customer')
|
||||
|
||||
if customer:
|
||||
# find list of Sales Invoice for made for customer.
|
||||
sales_invoice = frappe.db.sql('''SELECT name FROM `tabSales Invoice` WHERE customer = %s''',customer)
|
||||
sales_invoices = [d.name for d in frappe.get_all('Sales Invoice', filters={'customer': customer})] or [None]
|
||||
projects = [d.name for d in frappe.get_all('Project', filters={'customer': customer})]
|
||||
# Return timesheet related data to web portal.
|
||||
return frappe. db.sql('''SELECT ts.name, tsd.activity_type, ts.status, ts.total_billable_hours, \
|
||||
tsd.sales_invoice, tsd.project FROM `tabTimesheet` AS ts inner join `tabTimesheet Detail` \
|
||||
AS tsd ON tsd.parent = ts.name where tsd.sales_invoice IN %s order by\
|
||||
end_date asc limit {0} , {1}'''.format(limit_start, limit_page_length), [sales_invoice], as_dict = True)
|
||||
timesheets = frappe.db.sql('''
|
||||
SELECT
|
||||
ts.name, tsd.activity_type, ts.status, ts.total_billable_hours,
|
||||
COALESCE(ts.sales_invoice, tsd.sales_invoice) AS sales_invoice, tsd.project
|
||||
FROM `tabTimesheet` ts, `tabTimesheet Detail` tsd
|
||||
WHERE tsd.parent = ts.name AND
|
||||
(
|
||||
ts.sales_invoice IN %(sales_invoices)s OR
|
||||
tsd.sales_invoice IN %(sales_invoices)s OR
|
||||
tsd.project IN %(projects)s
|
||||
)
|
||||
ORDER BY `end_date` ASC
|
||||
LIMIT {0}, {1}
|
||||
'''.format(limit_start, limit_page_length), dict(sales_invoices=sales_invoices, projects=projects), as_dict=True) #nosec
|
||||
|
||||
return timesheets
|
||||
|
||||
def get_list_context(context=None):
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user