i add this code when the print button is clicked
def print_format(doctype, data):
try:
property_setters = frappe.get_all(
"Property Setter",
filters={
"doc_type": ["in", ["Payment Entry", "Journal Entry"]],
"property": ["=", "default_print_format"],
},
fields=["name"],
)
if len(property_setters) == 1:
frappe.db.set_value(
"Property Setter",
property_setters[0].name,
"doc_type",
doctype,
)
frappe.db.set_value(
"Print Format",
"Variable Print Format",
{"doc_type": doctype, "html": data},
)
return 0
except:
return -1
then when the print view display it must set the print format Variable Print Format in print format filter not select it manually
// Print type of Journal Entry
frappe.ui.form.on('Journal Entry Account', {
custom_print(frm, cdt, cdn) {
let row = frappe.get_doc(cdt, cdn);
id = row.idx - 1
data = '<style>.print-format { display: flex; justify-content: center; /* توسّط الشيك أفقيًا */ height: 100vh; /* يتأكد من أن الحاوية تأخذ ارتفاع الشاشة بالكامل */ margin: 0; /* إزالة الهوامش الافتراضية إذا كانت موجودة */ padding: 0; /* إزالة التباعد الداخلي إذا كان موجودًا */ box-sizing: border-box; /* يتأكد من أن التباعد يتم حسابه بشكل صحيح */ /*border:1px;*/ font-size:16px; font-weight:bold;} .cheque { /*background-repeat: repeat-y;*/ /*background-size: cover;*/ width: 9cm; height: 20cm; /*border: 3px solid;*/ margin-top: 0cm; writing-mode: vertical-rl; /*position: static;*/ /*bottom:0px;*/ }.year{ /*top:12.7cm;*/ position: relative; /*bottom:7.6cm;*/ bottom:8.6cm; left:-1.5cm;}.month{ /*top:12.7cm;*/ position: relative; /*bottom:5.8cm;*/ bottom:6.6cm; left:-1.5cm;}.day{ /*top:12.7cm;*/ position: relative; /*bottom:4.1cm;*/ bottom:5cm; left:-1.5cm;}.name{position: relative; /*text-align: center; */ width: 100%; bottom:5.5cm;/*left:-3cm;*/left:-3.1cm;}.amount_word{ position: relative; /*bottom:2cm; */ bottom:6cm; left:-3.1cm; /*text-align: center; */ /*width: 100%; */ /*line-height:0.5cm; */ /*word-wrap: break-word;*/}.amount{ position: relative; /*top:7cm; */ top:3.48cm; /*left:-5.3cm; */ left:-4.1cm; text-align: center; width: 100%; writing-mode: vertical-rl;}</style><div class="print-format"> <div class="cheque "> <span class="year"> {{frappe.utils.formatdate(doc.posting_date, "yyyy") or "" }} </span> <span class="month"> {{frappe.utils.formatdate(doc.posting_date, "MM") or "" }} </span> <span class="day"> {{frappe.utils.formatdate(doc.posting_date, "dd") or "" }} </span> <span class="name"> {{doc.accounts[' + id + '].user_remark}} </span> <p class="amount_word"> {% set x = doc.accounts[' + id + '].debit_in_account_currency if doc.accounts[' + id + '].debit_in_account_currency else doc.accounts[' + id + '].credit_in_account_currency %} {{" ".join(frappe.utils.money_in_words(x).split()[1:-1]) }} {{frappe.utils.money_in_words(x).split()[0]}} فقط </p> <p class="amount"> {% set x = "debit_in_account_currency" if doc.accounts[' + id + '].debit_in_account_currency else "credit_in_account_currency" %} {{doc.accounts[' + id + '].get_formatted(x).split()[1]}} {{doc.accounts[' + id + '].get_formatted(x).split()[0]}} </p> </div></div>';
frappe.call({
method: 'test_app.my_scripts.print.print_format',
args: {
doctype: frm.doc.doctype,
data: data
},
async: false
}).done((r) => {
if (r.message == 0) {
navigateToPrintFormatUI(frm);
}
})
}
});
function navigateToPrintFormatUI(frm) {
var docName = frm.doc.name;
var doctype = 'Journal Entry';
var printFormatUrl = `/app/print/${encodeURIComponent(doctype)}/${encodeURIComponent(docName)}`;
window.location.href = frappe.urllib.get_full_url(printFormatUrl);
}
as you see i but the async FALSE too