Fixes in address template

This commit is contained in:
Nabin Hait 2014-09-13 11:55:45 +05:30 committed by Anand Doshi
parent cb9331ddca
commit 65bef02607
2 changed files with 12 additions and 7 deletions

View File

@ -8,16 +8,16 @@ from frappe import _
class AddressTemplate(Document):
def validate(self):
defaults = frappe.db.get_values("Address Template",
{"is_default":1, "name":("!=", self.name)})
self.defaults = frappe.db.get_values("Address Template", {"is_default":1, "name":("!=", self.name)})
if not self.is_default:
if not defaults:
if not self.defaults:
self.is_default = 1
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[0], "is_default", 0)
def on_update(self):
if self.is_default and self.defaults:
for d in self.defaults:
frappe.db.set_value("Address Template", d[0], "is_default", 0)
def on_trash(self):
if self.is_default:

View File

@ -20,3 +20,8 @@ class TestAddressTemplate(unittest.TestCase):
b.save()
self.assertEqual(frappe.db.get_value("Address Template", "India", "is_default"), 0)
def tearDown(self):
a = frappe.get_doc("Address Template", "India")
a.is_default = 1
a.save()