[fix] DuplicateEntryError for Warehouse Account Creation

This commit is contained in:
Anand Doshi
2016-06-26 17:43:14 +05:30
parent 110855e572
commit d6b734e2e3

View File

@@ -53,6 +53,7 @@ class Warehouse(NestedSet):
if not self.get_account(self.name): if not self.get_account(self.name):
if self.get("__islocal") or not frappe.db.get_value( if self.get("__islocal") or not frappe.db.get_value(
"Stock Ledger Entry", {"warehouse": self.name}): "Stock Ledger Entry", {"warehouse": self.name}):
self.validate_parent_account() self.validate_parent_account()
ac_doc = frappe.get_doc({ ac_doc = frappe.get_doc({
"doctype": "Account", "doctype": "Account",
@@ -66,8 +67,15 @@ class Warehouse(NestedSet):
"freeze_account": "No" "freeze_account": "No"
}) })
ac_doc.flags.ignore_permissions = True ac_doc.flags.ignore_permissions = True
ac_doc.insert()
msgprint(_("Account head {0} created").format(ac_doc.name)) try:
ac_doc.insert()
msgprint(_("Account head {0} created").format(ac_doc.name))
except frappe.DuplicateEntryError, e:
if not (e.args and e.args[0]=='Account'):
# if this is not due to creation of Account
raise
def validate_parent_account(self): def validate_parent_account(self):
if not self.company: if not self.company: