diff --git a/setup/doctype/price_list/price_list.py b/setup/doctype/price_list/price_list.py index a5f22d9da0..051f54a323 100644 --- a/setup/doctype/price_list/price_list.py +++ b/setup/doctype/price_list/price_list.py @@ -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")