From a787882a8f55333d7f41a4df9c09e01d05b540df Mon Sep 17 00:00:00 2001 From: Frappe ERPnext Date: Fri, 28 Aug 2020 13:28:52 +0200 Subject: [PATCH 1/4] feat: Option to print UOM after quantity Standard for ERPNext prints was UOM before quantity. Now user has a choice. --- erpnext/controllers/print_settings.py | 12 +++++++++--- .../includes/item_table_qty_swapped.html | 5 +++++ 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 erpnext/templates/print_formats/includes/item_table_qty_swapped.html diff --git a/erpnext/controllers/print_settings.py b/erpnext/controllers/print_settings.py index c41db25253..d24b69162b 100644 --- a/erpnext/controllers/print_settings.py +++ b/erpnext/controllers/print_settings.py @@ -7,9 +7,15 @@ from frappe.utils import cint def print_settings_for_item_table(doc): - doc.print_templates = { - "qty": "templates/print_formats/includes/item_table_qty.html" - } + if frappe.db.get_single_value("Print Settings", "print_uom_after_quantity") != 1: + doc.print_templates = { + "qty": "templates/print_formats/includes/item_table_qty.html" + } + else: + doc.print_templates = { + "qty": "templates/print_formats/includes/item_table_qty_swapped.html" + } + doc.hide_in_print_layout = ["uom", "stock_uom"] doc.flags.compact_item_print = cint(frappe.db.get_single_value("Print Settings", "compact_item_print")) diff --git a/erpnext/templates/print_formats/includes/item_table_qty_swapped.html b/erpnext/templates/print_formats/includes/item_table_qty_swapped.html new file mode 100644 index 0000000000..c6c70f2cf7 --- /dev/null +++ b/erpnext/templates/print_formats/includes/item_table_qty_swapped.html @@ -0,0 +1,5 @@ +{{ doc.get_formatted("qty", doc) }} +{% if (doc.uom and not doc.is_print_hide("uom")) %}{{ _(doc.uom) }} +{% elif (doc.stock_uom and not doc.is_print_hide("stock_uom")) %}{{ _(doc.stock_uom) }} +{%- endif %} + From f28bef868db05c1482f6534ef9950a90caf7fc51 Mon Sep 17 00:00:00 2001 From: Frappe ERPnext Date: Wed, 2 Sep 2020 21:42:52 +0200 Subject: [PATCH 2/4] feat: Checkbox for activation of printing UOM after quantity Checkbox will be added to Frappe after installation of ERPNext. (Print Settings docType is part of frappe app, not erpnext app) --- erpnext/setup/install.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/erpnext/setup/install.py b/erpnext/setup/install.py index 4f0f5721c2..2225fe169f 100644 --- a/erpnext/setup/install.py +++ b/erpnext/setup/install.py @@ -20,6 +20,7 @@ def after_install(): frappe.get_doc({'doctype': "Role", "role_name": "Analytics"}).insert() set_single_defaults() create_compact_item_print_custom_field() + create_print_uom_after_qty_custom_field() create_print_zero_amount_taxes_custom_field() add_all_roles_to("Administrator") create_default_cash_flow_mapper_templates() @@ -66,6 +67,16 @@ def create_compact_item_print_custom_field(): }) +def create_print_uom_after_qty_custom_field(): + create_custom_field('Print Settings', { + 'label': _('Print UOM after Quantity'), + 'fieldname': 'print_uom_after_quantity', + 'fieldtype': 'Check', + 'default': 0, + 'insert_after': 'compact_item_print' + }) + + def create_print_zero_amount_taxes_custom_field(): create_custom_field('Print Settings', { 'label': _('Print taxes with zero amount'), From a5d5e70bf4f256e70064fc710c8597b32077e68f Mon Sep 17 00:00:00 2001 From: Frappe ERPnext Date: Thu, 3 Sep 2020 17:30:25 +0200 Subject: [PATCH 3/4] Revert "feat: Option to print UOM after quantity" This reverts commit a787882a8f55333d7f41a4df9c09e01d05b540df. --- erpnext/controllers/print_settings.py | 12 +++--------- .../includes/item_table_qty_swapped.html | 5 ----- 2 files changed, 3 insertions(+), 14 deletions(-) delete mode 100644 erpnext/templates/print_formats/includes/item_table_qty_swapped.html diff --git a/erpnext/controllers/print_settings.py b/erpnext/controllers/print_settings.py index d24b69162b..c41db25253 100644 --- a/erpnext/controllers/print_settings.py +++ b/erpnext/controllers/print_settings.py @@ -7,15 +7,9 @@ from frappe.utils import cint def print_settings_for_item_table(doc): - if frappe.db.get_single_value("Print Settings", "print_uom_after_quantity") != 1: - doc.print_templates = { - "qty": "templates/print_formats/includes/item_table_qty.html" - } - else: - doc.print_templates = { - "qty": "templates/print_formats/includes/item_table_qty_swapped.html" - } - + doc.print_templates = { + "qty": "templates/print_formats/includes/item_table_qty.html" + } doc.hide_in_print_layout = ["uom", "stock_uom"] doc.flags.compact_item_print = cint(frappe.db.get_single_value("Print Settings", "compact_item_print")) diff --git a/erpnext/templates/print_formats/includes/item_table_qty_swapped.html b/erpnext/templates/print_formats/includes/item_table_qty_swapped.html deleted file mode 100644 index c6c70f2cf7..0000000000 --- a/erpnext/templates/print_formats/includes/item_table_qty_swapped.html +++ /dev/null @@ -1,5 +0,0 @@ -{{ doc.get_formatted("qty", doc) }} -{% if (doc.uom and not doc.is_print_hide("uom")) %}{{ _(doc.uom) }} -{% elif (doc.stock_uom and not doc.is_print_hide("stock_uom")) %}{{ _(doc.stock_uom) }} -{%- endif %} - From 9355641c49835327a0efcbb03e7a3cded7104b15 Mon Sep 17 00:00:00 2001 From: Frappe ERPnext Date: Thu, 3 Sep 2020 17:31:21 +0200 Subject: [PATCH 4/4] refactor: logic moved to standard template Previously print_settings.py controller decided which template to use. Now standard template decides what to print according to settings. --- .../includes/item_table_qty.html | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/erpnext/templates/print_formats/includes/item_table_qty.html b/erpnext/templates/print_formats/includes/item_table_qty.html index 239859eea1..ecaaef42b5 100644 --- a/erpnext/templates/print_formats/includes/item_table_qty.html +++ b/erpnext/templates/print_formats/includes/item_table_qty.html @@ -1,6 +1,15 @@ -{% if (doc.uom and not doc.is_print_hide("uom")) %} - {{ _(doc.uom) }} -{% elif (doc.stock_uom and not doc.is_print_hide("stock_uom")) %} - {{ _(doc.stock_uom) }} +{% set qty_first=frappe.db.get_single_value("Print Settings", "print_uom_after_quantity") %} +{% if qty_first %} + {{ doc.get_formatted("qty", doc) }} + {% if (doc.uom and not doc.is_print_hide("uom")) %} {{ _(doc.uom) }} + {% elif (doc.stock_uom and not doc.is_print_hide("stock_uom")) %} {{ _(doc.stock_uom) }} + {%- endif %} +{% else %} + {% if (doc.uom and not doc.is_print_hide("uom")) %} + {{ _(doc.uom) }} + {% elif (doc.stock_uom and not doc.is_print_hide("stock_uom")) %} + {{ _(doc.stock_uom) }} + {%- endif %} + {{ doc.get_formatted("qty", doc) }} {%- endif %} -{{ doc.get_formatted("qty", doc) }} +