mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-31 18:59:08 +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"):
|
def get_timesheets_list(doctype, txt, filters, limit_start, limit_page_length=20, order_by="modified"):
|
||||||
user = frappe.session.user
|
user = frappe.session.user
|
||||||
# find customer name from contact.
|
# find customer name from contact.
|
||||||
customer = frappe.db.sql('''SELECT dl.link_name FROM `tabContact` AS c inner join \
|
customer = ''
|
||||||
`tabDynamic Link` AS dl ON c.first_name=dl.link_name WHERE c.email_id=%s''',user)
|
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:
|
if customer:
|
||||||
# find list of Sales Invoice for made for customer.
|
sales_invoices = [d.name for d in frappe.get_all('Sales Invoice', filters={'customer': customer})] or [None]
|
||||||
sales_invoice = frappe.db.sql('''SELECT name FROM `tabSales Invoice` WHERE customer = %s''',customer)
|
projects = [d.name for d in frappe.get_all('Project', filters={'customer': customer})]
|
||||||
# Return timesheet related data to web portal.
|
# Return timesheet related data to web portal.
|
||||||
return frappe. db.sql('''SELECT ts.name, tsd.activity_type, ts.status, ts.total_billable_hours, \
|
timesheets = frappe.db.sql('''
|
||||||
tsd.sales_invoice, tsd.project FROM `tabTimesheet` AS ts inner join `tabTimesheet Detail` \
|
SELECT
|
||||||
AS tsd ON tsd.parent = ts.name where tsd.sales_invoice IN %s order by\
|
ts.name, tsd.activity_type, ts.status, ts.total_billable_hours,
|
||||||
end_date asc limit {0} , {1}'''.format(limit_start, limit_page_length), [sales_invoice], as_dict = True)
|
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):
|
def get_list_context(context=None):
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
<div class="web-list-item">
|
<div class="web-list-item transaction-list-item">
|
||||||
<a href="/timesheets?name={{ doc.name | urlencode }}" class="no-decoration">
|
<div class="row">
|
||||||
<div class="row">
|
<div class="col-xs-3">
|
||||||
<div class="col-xs-3">
|
<span class='indicator {{ "red" if doc.status=="Cancelled" else "green" if doc.status=="Billed" else "blue" if doc.status=="Submitted" else "darkgrey" }} small'>
|
||||||
<span class="indicator {{ "red" if doc.status=="Cancelled" else "green" if doc.status=="Billed" else "blue" if doc.status=="Submitted" else "darkgrey" }}">{{ doc.name }}</span>
|
{{ doc.name }}
|
||||||
</div>
|
</span>
|
||||||
<div class="col-xs-3"> Billable Hours: {{ doc.total_billable_hours}} </div>
|
|
||||||
<div class="col-xs-2"> {{ _(doc.sales_invoice) }} </div>
|
|
||||||
<div class="col-xs-2"> {{ _(doc.project) }} </div>
|
|
||||||
<div class="col-xs-2"> {{ _(doc.activity_type) }} </div>
|
|
||||||
</div>
|
</div>
|
||||||
</a>
|
<div class="col-xs-2 small"> {{ doc.total_billable_hours }} </div>
|
||||||
|
<div class="col-xs-2 small"> {{ doc.project or '' }} </div>
|
||||||
|
<div class="col-xs-2 small"> {{ doc.sales_invoice or '' }} </div>
|
||||||
|
<div class="col-xs-2 small"> {{ _(doc.activity_type) }} </div>
|
||||||
|
</div>
|
||||||
|
<!-- <a href="/timesheets?name={{ doc.name | urlencode }}" class="transaction-item-link">Link</a> -->
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user