From 1f72b44f124db006b705de1bea01825595c4af87 Mon Sep 17 00:00:00 2001 From: Raffael Meyer Date: Sun, 27 Jan 2019 23:32:41 +0100 Subject: [PATCH 1/2] add german module with address template --- erpnext/regional/germany/__init__.py | 0 .../regional/germany/address_template.html | 8 +++++++ erpnext/regional/germany/setup.py | 21 +++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 erpnext/regional/germany/__init__.py create mode 100644 erpnext/regional/germany/address_template.html create mode 100644 erpnext/regional/germany/setup.py diff --git a/erpnext/regional/germany/__init__.py b/erpnext/regional/germany/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/regional/germany/address_template.html b/erpnext/regional/germany/address_template.html new file mode 100644 index 0000000000..0df786713c --- /dev/null +++ b/erpnext/regional/germany/address_template.html @@ -0,0 +1,8 @@ +{{ address_line1 }}
+{% if address_line2 %}{{ address_line2 }}
{% endif -%} +{{ pincode }} {{ city }}
+{% if country %}{{ country }}
{% endif -%} +
+{% if phone %}Tel: {{ phone }}
{% endif -%} +{% if fax %}Fax: {{ fax }}
{% endif -%} +{% if email_id %}E-Mail: {{ email_id }}
{% endif -%} diff --git a/erpnext/regional/germany/setup.py b/erpnext/regional/germany/setup.py new file mode 100644 index 0000000000..dd2a214a47 --- /dev/null +++ b/erpnext/regional/germany/setup.py @@ -0,0 +1,21 @@ +import frappe, os + +def setup(company=None, patch=True): + if not patch: + update_address_template() + + +def update_address_template(): + with open(os.path.join(os.path.dirname(__file__), 'address_template.html'), 'r') as f: + html = f.read() + + address_template = frappe.db.get_value('Address Template', 'Germany') + if address_template: + frappe.db.set_value('Address Template', 'Germany', 'template', html) + else: + # make new html template for Germany + frappe.get_doc(dict( + doctype='Address Template', + country='Germany', + template=html + )).insert() From ff878c0c1d10594446479a6f65687aeadd91e0e0 Mon Sep 17 00:00:00 2001 From: Raffael Meyer Date: Thu, 7 Feb 2019 03:28:27 +0100 Subject: [PATCH 2/2] fix formatting and names --- erpnext/regional/germany/setup.py | 40 +++++++++++++++++++------------ 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/erpnext/regional/germany/setup.py b/erpnext/regional/germany/setup.py index dd2a214a47..a5471366ca 100644 --- a/erpnext/regional/germany/setup.py +++ b/erpnext/regional/germany/setup.py @@ -1,21 +1,31 @@ -import frappe, os +import os +import frappe + def setup(company=None, patch=True): - if not patch: - update_address_template() + if not patch: + update_address_template() def update_address_template(): - with open(os.path.join(os.path.dirname(__file__), 'address_template.html'), 'r') as f: - html = f.read() + """ + Read address template from file. Update existing Address Template or create a + new one. + """ + dir_name = os.path.dirname(__file__) + template_path = os.path.join(dir_name, 'address_template.html') - address_template = frappe.db.get_value('Address Template', 'Germany') - if address_template: - frappe.db.set_value('Address Template', 'Germany', 'template', html) - else: - # make new html template for Germany - frappe.get_doc(dict( - doctype='Address Template', - country='Germany', - template=html - )).insert() + with open(template_path, 'r') as template_file: + template_html = template_file.read() + + address_template = frappe.db.get_value('Address Template', 'Germany') + + if address_template: + frappe.db.set_value('Address Template', 'Germany', 'template', template_html) + else: + # make new html template for Germany + frappe.get_doc(dict( + doctype='Address Template', + country='Germany', + template=template_html + )).insert()