From c1bfb63d96bb992769d1f6c654f87436d3c72dcc Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Fri, 13 Jun 2014 12:41:08 +0530 Subject: [PATCH] Create price list if missing --- erpnext/patches.txt | 1 + .../v4_0/create_price_list_if_missing.py | 28 +++++++++++++++++++ .../stock/doctype/price_list/price_list.py | 1 + 3 files changed, 30 insertions(+) create mode 100644 erpnext/patches/v4_0/create_price_list_if_missing.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 02c651f9ed..f7342c1d75 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -59,3 +59,4 @@ erpnext.patches.v4_0.create_custom_fields_for_india_specific_fields erpnext.patches.v4_0.save_default_letterhead erpnext.patches.v4_0.update_custom_print_formats_for_renamed_fields erpnext.patches.v4_0.update_other_charges_in_custom_purchase_print_formats +erpnext.patches.v4_0.create_price_list_if_missing diff --git a/erpnext/patches/v4_0/create_price_list_if_missing.py b/erpnext/patches/v4_0/create_price_list_if_missing.py new file mode 100644 index 0000000000..eeeae19783 --- /dev/null +++ b/erpnext/patches/v4_0/create_price_list_if_missing.py @@ -0,0 +1,28 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import frappe +from frappe import _ +from frappe.utils.nestedset import get_root_of + +def execute(): + if not frappe.db.sql("select name from `tabPrice List` where buying=1"): + create_price_list(_("Standard Buying"), buying=1) + + if not frappe.db.sql("select name from `tabPrice List` where selling=1"): + create_price_list(_("Standard Selling"), selling=1) + +def create_price_list(pl_name, buying=0, selling=0): + price_list = frappe.get_doc({ + "doctype": "Price List", + "price_list_name": pl_name, + "enabled": 1, + "buying": buying, + "selling": selling, + "currency": frappe.db.get_default("currency"), + "valid_for_territories": [{ + "territory": get_root_of("Territory") + }] + }) + price_list.insert() diff --git a/erpnext/stock/doctype/price_list/price_list.py b/erpnext/stock/doctype/price_list/price_list.py index d992488fc6..a4ff25044b 100644 --- a/erpnext/stock/doctype/price_list/price_list.py +++ b/erpnext/stock/doctype/price_list/price_list.py @@ -51,6 +51,7 @@ class PriceList(Document): if self.name == b.get(price_list_fieldname): b.set(price_list_fieldname, None) + b.ignore_permissions = True b.save() for module in ["Selling", "Buying"]: