-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* File Preview (#140) * wip: file preview * feat: preview in check run, allow to preview in non submittable documents * feat: WIP payables attachment report * feat: wip preview of attachments * style: prettify code * feat: close with space * fix: do not open sidebar in check run * wip: multiple attachments in check run * fix: merge * style: prettify code * fix: df-preview-wrapper-fw * feat: improve code * feat: improve code * feat: columns --------- Co-authored-by: Tyler Matteson <[email protected]> Co-authored-by: fproldan <[email protected]> * feat: use query builder in payables attachments report' * fix: build * fix: add remove btn * style: prettify code --------- Co-authored-by: Tyler Matteson <[email protected]> Co-authored-by: fproldan <[email protected]>
- Loading branch information
1 parent
a3cfc97
commit 78d2666
Showing
11 changed files
with
382 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
13 changes: 13 additions & 0 deletions
13
check_run/check_run/report/payables_attachments/payables_attachments.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) 2023, AgriTheory and contributors | ||
// For license information, please see license.txt | ||
/* eslint-disable */ | ||
|
||
frappe.query_reports['Payables Attachments'] = { | ||
filters: [], | ||
} | ||
|
||
frappe.ui.addFilePreviewWrapper() | ||
|
||
function pdf_preview(file_url) { | ||
frappe.ui.pdfPreview(cur_frm, file_url) | ||
} |
35 changes: 35 additions & 0 deletions
35
check_run/check_run/report/payables_attachments/payables_attachments.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"add_total_row": 0, | ||
"columns": [], | ||
"creation": "2023-08-11 10:09:28.938669", | ||
"disable_prepared_report": 0, | ||
"disabled": 0, | ||
"docstatus": 0, | ||
"doctype": "Report", | ||
"filters": [], | ||
"idx": 0, | ||
"is_standard": "Yes", | ||
"modified": "2023-08-11 10:09:28.938669", | ||
"modified_by": "Administrator", | ||
"module": "Check Run", | ||
"name": "Payables Attachments", | ||
"owner": "Administrator", | ||
"prepared_report": 0, | ||
"ref_doctype": "Purchase Invoice", | ||
"report_name": "Payables Attachments", | ||
"report_type": "Script Report", | ||
"roles": [ | ||
{ | ||
"role": "Accounts User" | ||
}, | ||
{ | ||
"role": "Purchase User" | ||
}, | ||
{ | ||
"role": "Accounts Manager" | ||
}, | ||
{ | ||
"role": "Auditor" | ||
} | ||
] | ||
} |
145 changes: 145 additions & 0 deletions
145
check_run/check_run/report/payables_attachments/payables_attachments.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
# Copyright (c) 2022, AgriTheory and contributors | ||
# For license information, please see license.txt | ||
|
||
import frappe | ||
from frappe.desk.form.load import get_attachments | ||
from frappe.query_builder import DocType | ||
from pypika import Order | ||
|
||
|
||
def execute(filters=None): | ||
return get_columns(filters), get_data(filters) | ||
|
||
def get_data(filters): | ||
PurchaseInvoice = DocType("Purchase Invoice") | ||
data = ( | ||
frappe.qb.from_(PurchaseInvoice) | ||
.select( | ||
PurchaseInvoice.name, PurchaseInvoice.title, PurchaseInvoice.supplier, PurchaseInvoice.company, | ||
PurchaseInvoice.posting_date, PurchaseInvoice.grand_total, PurchaseInvoice.status, PurchaseInvoice.currency, | ||
PurchaseInvoice.supplier_name, PurchaseInvoice.grand_total, PurchaseInvoice.outstanding_amount, | ||
PurchaseInvoice.due_date, PurchaseInvoice.is_return, PurchaseInvoice.release_date, PurchaseInvoice.represents_company, | ||
PurchaseInvoice.is_internal_supplier | ||
) | ||
.orderby('modified', Order.desc) | ||
).run(as_dict=True) | ||
|
||
for row in data: | ||
row['attachments'] = " ".join([ | ||
f"""<a data-pdf-preview="{attachment.file_url}" onclick="pdf_preview('{attachment.file_url}')">{attachment.file_name}</a>""" | ||
for attachment in get_attachments('Purchase Invoice', row['name']) if attachment.file_url.endswith('.pdf') | ||
]) | ||
return data | ||
|
||
def get_columns(filters): | ||
return [ | ||
|
||
{ | ||
"label": frappe._("Name"), | ||
"fieldname": "name", | ||
"fieldtype": "Link", | ||
"options": "Purchase Invoice", | ||
"width": "150px", | ||
}, | ||
{ | ||
"label": frappe._("Title"), | ||
"fieldname": "title", | ||
"fieldtype": "Data", | ||
"width": "200px", | ||
}, | ||
{ | ||
"label": frappe._("Supplier"), | ||
"fieldname": "supplier", | ||
"fieldtype": "Link", | ||
"options": "Supplier", | ||
"width": "200px", | ||
}, | ||
{ | ||
"label": frappe._("Supplier Name"), | ||
"fieldname": "supplier_name", | ||
"fieldtype": "Data", | ||
"width": "200px", | ||
}, | ||
{ | ||
"label": frappe._("Company"), | ||
"fieldname": "company", | ||
"fieldtype": "Link", | ||
"options": "Company", | ||
"width": "200px", | ||
}, | ||
{ | ||
"label": frappe._("Date"), | ||
"fieldname": "posting_date", | ||
"fieldtype": "Date", | ||
"width": "200px", | ||
}, | ||
{ | ||
"label": frappe._("Grand Total"), | ||
"fieldname": "grand_total", | ||
"fieldtype": "Currency", | ||
"width": "200px", | ||
}, | ||
{ | ||
"label": frappe._("Status"), | ||
"fieldname": "status", | ||
"fieldtype": "Data", | ||
"width": "200px", | ||
}, | ||
{ | ||
"label": frappe._("Currency"), | ||
"fieldname": "currency", | ||
"fieldtype": "Link", | ||
"options": "Currency", | ||
"width": "200px", | ||
}, | ||
{ | ||
"label": frappe._("Grand Total (Company Currency)"), | ||
"fieldname": "grand_total", | ||
"fieldtype": "Currency", | ||
"width": "200px", | ||
}, | ||
{ | ||
"label": frappe._("Outstanding Amount"), | ||
"fieldname": "outstanding_amount", | ||
"fieldtype": "Currency", | ||
"width": "200px", | ||
}, | ||
{ | ||
"label": frappe._("Due Date"), | ||
"fieldname": "due_date", | ||
"fieldtype": "Date", | ||
"width": "200px", | ||
}, | ||
{ | ||
"label": frappe._("Is Return (Debit Note)"), | ||
"fieldname": "is_return", | ||
"fieldtype": "Check", | ||
"width": "200px", | ||
}, | ||
{ | ||
"label": frappe._("Release Date"), | ||
"fieldname": "release_date", | ||
"fieldtype": "Date", | ||
"width": "200px", | ||
}, | ||
{ | ||
"label": frappe._("Represents Company"), | ||
"fieldname": "represents_company", | ||
"fieldtype": "Link", | ||
"options": "Company", | ||
"width": "200px", | ||
}, | ||
{ | ||
"label": frappe._("Is Internal Supplier"), | ||
"fieldname": "is_internal_supplier", | ||
"fieldtype": "Check", | ||
"width": "200px", | ||
}, | ||
{ | ||
"label": frappe._("Attachments"), | ||
"fieldname": "attachments", | ||
"fieldtype": "Data", | ||
"width": "400px", | ||
}, | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
.fa-file-pdf-o { | ||
font-size: 120%; | ||
padding-left: 0.5ch; | ||
color: var(--brand-secondary); | ||
} | ||
#close-pdf-button { | ||
position: absolute; | ||
top: 10px; | ||
right: 10px; | ||
} | ||
#pdf-preview-wrapper { | ||
position: fixed; | ||
width: calc(1290px / 2); | ||
height: calc(100vh - 135px); | ||
top: 135px; | ||
right: calc((100vw - 1290px) / 2); | ||
display: none; | ||
} | ||
#pdf-preview-wrapper.pdf-preview-wrapper-fw { | ||
width: calc(90vw / 2); | ||
height: calc(100vh - 135px); | ||
right: calc(10vw / 2); | ||
} | ||
#pdf-preview-wrapper.pdf-preview-wrapper-fw #pdf-preview { | ||
width: calc(90vw / 2); | ||
} | ||
.page-body.show-pdf-preview #pdf-preview-wrapper { | ||
display: block; | ||
} | ||
#pdf-preview { | ||
position: absolute; | ||
top: 50px; | ||
left: 0; | ||
right: 0; | ||
bottom: 0; | ||
width: calc(1290px / 2); | ||
height: calc(100vh - 135px - 20px); | ||
} | ||
.page-body.show-pdf-preview .page-wrapper .page-content { | ||
width: calc(50% - 10px); | ||
} | ||
|
||
.portal-widget { | ||
position: absolute; | ||
top: 5px; | ||
right:5px; | ||
bottom:5px; | ||
left:5px; | ||
border-radius: 5px; | ||
box-shadow: 0px 1px 2px rgba(25, 39, 52, 0.05), 0px 0px 4px rgba(25, 39, 52, 0.1); | ||
} | ||
a.portal-widget-col { | ||
position: relative; | ||
padding: 20px; | ||
text-decoration: none; | ||
} | ||
|
||
.widget-row { | ||
margin-top: 10px; | ||
margin-bottom: 20px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
import './check_run/check_run_quick_entry.js' | ||
import './check_run/check_run.js' | ||
import './custom/file_preview.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.