Skip to content

Commit 6867dc4

Browse files
authored
feat: make handling units respect config, add defaults (#309)
1 parent a45b89f commit 6867dc4

File tree

3 files changed

+62
-41
lines changed

3 files changed

+62
-41
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ repos:
5555
- tomli
5656

5757
- repo: https://github.com/agritheory/test_utils
58-
rev: v1.7.1
58+
rev: v1.12.0
5959
hooks:
6060
- id: update_pre_commit_config
6161
- id: validate_copyright

beam/beam/boot.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
11
# Copyright (c) 2025, AgriTheory and contributors
22
# For license information, please see license.txt
33

4+
import frappe
45

56
from beam.beam.scan.config import get_scan_doctypes
67

78

89
def boot_session(bootinfo):
910
bootinfo.beam = get_scan_doctypes()
11+
bootinfo.beam["settings"] = get_beam_settings()
12+
bootinfo.beam["default_hu_print_format"] = frappe.get_meta("Handling Unit").get(
13+
"default_print_format"
14+
)
15+
16+
17+
def get_beam_settings():
18+
"""Get BEAM Settings for all companies, keyed by company name."""
19+
settings = {}
20+
beam_settings = frappe.get_all(
21+
"BEAM Settings",
22+
fields=["company", "enable_handling_units"],
23+
)
24+
for setting in beam_settings:
25+
settings[setting.company] = {
26+
"enable_handling_units": setting.enable_handling_units,
27+
}
28+
return settings

beam/public/js/print/print.js

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -40,47 +40,49 @@ function custom_print_button(frm) {
4040
if (frm.doc.docstatus != 1) {
4141
return
4242
}
43-
frappe.db.get_value('BEAM Settings', { company: frm.doc.company }, 'enable_handling_units', r => {
44-
if (r && r.enable_handling_units) {
45-
frm.add_custom_button(__('<span class="fa fa-print"></span> Print Handling Unit'), () => {
46-
let d = new frappe.ui.Dialog({
47-
title: __('Select Printer Setting'),
48-
fields: [
49-
{
50-
label: __('Printer Setting'),
51-
fieldname: 'printer_setting',
52-
fieldtype: 'Link',
53-
options: 'Network Printer Settings',
54-
},
55-
{
56-
label: __('Printer Format'),
57-
fieldname: 'print_format',
58-
fieldtype: 'Link',
59-
options: 'Print Format',
60-
get_query: function () {
61-
return {
62-
filters: { doc_type: 'Handling Unit' },
63-
}
64-
},
65-
},
66-
],
67-
primary_action_label: 'Select',
68-
primary_action(selection) {
69-
d.hide()
70-
frappe.call({
71-
method: 'beam.beam.printing.print_handling_units',
72-
args: {
73-
doctype: frm.doc.doctype,
74-
name: frm.doc.name,
75-
printer_setting: selection.printer_setting,
76-
print_format: selection.print_format,
77-
doc: frm.doc,
78-
},
79-
})
43+
const beam_settings = frappe.boot.beam?.settings?.[frm.doc.company]
44+
if (!beam_settings?.enable_handling_units) {
45+
return
46+
}
47+
frm.add_custom_button(__('<span class="fa fa-print"></span> Print Handling Unit'), () => {
48+
let d = new frappe.ui.Dialog({
49+
title: __('Select Printer Setting'),
50+
fields: [
51+
{
52+
label: __('Printer Setting'),
53+
fieldname: 'printer_setting',
54+
fieldtype: 'Link',
55+
options: 'Network Printer Settings',
56+
default: frappe.defaults.get_user_default('Network Printer Settings'),
57+
},
58+
{
59+
label: __('Print Format'),
60+
fieldname: 'print_format',
61+
fieldtype: 'Link',
62+
options: 'Print Format',
63+
default: frappe.boot.beam?.default_hu_print_format,
64+
get_query: function () {
65+
return {
66+
filters: { doc_type: 'Handling Unit' },
67+
}
68+
},
69+
},
70+
],
71+
primary_action_label: 'Select',
72+
primary_action(selection) {
73+
d.hide()
74+
frappe.call({
75+
method: 'beam.beam.printing.print_handling_units',
76+
args: {
77+
doctype: frm.doc.doctype,
78+
name: frm.doc.name,
79+
printer_setting: selection.printer_setting,
80+
print_format: selection.print_format,
81+
doc: frm.doc,
8082
},
8183
})
82-
d.show()
83-
})
84-
}
84+
},
85+
})
86+
d.show()
8587
})
8688
}

0 commit comments

Comments
 (0)