patch for address template fixes #1749
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index b5e66d4..a5a7ae4 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -45,3 +45,4 @@
execute:import frappe.defaults;frappe.defaults.clear_default("price_list_currency")
erpnext.patches.v4_0.update_account_root_type
execute:frappe.delete_doc("Report", "Purchase In Transit")
+erpnext.patches.v4_0.new_address_template
diff --git a/erpnext/patches/v4_0/new_address_template.py b/erpnext/patches/v4_0/new_address_template.py
new file mode 100644
index 0000000..fc0c957
--- /dev/null
+++ b/erpnext/patches/v4_0/new_address_template.py
@@ -0,0 +1,9 @@
+import frappe
+
+def execute():
+ d = frappe.new_doc("Address Template")
+ d.update({"country":frappe.db.get_default("country")})
+ try:
+ d.insert()
+ except Exception:
+ pass
diff --git a/erpnext/utilities/doctype/address_template/address_template.json b/erpnext/utilities/doctype/address_template/address_template.json
index f08660b..13fd003 100644
--- a/erpnext/utilities/doctype/address_template/address_template.json
+++ b/erpnext/utilities/doctype/address_template/address_template.json
@@ -24,8 +24,8 @@
"permlevel": 0
},
{
- "default": "{{ address_title }}<br>\n{{ address_line1 }}<br>\n{% if address_line2 %}{{ address_line2 }}<br>{% endif -%}\n{{ city }}<br>\n{% if state %}{{ state }}<br>{% endif -%}\n{% if pincode %} PIN / ZIP: {{ pincode }}<br>{% endif -%}\n{{ country }}<br>\n{% if phone %}Phone: {{ phone }}<br>{% endif -%}\n{% if fax %}Fax: {{ fax }}<br>{% endif -%}\n{% if email_id %}Email: {{ email_id }}<br>{% endif -%}\n",
- "description": "<h4>Default Template</h4>\n<p>Uses <a href=\"http://jinja.pocoo.org/docs/templates/\">Jinja Templating</a> and all the fields of Address (including Custom Fields if any) will be available</p>\n<pre><code>{{ address_title }}<br>\n{{ address_line1 }}<br>\n{% if address_line2 %}{{ address_line2 }}<br>{% endif -%}\n{{ city }}<br>\n{% if state %}{{ state }}<br>{% endif -%}\n{% if pincode %} PIN / ZIP: {{ pincode }}<br>{% endif -%}\n{{ country }}<br>\n{% if phone %}Phone: {{ phone }}<br>{% endif -%}\n{% if fax %}Fax: {{ fax }}<br>{% endif -%}\n{% if email_id %}Email: {{ email_id }}<br>{% endif -%}\n</code></pre>",
+ "default": "{{ address_title }}<br>\n{{ address_line1 }}<br>\n{% if address_line2 %}{{ address_line2 }}<br>{% endif -%}\n{{ city }}<br>\n{% if state %}{{ state }}<br>{% endif -%}\n{% if pincode %} PIN: {{ pincode }}<br>{% endif -%}\n{{ country }}<br>\n{% if phone %}Phone: {{ phone }}<br>{% endif -%}\n{% if fax %}Fax: {{ fax }}<br>{% endif -%}\n{% if email_id %}Email: {{ email_id }}<br>{% endif -%}\n",
+ "description": "<h4>Default Template</h4>\n<p>Uses <a href=\"http://jinja.pocoo.org/docs/templates/\">Jinja Templating</a> and all the fields of Address (including Custom Fields if any) will be available</p>\n<pre><code>{{ address_title }}<br>\n{{ address_line1 }}<br>\n{% if address_line2 %}{{ address_line2 }}<br>{% endif -%}\n{{ city }}<br>\n{% if state %}{{ state }}<br>{% endif -%}\n{% if pincode %} PIN: {{ pincode }}<br>{% endif -%}\n{{ country }}<br>\n{% if phone %}Phone: {{ phone }}<br>{% endif -%}\n{% if fax %}Fax: {{ fax }}<br>{% endif -%}\n{% if email_id %}Email: {{ email_id }}<br>{% endif -%}\n</code></pre>",
"fieldname": "template",
"fieldtype": "Code",
"label": "Template",
@@ -33,7 +33,7 @@
}
],
"icon": "icon-map-marker",
- "modified": "2014-06-05 03:28:45.428733",
+ "modified": "2014-06-05 05:12:20.507364",
"modified_by": "Administrator",
"module": "Utilities",
"name": "Address Template",
diff --git a/erpnext/utilities/doctype/address_template/address_template.py b/erpnext/utilities/doctype/address_template/address_template.py
index bf68d82..21d3e6b 100644
--- a/erpnext/utilities/doctype/address_template/address_template.py
+++ b/erpnext/utilities/doctype/address_template/address_template.py
@@ -4,6 +4,7 @@
from __future__ import unicode_literals
import frappe
from frappe.model.document import Document
+from frappe import _
class AddressTemplate(Document):
def validate(self):
@@ -12,8 +13,12 @@
if not self.is_default:
if not defaults:
self.is_default = 1
- frappe.msgprint(frappe._("Setting this Address Template as default as there is no other default"))
+ frappe.msgprint(_("Setting this Address Template as default as there is no other default"))
else:
if defaults:
for d in defaults:
frappe.db.set_value("Address Template", d, "is_default", 0)
+
+ def on_trash(self):
+ if self.is_default:
+ frappe.throw(_("Default Address Tempalate cannot be deleted"))