From eaa2e55d20fad3ebc0c15636acc922b5b6dd95c3 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 5 Jun 2014 14:44:16 +0530 Subject: [PATCH] patch for address template fixes #1749 --- erpnext/patches.txt | 1 + erpnext/patches/v4_0/new_address_template.py | 9 +++++++++ .../doctype/address_template/address_template.json | 6 +++--- .../doctype/address_template/address_template.py | 7 ++++++- 4 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 erpnext/patches/v4_0/new_address_template.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index b5e66d4b1a..a5a7ae49c0 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -45,3 +45,4 @@ execute:frappe.delete_doc("Print Format", "SalesInvoice") 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 0000000000..fc0c957ad6 --- /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 f08660bddb..13fd003514 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 }}
\n{{ address_line1 }}
\n{% if address_line2 %}{{ address_line2 }}
{% endif -%}\n{{ city }}
\n{% if state %}{{ state }}
{% endif -%}\n{% if pincode %} PIN / ZIP: {{ pincode }}
{% endif -%}\n{{ country }}
\n{% if phone %}Phone: {{ phone }}
{% endif -%}\n{% if fax %}Fax: {{ fax }}
{% endif -%}\n{% if email_id %}Email: {{ email_id }}
{% endif -%}\n", - "description": "

Default Template

\n

Uses Jinja Templating and all the fields of Address (including Custom Fields if any) will be available

\n
{{ 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
", + "default": "{{ address_title }}
\n{{ address_line1 }}
\n{% if address_line2 %}{{ address_line2 }}
{% endif -%}\n{{ city }}
\n{% if state %}{{ state }}
{% endif -%}\n{% if pincode %} PIN: {{ pincode }}
{% endif -%}\n{{ country }}
\n{% if phone %}Phone: {{ phone }}
{% endif -%}\n{% if fax %}Fax: {{ fax }}
{% endif -%}\n{% if email_id %}Email: {{ email_id }}
{% endif -%}\n", + "description": "

Default Template

\n

Uses Jinja Templating and all the fields of Address (including Custom Fields if any) will be available

\n
{{ 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
", "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 bf68d82d7d..21d3e6bfcb 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 @@ class AddressTemplate(Document): 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"))