added address template:
This commit is contained in:
parent
41471c3b44
commit
c22e11d483
@ -30,6 +30,11 @@ def get_data():
|
|||||||
"name": "Print Heading",
|
"name": "Print Heading",
|
||||||
"description": _("Titles for print templates e.g. Proforma Invoice.")
|
"description": _("Titles for print templates e.g. Proforma Invoice.")
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "doctype",
|
||||||
|
"name": "Address Template",
|
||||||
|
"description": _("Country wise default Address Templates")
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "doctype",
|
"type": "doctype",
|
||||||
"name": "Terms and Conditions",
|
"name": "Terms and Conditions",
|
||||||
|
@ -10,6 +10,9 @@ from frappe import _
|
|||||||
def install(country=None):
|
def install(country=None):
|
||||||
records = [
|
records = [
|
||||||
|
|
||||||
|
# address template
|
||||||
|
{'doctype':"Address Template", "country": country},
|
||||||
|
|
||||||
# item group
|
# item group
|
||||||
{'doctype': 'Item Group', 'item_group_name': _('All Item Groups'),
|
{'doctype': 'Item Group', 'item_group_name': _('All Item Groups'),
|
||||||
'is_group': 'Yes', 'parent_item_group': ''},
|
'is_group': 'Yes', 'parent_item_group': ''},
|
||||||
@ -189,7 +192,8 @@ def install(country=None):
|
|||||||
|
|
||||||
from frappe.modules import scrub
|
from frappe.modules import scrub
|
||||||
for r in records:
|
for r in records:
|
||||||
doc = frappe.get_doc(r)
|
doc = frappe.new_doc(r.get("doctype"))
|
||||||
|
doc.update(r)
|
||||||
|
|
||||||
# ignore mandatory for root
|
# ignore mandatory for root
|
||||||
parent_link_field = ("parent_" + scrub(doc.doctype))
|
parent_link_field = ("parent_" + scrub(doc.doctype))
|
||||||
|
@ -10,7 +10,6 @@ from frappe.utils import cstr
|
|||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
class Address(Document):
|
class Address(Document):
|
||||||
|
|
||||||
def autoname(self):
|
def autoname(self):
|
||||||
if not self.address_title:
|
if not self.address_title:
|
||||||
self.address_title = self.customer \
|
self.address_title = self.customer \
|
||||||
@ -56,22 +55,16 @@ def get_address_display(address_dict):
|
|||||||
if not isinstance(address_dict, dict):
|
if not isinstance(address_dict, dict):
|
||||||
address_dict = frappe.db.get_value("Address", address_dict, "*", as_dict=True) or {}
|
address_dict = frappe.db.get_value("Address", address_dict, "*", as_dict=True) or {}
|
||||||
|
|
||||||
meta = frappe.get_meta("Address")
|
template = frappe.db.get_value("Address Template", \
|
||||||
sequence = (("", "address_line1"),
|
{"country": address_dict.get("country")}, "template")
|
||||||
("\n", "address_line2"),
|
if not template:
|
||||||
("\n", "city"),
|
template = frappe.db.get_value("Address Template", \
|
||||||
("\n", "state"),
|
{"is_default": 1}, "template")
|
||||||
("\n" + meta.get_label("pincode") + ": ", "pincode"),
|
|
||||||
("\n", "country"),
|
|
||||||
("\n" + meta.get_label("phone") + ": ", "phone"),
|
|
||||||
("\n" + meta.get_label("fax") + ": ", "fax"))
|
|
||||||
|
|
||||||
display = ""
|
if not template:
|
||||||
for separator, fieldname in sequence:
|
frappe.throw(_("No default Address Template found. Please create a new one"))
|
||||||
if address_dict.get(fieldname):
|
|
||||||
display += separator + address_dict.get(fieldname)
|
|
||||||
|
|
||||||
return display.strip()
|
return frappe.render_template(template, address_dict)
|
||||||
|
|
||||||
def get_territory_from_address(address):
|
def get_territory_from_address(address):
|
||||||
"""Tries to match city, state and country of address to existing territory"""
|
"""Tries to match city, state and country of address to existing territory"""
|
||||||
@ -88,3 +81,6 @@ def get_territory_from_address(address):
|
|||||||
break
|
break
|
||||||
|
|
||||||
return territory
|
return territory
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,18 @@
|
|||||||
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
|
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
|
||||||
# License: GNU General Public License v3. See license.txt
|
# License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
test_records = frappe.get_test_records('Address')
|
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)
|
||||||
|
@ -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"
|
||||||
|
}
|
@ -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)
|
@ -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)
|
13
erpnext/utilities/doctype/address_template/test_records.json
Normal file
13
erpnext/utilities/doctype/address_template/test_records.json
Normal file
@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user