[print] Print Settings -> With Letterhead, defaults the Letterhead checkbox in Print Preview

This commit is contained in:
Anand Doshi 2014-07-31 17:32:54 +05:30
parent 065b53ab3d
commit 4d8b65b22f
6 changed files with 41 additions and 9 deletions

View file

@ -51,7 +51,7 @@ def get_bootinfo():
load_translations(bootinfo)
add_timezone_info(bootinfo)
load_conf_settings(bootinfo)
load_print_css(bootinfo)
load_print(bootinfo, doclist)
# ipinfo
if frappe.session['data'].get('ipinfo'):
@ -150,6 +150,11 @@ def add_timezone_info(bootinfo):
frappe.utils.momentjs.update(user, bootinfo.timezone_info)
frappe.utils.momentjs.update(system, bootinfo.timezone_info)
def load_print_css(bootinfo):
bootinfo.print_css = frappe.get_attr("frappe.templates.pages.print.get_print_style")(frappe.db.get_single_value("Print Settings",
"print_style") or "Modern")
def load_print(bootinfo, doclist):
print_settings = frappe.db.get_singles_dict("Print Settings")
print_settings.doctype = ":Print Settings"
doclist.append(print_settings)
load_print_css(bootinfo, print_settings)
def load_print_css(bootinfo, print_settings):
bootinfo.print_css = frappe.get_attr("frappe.templates.pages.print.get_print_style")(print_settings.print_style or "Modern")

View file

@ -53,6 +53,15 @@
"label": "Font Size",
"permlevel": 0
},
{
"default": "1",
"description": "Print with Letterhead, unless unchecked in a particular Document",
"fieldname": "with_letterhead",
"fieldtype": "Check",
"label": "With Letterhead",
"permlevel": 0,
"reqd": 0
},
{
"fieldname": "section_break_8",
"fieldtype": "Section Break",
@ -67,7 +76,7 @@
],
"icon": "icon-cog",
"issingle": 1,
"modified": "2014-07-31 06:25:45.297096",
"modified": "2014-07-31 07:43:54.550258",
"modified_by": "Administrator",
"module": "Core",
"name": "Print Settings",

View file

@ -49,3 +49,4 @@ frappe.patches.v4_1.enable_print_as_pdf #2014-06-17
execute:frappe.db.sql("""update `tabDocPerm` set email=1 where parent='User' and permlevel=0 and `role`='All' and `read`=1 and apply_user_permissions=1""") #2014-07-15
execute:frappe.db.sql("""update `tabPrint Format` set print_format_type='Client' where ifnull(print_format_type, '')=''""") #2014-07-28
frappe.patches.v4_1.file_manager_fix
frappe.patches.v4_2.print_with_letterhead

View file

@ -0,0 +1,11 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
frappe.reload_doc("core", "doctype", "print_settings")
print_settings = frappe.get_doc("Print Settings")
print_settings.with_letterhead = 1
print_settings.save()

View file

@ -14,7 +14,7 @@ frappe.ui.form.PrintPreview = Class.extend({
<div class="col-xs-3">\
<select class="print-preview-select form-control"></select></div>\
<div class="col-xs-3">\
<div class="checkbox"><label><input type="checkbox" class="print-letterhead" checked/> Letterhead</label></div></div>\
<div class="checkbox"><label><input type="checkbox" class="print-letterhead" /> Letterhead</label></div></div>\
<div class="col-xs-6 text-right" style="padding-top: 7px;">\
<a style="margin-right: 7px;" class="btn-print-preview text-muted small">Preview</a>\
<a style="margin-right: 7px;" class="btn-download-pdf text-muted small">Download PDF</a>\
@ -38,7 +38,10 @@ frappe.ui.form.PrintPreview = Class.extend({
this.print_formats = frappe.meta.get_print_formats(this.frm.meta.name);
this.print_letterhead = this.wrapper
.find(".print-letterhead")
.on("change", function() { me.print_sel.trigger("change"); });
.on("change", function() { me.print_sel.trigger("change"); })
.prop("checked", cint(
(frappe.model.get_doc(":Print Settings", "Print Settings")
|| {with_letterhead: 1}).with_letterhead) ? true : false);
this.print_sel = this.wrapper
.find(".print-preview-select")
.on("change", function() {
@ -72,7 +75,8 @@ frappe.ui.form.PrintPreview = Class.extend({
var w = window.open("/api/method/frappe.templates.pages.print.download_pdf?"
+"doctype="+encodeURIComponent(me.frm.doc.doctype)
+"&name="+encodeURIComponent(me.frm.doc.name)
+"&format="+me.selected_format());
+"&format="+me.selected_format()
+"&no_letterhead="+(me.with_letterhead() ? "0" : "1"));
if(!w) {
msgprint(__("Please enable pop-ups")); return;
}

View file

@ -42,10 +42,12 @@ def get_context(context):
@frappe.whitelist()
def get_html(doc, name=None, print_format=None, meta=None,
no_letterhead=False, trigger_print=False):
no_letterhead=None, trigger_print=False):
if isinstance(no_letterhead, basestring):
no_letterhead = cint(no_letterhead)
elif no_letterhead is None:
no_letterhead = not cint(frappe.db.get_single_value("Print Settings", "with_letterhead"))
if isinstance(doc, basestring) and isinstance(name, basestring):
doc = frappe.get_doc(doc, name)