added address template:
diff --git a/erpnext/config/setup.py b/erpnext/config/setup.py
index 66b44e2..8db9ef2 100644
--- a/erpnext/config/setup.py
+++ b/erpnext/config/setup.py
@@ -32,6 +32,11 @@
},
{
"type": "doctype",
+ "name": "Address Template",
+ "description": _("Country wise default Address Templates")
+ },
+ {
+ "type": "doctype",
"name": "Terms and Conditions",
"description": _("Standard contract terms for Sales or Purchase.")
},
diff --git a/erpnext/setup/page/setup_wizard/install_fixtures.py b/erpnext/setup/page/setup_wizard/install_fixtures.py
index 90ef1f4..4bdf15e 100644
--- a/erpnext/setup/page/setup_wizard/install_fixtures.py
+++ b/erpnext/setup/page/setup_wizard/install_fixtures.py
@@ -10,6 +10,9 @@
def install(country=None):
records = [
+ # address template
+ {'doctype':"Address Template", "country": country},
+
# item group
{'doctype': 'Item Group', 'item_group_name': _('All Item Groups'),
'is_group': 'Yes', 'parent_item_group': ''},
@@ -189,7 +192,8 @@
from frappe.modules import scrub
for r in records:
- doc = frappe.get_doc(r)
+ doc = frappe.new_doc(r.get("doctype"))
+ doc.update(r)
# ignore mandatory for root
parent_link_field = ("parent_" + scrub(doc.doctype))
diff --git a/erpnext/utilities/doctype/address/address.py b/erpnext/utilities/doctype/address/address.py
index b00b40d..01b9d9a 100644
--- a/erpnext/utilities/doctype/address/address.py
+++ b/erpnext/utilities/doctype/address/address.py
@@ -10,7 +10,6 @@
from frappe.model.document import Document
class Address(Document):
-
def autoname(self):
if not self.address_title:
self.address_title = self.customer \
@@ -56,22 +55,16 @@
if not isinstance(address_dict, dict):
address_dict = frappe.db.get_value("Address", address_dict, "*", as_dict=True) or {}
- meta = frappe.get_meta("Address")
- sequence = (("", "address_line1"),
- ("\n", "address_line2"),
- ("\n", "city"),
- ("\n", "state"),
- ("\n" + meta.get_label("pincode") + ": ", "pincode"),
- ("\n", "country"),
- ("\n" + meta.get_label("phone") + ": ", "phone"),
- ("\n" + meta.get_label("fax") + ": ", "fax"))
+ template = frappe.db.get_value("Address Template", \
+ {"country": address_dict.get("country")}, "template")
+ if not template:
+ template = frappe.db.get_value("Address Template", \
+ {"is_default": 1}, "template")
- display = ""
- for separator, fieldname in sequence:
- if address_dict.get(fieldname):
- display += separator + address_dict.get(fieldname)
+ if not template:
+ frappe.throw(_("No default Address Template found. Please create a new one"))
- return display.strip()
+ return frappe.render_template(template, address_dict)
def get_territory_from_address(address):
"""Tries to match city, state and country of address to existing territory"""
@@ -88,3 +81,6 @@
break
return territory
+
+
+
diff --git a/erpnext/utilities/doctype/address/test_address.py b/erpnext/utilities/doctype/address/test_address.py
index 815449a..1e36a44 100644
--- a/erpnext/utilities/doctype/address/test_address.py
+++ b/erpnext/utilities/doctype/address/test_address.py
@@ -1,6 +1,18 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
+from __future__ import unicode_literals
import frappe
-test_records = frappe.get_test_records('Address')
\ No newline at end of file
+test_records = frappe.get_test_records('Address')
+
+import unittest
+import frappe
+
+from erpnext.utilities.doctype.address.address import get_address_display
+
+class TestAddress(unittest.TestCase):
+ def test_template_works(self):
+ address = frappe.get_list("Address")[0].name
+ display = get_address_display(frappe.get_doc("Address", address).as_dict())
+ self.assertTrue(display)
diff --git a/erpnext/utilities/doctype/address_template/__init__.py b/erpnext/utilities/doctype/address_template/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/utilities/doctype/address_template/__init__.py
diff --git a/erpnext/utilities/doctype/address_template/address_template.json b/erpnext/utilities/doctype/address_template/address_template.json
new file mode 100644
index 0000000..f08660b
--- /dev/null
+++ b/erpnext/utilities/doctype/address_template/address_template.json
@@ -0,0 +1,57 @@
+{
+ "autoname": "field:country",
+ "creation": "2014-06-05 02:22:36.029850",
+ "docstatus": 0,
+ "doctype": "DocType",
+ "document_type": "Master",
+ "fields": [
+ {
+ "fieldname": "country",
+ "fieldtype": "Link",
+ "in_list_view": 1,
+ "label": "Country",
+ "options": "Country",
+ "permlevel": 0,
+ "reqd": 0,
+ "search_index": 1
+ },
+ {
+ "description": "This format is used if country specific format is not found",
+ "fieldname": "is_default",
+ "fieldtype": "Check",
+ "in_list_view": 1,
+ "label": "Is Default",
+ "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>",
+ "fieldname": "template",
+ "fieldtype": "Code",
+ "label": "Template",
+ "permlevel": 0
+ }
+ ],
+ "icon": "icon-map-marker",
+ "modified": "2014-06-05 03:28:45.428733",
+ "modified_by": "Administrator",
+ "module": "Utilities",
+ "name": "Address Template",
+ "name_case": "",
+ "owner": "Administrator",
+ "permissions": [
+ {
+ "create": 1,
+ "delete": 1,
+ "export": 1,
+ "permlevel": 0,
+ "read": 1,
+ "report": 1,
+ "role": "System Manager",
+ "set_user_permissions": 1,
+ "write": 1
+ }
+ ],
+ "sort_field": "modified",
+ "sort_order": "DESC"
+}
\ No newline at end of file
diff --git a/erpnext/utilities/doctype/address_template/address_template.py b/erpnext/utilities/doctype/address_template/address_template.py
new file mode 100644
index 0000000..bf68d82
--- /dev/null
+++ b/erpnext/utilities/doctype/address_template/address_template.py
@@ -0,0 +1,19 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe.model.document import Document
+
+class AddressTemplate(Document):
+ def validate(self):
+ defaults = frappe.db.get_values("Address Template",
+ {"is_default":1, "name":("!=", self.name)})
+ 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"))
+ else:
+ if defaults:
+ for d in defaults:
+ frappe.db.set_value("Address Template", d, "is_default", 0)
diff --git a/erpnext/utilities/doctype/address_template/test_address_template.py b/erpnext/utilities/doctype/address_template/test_address_template.py
new file mode 100644
index 0000000..953c852
--- /dev/null
+++ b/erpnext/utilities/doctype/address_template/test_address_template.py
@@ -0,0 +1,22 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
+# License: See license.txt
+
+from __future__ import unicode_literals
+
+import frappe
+test_records = frappe.get_test_records('Address Template')
+
+import unittest
+import frappe
+
+class TestAddressTemplate(unittest.TestCase):
+ def test_default_is_unset(self):
+ a = frappe.get_doc("Address Template", "India")
+ a.is_default = 1
+ a.save()
+
+ b = frappe.get_doc("Address Template", "Brazil")
+ b.is_default = 1
+ b.save()
+
+ self.assertEqual(frappe.db.get_value("Address Template", "India", "is_default"), 0)
diff --git a/erpnext/utilities/doctype/address_template/test_records.json b/erpnext/utilities/doctype/address_template/test_records.json
new file mode 100644
index 0000000..412c9e7
--- /dev/null
+++ b/erpnext/utilities/doctype/address_template/test_records.json
@@ -0,0 +1,13 @@
+[
+ {
+ "country": "India",
+ "is_default": 1,
+ "template": "{{ 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"
+ },
+ {
+ "country": "Brazil",
+ "is_default": 0,
+ "template": "{{ 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"
+ }
+]
+