Skip to content

Commit

Permalink
fix: raw_cmd, raw_cmd language select handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
IamSaiyyamChhetri authored and IamSaiyyamChhetri committed Jun 3, 2024
1 parent e5eb000 commit 6059928
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
21 changes: 13 additions & 8 deletions print_designer/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ def get_raw_cmd_render_pd(doc: str, name: str | None = None, print_format: str |
document = frappe.get_doc(json.loads(doc))
document.check_permission()
print_format = get_print_format_doc(print_format, meta=document.meta)
return { 'raw_commands' : get_rendered_template_pd(doc=document, print_format=print_format)}

return get_rendered_template_pd(doc=document, print_format=print_format)


def get_rendered_template_pd(
Expand Down Expand Up @@ -172,19 +173,23 @@ def get_rendered_template_pd(

raw_cmd_lang = settings.get('page').get('rawCmdLang')
if raw_cmd_lang is None:
return f"<h1><b>Please select the Raw Command language from Print Designer.</b>"
return {'status' : False, 'msg' : 'Language is not selected from Print Designer'}

for set_type in element_List:
for element in element_List[set_type]:
try :
rawCmdBeforeEle = element.get('childrens')[0].get('rawCmdBeforeEle', ' ').strip()
rawCmdAfterEle = element.get('childrens')[0].get('rawCmdAfterEle', ' ').strip()

if rawCmdBeforeEle != "":
if rawCmdBeforeEle != "" and rawCmdBeforeEle != 'custom':
rawCmdBeforeEle = convert_str_raw_cmd(rawCmdBeforeEle, raw_cmd_lang)

if rawCmdAfterEle != "":
elif rawCmdBeforeEle == 'custom':
rawCmdBeforeEle = element.get('childrens')[0].get('customRawCmdBeforeEle', ' ').strip()

if rawCmdAfterEle != "" and rawCmdAfterEle != 'custom':
rawCmdAfterEle = convert_str_raw_cmd(rawCmdAfterEle, raw_cmd_lang)
elif rawCmdAfterEle == 'custom':
rawCmdAfterEle = element.get('childrens')[0].get('customRawCmdAfterEle', ' ').strip()

args.update({"element": [element]})
#Need to change options value to raw_cmd
Expand All @@ -196,11 +201,11 @@ def get_rendered_template_pd(
except Exception as e :
error = log_error(title=e, reference_doctype="Print Format", reference_name=print_format.name)
if frappe.conf.developer_mode:
return f"<h1><b>Something went wrong while rendering the print format.</b> <hr/> If you don't know what just happened, and wish to file a ticket or issue on Github <hr /> Please copy the error from <code>Error Log {error.name}</code> or ask Administrator.<hr /><h3>Error rendering print format: {error.reference_name}</h3><h4>{error.method}</h4><pre>{html.escape(error.error)}</pre>"
return { 'status' : False, 'msg' : f"<h1><b>Something went wrong while rendering the print format.</b> <hr/> If you don't know what just happened, and wish to file a ticket or issue on Github <hr /> Please copy the error from <code>Error Log {error.name}</code> or ask Administrator.<hr /><h3>Error rendering print format: {error.reference_name}</h3><h4>{error.method}</h4><pre>{html.escape(error.error)}</pre>"}
else:
return f"<h1><b>Something went wrong while rendering the print format.</b> <hr/> If you don't know what just happened, and wish to file a ticket or issue on Github <hr /> Please copy the error from <code>Error Log {error.name}</code> or ask Administrator.</h1>"
return { 'status' : False, 'msg' : f"<h1><b>Something went wrong while rendering the print format.</b> <hr/> If you don't know what just happened, and wish to file a ticket or issue on Github <hr /> Please copy the error from <code>Error Log {error.name}</code> or ask Administrator.</h1>"}

return html_with_raw_cmd_list
return {'status' : True, 'raw_commands' : html_with_raw_cmd_list}

def convert_str_raw_cmd(raw_string, printer_lang):
str_cmd_dict = {
Expand Down
4 changes: 4 additions & 0 deletions print_designer/print_designer/client_scripts/print.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ frappe.ui.form.PrintView = class PrintView extends frappe.ui.form.PrintView {
frappe.ui.form
.qz_connect()
.then(function () {
if(!out.status){
frappe.throw(out.msg)
}

let printer_map = me.get_mapped_printer()[0];
let config = qz.configs.create(printer_map.printer);
return qz.print(config, out.raw_commands);
Expand Down
9 changes: 9 additions & 0 deletions print_designer/public/js/print_designer/store/ElementStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,15 @@ export const useElementStore = defineStore("ElementStore", {
});
throw new Error(message);
}
if (MainStore.frappeControls['rawCmdLang'].value == null){
frappe.show_alert(
{
message: "Please select the language for raw cmd",
indicator: "red",
});
throw new Error('Please select the language for raw cmd');
}

const tableElement = this.Elements.filter((el) => el.type == "table");
if(this.isParentElementOverlapping(elements)){
throwOverlappingError("element", false);
Expand Down

0 comments on commit 6059928

Please sign in to comment.