fix: serial and batch bundle values in the standard print format

This commit is contained in:
Rohit Waghchaure 2023-06-26 16:00:53 +05:30
parent c51e6dba8d
commit 9cf645e07f
4 changed files with 36 additions and 3 deletions

View File

@ -10,6 +10,7 @@ def set_print_templates_for_item_table(doc, settings):
doc.child_print_templates = {
"items": {
"qty": "templates/print_formats/includes/item_table_qty.html",
"serial_and_batch_bundle": "templates/print_formats/includes/serial_and_batch_bundle.html",
}
}

View File

@ -312,7 +312,35 @@ def get_serial_nos_from_bundle(serial_and_batch_bundle, serial_nos=None):
def get_serial_or_batch_nos(bundle):
return frappe.get_all("Serial and Batch Entry", fields=["*"], filters={"parent": bundle})
# For print format
bundle_data = frappe.get_cached_value(
"Serial and Batch Bundle", bundle, ["has_serial_no", "has_batch_no"], as_dict=True
)
fields = []
if bundle_data.has_serial_no:
fields.append("serial_no")
if bundle_data.has_batch_no:
fields.extend(["batch_no", "qty"])
data = frappe.get_all("Serial and Batch Entry", fields=fields, filters={"parent": bundle})
if bundle_data.has_serial_no and not bundle_data.has_batch_no:
return ", ".join([d.serial_no for d in data])
elif bundle_data.has_batch_no:
html = "<table class= 'table table-borderless' style='margin-top: 0px;margin-bottom: 0px;'>"
for d in data:
if d.serial_no:
html += f"<tr><td>{d.batch_no}</th><th>{d.serial_no}</th ><th>{abs(d.qty)}</th></tr>"
else:
html += f"<tr><td>{d.batch_no}</td><td>{abs(d.qty)}</td></tr>"
html += "</table>"
return html
class SerialNoValuation(DeprecatedSerialNoValuation):

View File

@ -0,0 +1,4 @@
{% if doc.get("serial_and_batch_bundle") %}
{% set bundle_print = get_serial_or_batch_nos(doc.serial_and_batch_bundle) %}
{{bundle_print}}
{%- endif %}