feat: add barcode option to show text
add option to show text for non QR barcode types..
- [x] Print Design and PDF Generation (Success)
- [x] Patch existing gloablStyles
- [ ] Patch elements (https://github.com/frappe/print_designer/pull/63#issuecomment-1732313025)
https://github.com/frappe/print_designer/assets/29856401/506f6918-eeeb-4200-bfb5-964e0b8d75ae
@dj12djdjs can you please add more information about this pr in description?
@maharshivpatel I've updated the description with video example
let's make barcodeShowText boolean and set default as True! we can write patch for existing formats. I believe this is better in long run.
Edit: Also thank you for contributing i was going to add this and then completely forgot about it.
@maharshivpatel I initially tried using a "Check" field, but it wouldn't render. That is why I used a Select field.
I tried searching the code base for existing "Check" usage on the panel but couldn't find any. Can you point me in the right direction to get that working?
@dj12djdjs Select Field is fine just use formatValue to convert Yes/No to true/false.
@maharshivpatel I've added this logic to convert "Yes" and "No" into bool. But it results in infinite loop. I'm not familiar with the inner workings of this. Do you have any suggestions?
formatValue(object, property) {
const from = object[property];
const to = from === "Yes";
return to;
}
@dj12djdjs you can do something like this:
// formatValue: is used to format value from state ( Pinia store ) to what PropertiesPanel need.
formatValue: (object, property, isStyle) => {
if (!object) return;
return object[property] ? "Yes" : "No";
},
// onChangeCallback: is called just after value is saved in state ( Pinia store ).
// you can overwrite value based on requirement from here or trigger something when value changes.
onChangeCallback: (value = null) => {
if (value && MainStore.getCurrentElementsValues[0]) {
MainStore.getCurrentElementsValues[0]["barcodeShowText"] = value === "Yes";
MainStore.frappeControls[name].$input.blur();
}
},
you also need to change the logic as per true and false boolean instead of "Yes"/"No"
@maharshivpatel Thank you, it seems to be working. I just need to figure out the patch. Let me know if there is anything else
i am planning to write utils for patches as it will be quite complicated otherwise. i will share with you if i get time to write utils in few days else i will help you write a patch.
if you want to explore just check how ElementStore is used to save elements. There are two places elements and globalStyles that needs to be patched. Elements can also be nested inside if type is Rectangle.
@maharshivpatel I think I've got the globalStyles, elements I'm going to need to look into
def execute():
for name, print_format in frappe.get_all("Print Format", filters={"print_designer": 1}, fields=["name", "print_designer_settings"], as_list=1):
print_format = frappe.parse_json(print_format)
if print_format and "barcode" in print_format["globalStyles"]:
print_format["globalStyles"]["barcode"]["showBarcodeText"] = True
frappe.set_value("Print Format", name, "print_designer_settings", frappe.as_json(print_format))
@dj12djdjs Patch utils are available now. you can read the patch file and check example here .
Incase you want i can also write patch 😄
@maharshivpatel Awesome! I'll try to get some time this weekend to finish up this PR.
Probably over the holiday break I'll get a chance to finish this up
@dj12djdjs awesome, let me know if/whenever you need any help
@dj12djdjs hey, did you got time to add patches 😅.
how to adjust the sizes of the barcode?