-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from CodeVenturers/gubbu_dev
feat: report print format
- Loading branch information
Showing
8 changed files
with
359 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
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,45 @@ | ||
|
||
import frappe | ||
import os | ||
from frappe.desk.query_report import get_report_doc | ||
from frappe.modules import get_module_path, scrub | ||
from frappe.model.utils import render_include | ||
|
||
|
||
@frappe.whitelist() | ||
def get_script(report_name): | ||
report = get_report_doc(report_name) | ||
module = report.module or frappe.db.get_value("DocType", report.ref_doctype, "module") | ||
|
||
is_custom_module = frappe.get_cached_value("Module Def", module, "custom") | ||
|
||
# custom modules are virtual modules those exists in DB but not in disk. | ||
module_path = "" if is_custom_module else get_module_path(module) | ||
report_folder = module_path and os.path.join(module_path, "report", scrub(report.name)) | ||
script_path = report_folder and os.path.join(report_folder, scrub(report.name) + ".js") | ||
|
||
script = None | ||
if os.path.exists(script_path): | ||
with open(script_path) as f: | ||
script = f.read() | ||
script += f"\n\n//# sourceURL={scrub(report.name)}.js" | ||
|
||
html_format = get_html_format() | ||
|
||
if not script and report.javascript: | ||
script = report.javascript | ||
script += f"\n\n//# sourceURL={scrub(report.name)}__custom" | ||
|
||
if not script: | ||
script = "frappe.query_reports['%s']={}" % report_name | ||
|
||
return { | ||
"script": render_include(script), | ||
"html_format": html_format, | ||
"execution_time": 0, | ||
"filters": report.filters, | ||
"custom_report_name": report.name if report.get("is_custom_report") else None, | ||
} | ||
|
||
def get_html_format(): | ||
return frappe.db.get_value("Report Print Format", "", "html") |
Empty file.
Empty file.
8 changes: 8 additions & 0 deletions
8
report_print/report_print/doctype/report_print_format/report_print_format.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,8 @@ | ||
// Copyright (c) 2024, Code Venturers and contributors | ||
// For license information, please see license.txt | ||
|
||
frappe.ui.form.on('Report Print Format', { | ||
// refresh: function(frm) { | ||
|
||
// } | ||
}); |
286 changes: 286 additions & 0 deletions
286
report_print/report_print/doctype/report_print_format/report_print_format.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,286 @@ | ||
{ | ||
"actions": [], | ||
"allow_rename": 1, | ||
"autoname": "Prompt", | ||
"creation": "2024-08-29 01:52:40.846934", | ||
"default_view": "List", | ||
"doctype": "DocType", | ||
"engine": "InnoDB", | ||
"field_order": [ | ||
"report", | ||
"module", | ||
"default_print_language", | ||
"column_break_3", | ||
"standard", | ||
"custom_format", | ||
"disabled", | ||
"section_break_6", | ||
"print_format_type", | ||
"raw_printing", | ||
"html", | ||
"raw_commands", | ||
"section_break_9", | ||
"margin_top", | ||
"margin_bottom", | ||
"margin_left", | ||
"margin_right", | ||
"align_labels_right", | ||
"show_section_headings", | ||
"line_breaks", | ||
"absolute_value", | ||
"column_break_11", | ||
"font_size", | ||
"font", | ||
"page_number", | ||
"css_section", | ||
"css", | ||
"custom_html_help", | ||
"section_break_13", | ||
"print_format_help", | ||
"format_data", | ||
"print_format_builder", | ||
"print_format_builder_beta" | ||
], | ||
"fields": [ | ||
{ | ||
"fieldname": "report", | ||
"fieldtype": "Link", | ||
"in_filter": 1, | ||
"in_list_view": 1, | ||
"in_standard_filter": 1, | ||
"label": "Report", | ||
"options": "Report", | ||
"reqd": 1 | ||
}, | ||
{ | ||
"fieldname": "module", | ||
"fieldtype": "Link", | ||
"label": "Module", | ||
"options": "Module Def" | ||
}, | ||
{ | ||
"fieldname": "default_print_language", | ||
"fieldtype": "Link", | ||
"label": "Default Print Language", | ||
"options": "Language" | ||
}, | ||
{ | ||
"fieldname": "column_break_3", | ||
"fieldtype": "Column Break" | ||
}, | ||
{ | ||
"default": "No", | ||
"fieldname": "standard", | ||
"fieldtype": "Select", | ||
"in_filter": 1, | ||
"label": "Standard", | ||
"no_copy": 1, | ||
"oldfieldname": "standard", | ||
"oldfieldtype": "Select", | ||
"options": "No\nYes", | ||
"reqd": 1, | ||
"search_index": 1 | ||
}, | ||
{ | ||
"default": "0", | ||
"fieldname": "custom_format", | ||
"fieldtype": "Check", | ||
"label": "Custom Format" | ||
}, | ||
{ | ||
"default": "0", | ||
"fieldname": "disabled", | ||
"fieldtype": "Check", | ||
"label": "Disabled" | ||
}, | ||
{ | ||
"depends_on": "custom_format", | ||
"fieldname": "section_break_6", | ||
"fieldtype": "Section Break" | ||
}, | ||
{ | ||
"default": "Jinja", | ||
"depends_on": "custom_format", | ||
"fieldname": "print_format_type", | ||
"fieldtype": "Select", | ||
"label": "Print Format Type", | ||
"options": "Jinja\nJS" | ||
}, | ||
{ | ||
"default": "0", | ||
"fieldname": "raw_printing", | ||
"fieldtype": "Check", | ||
"label": "Raw Printing" | ||
}, | ||
{ | ||
"depends_on": "eval:!doc.raw_printing", | ||
"fieldname": "html", | ||
"fieldtype": "Code", | ||
"label": "HTML", | ||
"oldfieldname": "html", | ||
"oldfieldtype": "Text Editor", | ||
"options": "Jinja" | ||
}, | ||
{ | ||
"depends_on": "raw_printing", | ||
"description": "Any string-based printer languages can be used. Writing raw commands requires knowledge of the printer's native language provided by the printer manufacturer. Please refer to the developer manual provided by the printer manufacturer on how to write their native commands. These commands are rendered on the server side using the Jinja Templating Language.", | ||
"fieldname": "raw_commands", | ||
"fieldtype": "Code", | ||
"label": "Raw Commands", | ||
"options": "Jinja" | ||
}, | ||
{ | ||
"depends_on": "eval:!doc.custom_format", | ||
"fieldname": "section_break_9", | ||
"fieldtype": "Section Break", | ||
"label": "Style Settings" | ||
}, | ||
{ | ||
"default": "15", | ||
"fieldname": "margin_top", | ||
"fieldtype": "Float", | ||
"label": "Margin Top" | ||
}, | ||
{ | ||
"default": "15", | ||
"fieldname": "margin_bottom", | ||
"fieldtype": "Float", | ||
"label": "Margin Bottom" | ||
}, | ||
{ | ||
"default": "15", | ||
"fieldname": "margin_left", | ||
"fieldtype": "Float", | ||
"label": "Margin Left" | ||
}, | ||
{ | ||
"default": "15", | ||
"fieldname": "margin_right", | ||
"fieldtype": "Float", | ||
"label": "Margin Right" | ||
}, | ||
{ | ||
"default": "0", | ||
"fieldname": "align_labels_right", | ||
"fieldtype": "Check", | ||
"label": "Align Labels to the Right" | ||
}, | ||
{ | ||
"default": "0", | ||
"fieldname": "show_section_headings", | ||
"fieldtype": "Check", | ||
"label": "Show Section Headings" | ||
}, | ||
{ | ||
"default": "0", | ||
"fieldname": "line_breaks", | ||
"fieldtype": "Check", | ||
"label": "Show Line Breaks after Sections" | ||
}, | ||
{ | ||
"default": "0", | ||
"depends_on": "doc_type", | ||
"description": "If checked, negative numeric values of Currency, Quantity or Count would be shown as positive", | ||
"fieldname": "absolute_value", | ||
"fieldtype": "Check", | ||
"label": "Show Absolute Values" | ||
}, | ||
{ | ||
"fieldname": "column_break_11", | ||
"fieldtype": "Column Break" | ||
}, | ||
{ | ||
"default": "14", | ||
"fieldname": "font_size", | ||
"fieldtype": "Int", | ||
"label": "Font Size" | ||
}, | ||
{ | ||
"depends_on": "eval:!doc.custom_format", | ||
"fieldname": "font", | ||
"fieldtype": "Data", | ||
"label": "Google Font" | ||
}, | ||
{ | ||
"default": "Hide", | ||
"fieldname": "page_number", | ||
"fieldtype": "Select", | ||
"label": "Page Number", | ||
"options": "Hide\nTop Left\nTop Center\nTop Right\nBottom Left\nBottom Center\nBottom Right" | ||
}, | ||
{ | ||
"depends_on": "eval:!doc.raw_printing", | ||
"fieldname": "css_section", | ||
"fieldtype": "Section Break" | ||
}, | ||
{ | ||
"fieldname": "css", | ||
"fieldtype": "Code", | ||
"label": "Custom CSS", | ||
"options": "CSS" | ||
}, | ||
{ | ||
"fieldname": "custom_html_help", | ||
"fieldtype": "HTML", | ||
"label": "Custom HTML Help", | ||
"options": "<h3>Custom CSS Help</h3>\n\n<p>Notes:</p>\n\n<ol>\n<li>All field groups (label + value) are set attributes <code>data-fieldtype</code> and <code>data-fieldname</code></li>\n<li>All values are given class <code>value</code></li>\n<li>All Section Breaks are given class <code>section-break</code></li>\n<li>All Column Breaks are given class <code>column-break</code></li>\n</ol>\n\n<h4>Examples</h4>\n\n<p>1. Left align integers</p>\n\n<pre><code>[data-fieldtype=\"Int\"] .value { text-align: left; }</code></pre>\n\n<p>1. Add border to sections except the last section</p>\n\n<pre><code>.section-break { padding: 30px 0px; border-bottom: 1px solid #eee; }\n.section-break:last-child { padding-bottom: 0px; border-bottom: 0px; }</code></pre>\n" | ||
}, | ||
{ | ||
"depends_on": "custom_format", | ||
"fieldname": "section_break_13", | ||
"fieldtype": "Section Break" | ||
}, | ||
{ | ||
"depends_on": "custom_format", | ||
"fieldname": "print_format_help", | ||
"fieldtype": "HTML", | ||
"label": "Print Format Help", | ||
"options": "<h3>Print Format Help</h3>\n<hr>\n<h4>Introduction</h4>\n<p>Print Formats are rendered on the server side using the Jinja Templating Language. All forms have access to the <code>doc</code> object which contains information about the document that is being formatted. You can also access common utilities via the <code>frappe</code> module.</p>\n<p>For styling, the Boostrap CSS framework is provided and you can enjoy the full range of classes.</p>\n<hr>\n<h4>References</h4>\n<ol>\n\t<li><a href=\"http://jinja.pocoo.org/docs/templates/\" target=\"_blank\">Jinja Templating Language</a></li>\n\t<li><a href=\"http://getbootstrap.com\" target=\"_blank\">Bootstrap CSS Framework</a></li>\n</ol>\n<hr>\n<h4>Example</h4>\n<pre><code><h3>{{ doc.select_print_heading or \"Invoice\" }}</h3>\n<div class=\"row\">\n\t<div class=\"col-md-3 text-right\">Customer Name</div>\n\t<div class=\"col-md-9\">{{ doc.customer_name }}</div>\n</div>\n<div class=\"row\">\n\t<div class=\"col-md-3 text-right\">Date</div>\n\t<div class=\"col-md-9\">{{ doc.get_formatted(\"invoice_date\") }}</div>\n</div>\n<table class=\"table table-bordered\">\n\t<tbody>\n\t\t<tr>\n\t\t\t<th>Sr</th>\n\t\t\t<th>Item Name</th>\n\t\t\t<th>Description</th>\n\t\t\t<th class=\"text-right\">Qty</th>\n\t\t\t<th class=\"text-right\">Rate</th>\n\t\t\t<th class=\"text-right\">Amount</th>\n\t\t</tr>\n\t\t{%- for row in doc.items -%}\n\t\t<tr>\n\t\t\t<td style=\"width: 3%;\">{{ row.idx }}</td>\n\t\t\t<td style=\"width: 20%;\">\n\t\t\t\t{{ row.item_name }}\n\t\t\t\t{% if row.item_code != row.item_name -%}\n\t\t\t\t<br>Item Code: {{ row.item_code}}\n\t\t\t\t{%- endif %}\n\t\t\t</td>\n\t\t\t<td style=\"width: 37%;\">\n\t\t\t\t<div style=\"border: 0px;\">{{ row.description }}</div></td>\n\t\t\t<td style=\"width: 10%; text-align: right;\">{{ row.qty }} {{ row.uom or row.stock_uom }}</td>\n\t\t\t<td style=\"width: 15%; text-align: right;\">{{\n\t\t\t\trow.get_formatted(\"rate\", doc) }}</td>\n\t\t\t<td style=\"width: 15%; text-align: right;\">{{\n\t\t\t\trow.get_formatted(\"amount\", doc) }}</td>\n\t\t</tr>\n\t\t{%- endfor -%}\n\t</tbody>\n</table></code></pre>\n<hr>\n<h4>Common Functions</h4>\n<table class=\"table table-bordered\">\n\t<tbody>\n\t\t<tr>\n\t\t\t<td style=\"width: 30%;\"><code>doc.get_formatted(\"[fieldname]\", [parent_doc])</code></td>\n\t\t\t<td>Get document value formatted as Date, Currency, etc. Pass parent <code>doc</code> for currency type fields.</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td style=\"width: 30%;\"><code>frappe.db.get_value(\"[doctype]\", \"[name]\", \"fieldname\")</code></td>\n\t\t\t<td>Get value from another document.</td>\n\t\t</tr>\n\t</tbody>\n</table>\n" | ||
}, | ||
{ | ||
"fieldname": "format_data", | ||
"fieldtype": "Code", | ||
"hidden": 1, | ||
"label": "Format Data" | ||
}, | ||
{ | ||
"default": "0", | ||
"fieldname": "print_format_builder", | ||
"fieldtype": "Check", | ||
"hidden": 1, | ||
"label": "Print Format Builder" | ||
}, | ||
{ | ||
"default": "0", | ||
"fieldname": "print_format_builder_beta", | ||
"fieldtype": "Check", | ||
"label": "Print Format Builder Beta" | ||
} | ||
], | ||
"icon": "fa fa-print", | ||
"index_web_pages_for_search": 1, | ||
"links": [], | ||
"modified": "2024-08-29 01:52:40.846934", | ||
"modified_by": "Administrator", | ||
"module": "Report Print", | ||
"name": "Report Print Format", | ||
"naming_rule": "Set by user", | ||
"owner": "Administrator", | ||
"permissions": [ | ||
{ | ||
"create": 1, | ||
"delete": 1, | ||
"email": 1, | ||
"print": 1, | ||
"read": 1, | ||
"report": 1, | ||
"role": "System Manager", | ||
"share": 1, | ||
"write": 1 | ||
} | ||
], | ||
"sort_field": "modified", | ||
"sort_order": "DESC", | ||
"states": [], | ||
"track_changes": 1 | ||
} |
8 changes: 8 additions & 0 deletions
8
report_print/report_print/doctype/report_print_format/report_print_format.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,8 @@ | ||
# Copyright (c) 2024, Code Venturers and contributors | ||
# For license information, please see license.txt | ||
|
||
# import frappe | ||
from frappe.model.document import Document | ||
|
||
class ReportPrintFormat(Document): | ||
pass |
9 changes: 9 additions & 0 deletions
9
report_print/report_print/doctype/report_print_format/test_report_print_format.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,9 @@ | ||
# Copyright (c) 2024, Code Venturers and Contributors | ||
# See license.txt | ||
|
||
# import frappe | ||
from frappe.tests.utils import FrappeTestCase | ||
|
||
|
||
class TestReportPrintFormat(FrappeTestCase): | ||
pass |