[fix] if no valid territory for price list, try adding the user's default territory

This commit is contained in:
Anand Doshi 2013-08-01 15:43:28 +05:30
parent 482f34302e
commit 49154c790e

View File

@ -19,6 +19,7 @@ import webnotes
from webnotes import msgprint, _
from webnotes.utils import comma_or, cint
from webnotes.model.controller import DocListController
import webnotes.defaults
class DocType(DocListController):
def onload(self):
@ -30,8 +31,17 @@ class DocType(DocListController):
msgprint(_(self.meta.get_label("buying_or_selling")) + " " + _("must be one of") + " " +
comma_or(["Buying", "Selling"]), raise_exception=True)
# at least one territory
self.validate_table_has_rows("valid_for_territories")
if not self.doclist.get({"parentfield": "valid_for_territories"}):
# if no territory, set default territory
if webnotes.defaults.get_user_default("territory"):
self.doclist.append({
"doctype": "For Territory",
"parentfield": "valid_for_territories",
"territory": webnotes.defaults.get_user_default("territory")
})
else:
# at least one territory
self.validate_table_has_rows("valid_for_territories")
def on_update(self):
cart_settings = webnotes.get_obj("Shopping Cart Settings")