feat: contextual setting for print uom after quantity

This commit is contained in:
prssanna 2020-10-22 17:19:00 +05:30
parent d7b704c90f
commit 13c6e2f320
2 changed files with 32 additions and 16 deletions

View File

@ -5,24 +5,24 @@ from __future__ import unicode_literals
import frappe
from frappe.utils import cint
def print_settings_for_item_table(doc, setting_value=None):
def print_settings_for_item_table(doc, settings=None):
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 = setting_value if setting_value is not None\
else cint(frappe.db.get_single_value("Print Settings", "compact_item_print"))
setting_fields = ['compact_item_print', 'print_uom_after_quantity']
set_doc_flags_from_settings(doc, setting_fields, settings)
if doc.flags.compact_item_print:
doc.print_templates["description"] = "templates/print_formats/includes/item_table_description.html"
doc.flags.compact_item_fields = ["description", "qty", "rate", "amount"]
doc.flags.format_columns = format_columns
def print_settings_for_taxes(doc, setting_value=None):
doc.flags.print_taxes_with_zero_amount = setting_value if setting_value is not None\
else cint(frappe.db.get_single_value("Print Settings", "print_taxes_with_zero_amount"))
def print_settings_for_taxes(doc, settings=None):
set_doc_flags_from_settings(doc, ['print_taxes_with_zero_amount'], settings)
doc.flags.show_inclusive_tax_in_print = doc.is_inclusive_tax()
doc.print_templates = {
@ -30,6 +30,17 @@ def print_settings_for_taxes(doc, setting_value=None):
"taxes": "templates/print_formats/includes/taxes.html"
}
def set_doc_flags_from_settings(doc, fields, settings=None):
if not settings: settings = {}
print_settings = frappe.get_single('Print Settings')
for field in fields:
if field in settings:
doc.flags[field] = settings.get(field)
else:
doc.flags[field] = print_settings.get(field)
def format_columns(display_columns, compact_fields):
compact_fields = compact_fields + ["image", "item_code", "item_name"]
final_columns = []
@ -38,33 +49,38 @@ def format_columns(display_columns, compact_fields):
final_columns.append(column)
return final_columns
@frappe.whitelist()
def show_compact_item_setting(doc):
def has_items_field(doc):
meta = frappe.get_meta(doc.doctype)
items_field = meta.get_field('items')
if items_field and items_field.fieldtype == 'Table':
return True
return False
@frappe.whitelist()
def show_taxes_setting(doc):
def has_taxes_field(doc):
meta = frappe.get_meta(doc.doctype)
items_field = meta.get_field('taxes')
if items_field and items_field.fieldtype == 'Table':
taxes_field = meta.get_field('taxes')
if taxes_field and taxes_field.fieldtype == 'Table':
return True
return False
def get_print_settings():
settings = {
'compact_item_print': {
'condition': 'erpnext.controllers.print_settings.show_compact_item_setting',
'condition': 'erpnext.controllers.print_settings.has_items_field',
'fieldtype': 'Check',
'child_field': 'items',
'label': 'Compact Item Print',
'set_template': 'erpnext.controllers.print_settings.print_settings_for_item_table'
},
'print_uom_after_quantity': {
'condition': 'erpnext.controllers.print_settings.has_taxes_field',
'fieldtype': 'Check',
'child_field': 'items',
'label': 'Print UOM after Quantity',
'set_template': 'erpnext.controllers.print_settings.print_settings_for_item_table'
},
'print_taxes_with_zero_amount': {
'condition': 'erpnext.controllers.print_settings.show_taxes_setting',
'condition': 'erpnext.controllers.print_settings.has_taxes_field',
'fieldtype': 'Check',
'label': 'Print taxes with zero amount',
'set_template': 'erpnext.controllers.print_settings.print_settings_for_taxes'

View File

@ -1,4 +1,4 @@
{% set qty_first=frappe.db.get_single_value("Print Settings", "print_uom_after_quantity") %}
{% set qty_first=doc.flags.print_uom_after_quantity %}
{% if qty_first %}
{{ doc.get_formatted("qty", doc) }}
{% if (doc.uom and not doc.is_print_hide("uom")) %} {{ _(doc.uom) }}