feat: hook to fetch additional print settings in print view

This commit is contained in:
prssanna 2020-10-22 15:37:47 +05:30
parent 5ee7bca185
commit b57b3c9f6c
5 changed files with 57 additions and 21 deletions

View File

@ -13,6 +13,7 @@ from erpnext.stock.stock_ledger import get_valuation_rate
from erpnext.stock.doctype.stock_entry.stock_entry import get_used_alternative_items
from erpnext.stock.doctype.serial_no.serial_no import get_auto_serial_nos, auto_make_serial_nos, get_serial_nos
from frappe.contacts.doctype.address.address import get_address_display
from erpnext.controllers.print_settings import print_settings_for_taxes
from erpnext.accounts.doctype.budget.budget import validate_expense_against_budget
from erpnext.controllers.stock_controller import StockController
@ -20,14 +21,7 @@ from erpnext.controllers.stock_controller import StockController
class BuyingController(StockController):
def __setup__(self):
if hasattr(self, "taxes"):
self.flags.print_taxes_with_zero_amount = cint(frappe.db.get_single_value("Print Settings",
"print_taxes_with_zero_amount"))
self.flags.show_inclusive_tax_in_print = self.is_inclusive_tax()
self.print_templates = {
"total": "templates/print_formats/includes/total.html",
"taxes": "templates/print_formats/includes/taxes.html"
}
print_settings_for_taxes(self)
def get_feed(self):
if self.get("supplier_name"):

View File

@ -5,20 +5,31 @@ from __future__ import unicode_literals
import frappe
from frappe.utils import cint
def print_settings_for_item_table(doc):
def print_settings_for_item_table(doc, setting_value=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 = cint(frappe.db.get_single_value("Print Settings", "compact_item_print"))
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"))
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"))
doc.flags.show_inclusive_tax_in_print = doc.is_inclusive_tax()
doc.print_templates = {
"total": "templates/print_formats/includes/total.html",
"taxes": "templates/print_formats/includes/taxes.html"
}
def format_columns(display_columns, compact_fields):
compact_fields = compact_fields + ["image", "item_code", "item_name"]
final_columns = []
@ -26,3 +37,38 @@ def format_columns(display_columns, compact_fields):
if column not in compact_fields:
final_columns.append(column)
return final_columns
@frappe.whitelist()
def show_compact_item_setting(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):
meta = frappe.get_meta(doc.doctype)
items_field = meta.get_field('taxes')
if items_field and items_field.fieldtype == 'Table':
return True
return False
def get_print_settings():
settings = {
'compact_item_print': {
'condition': 'erpnext.controllers.print_settings.show_compact_item_setting',
'fieldtype': 'Check',
'child_field': 'items',
'label': 'Compact Item Print',
'set_template': 'erpnext.controllers.print_settings.print_settings_for_item_table'
},
'print_taxes_with_zero_amount': {
'condition': 'erpnext.controllers.print_settings.show_taxes_setting',
'fieldtype': 'Check',
'label': 'Print taxes with zero amount',
'set_template': 'erpnext.controllers.print_settings.print_settings_for_taxes'
}
}
return settings

View File

@ -11,20 +11,15 @@ from erpnext.stock.get_item_details import get_conversion_factor
from erpnext.stock.doctype.item.item import set_item_default
from frappe.contacts.doctype.address.address import get_address_display
from erpnext.controllers.accounts_controller import get_taxes_and_charges
from erpnext.controllers.print_settings import print_settings_for_taxes
from erpnext.controllers.stock_controller import StockController
class SellingController(StockController):
def __setup__(self):
if hasattr(self, "taxes"):
self.flags.print_taxes_with_zero_amount = cint(frappe.db.get_single_value("Print Settings",
"print_taxes_with_zero_amount"))
self.flags.show_inclusive_tax_in_print = self.is_inclusive_tax()
print_settings_for_taxes(self)
self.print_templates = {
"total": "templates/print_formats/includes/total.html",
"taxes": "templates/print_formats/includes/taxes.html"
}
def get_feed(self):
return _("To {0} | {1} {2}").format(self.customer_name, self.currency,

View File

@ -41,6 +41,7 @@ notification_config = "erpnext.startup.notifications.get_notification_config"
get_help_messages = "erpnext.utilities.activation.get_help_messages"
leaderboards = "erpnext.startup.leaderboard.get_leaderboards"
filters_config = "erpnext.startup.filters.get_filters_config"
additional_print_settings = "erpnext.controllers.print_settings.get_print_settings"
on_session_creation = [
"erpnext.portal.utils.create_customer_or_supplier",

View File

@ -2,13 +2,13 @@
import frappe
def get_filters_config():
filters_config = {
filters_config = {
"fiscal year": {
"label": "Fiscal Year",
"get_field": "erpnext.accounts.utils.get_fiscal_year_filter_field",
"valid_for_fieldtypes": ["Date", "Datetime", "DateRange"],
"depends_on": "company",
}
}
}
return filters_config
return filters_config