brotherton-erpnext/erpnext/patches/v4_0/customer_discount_to_pricing_rule.py

34 lines
961 B
Python
Raw Normal View History

# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
2014-05-29 14:37:10 +00:00
from frappe.utils.nestedset import get_root_of
def execute():
frappe.reload_doc("accounts", "doctype", "pricing_rule")
2014-05-29 14:37:10 +00:00
2014-03-05 12:01:37 +00:00
frappe.db.auto_commit_on_many_writes = True
2014-05-29 14:37:10 +00:00
default_item_group = get_root_of("Item Group")
for d in frappe.db.sql("""select * from `tabCustomer Discount`
where ifnull(parent, '') != ''""", as_dict=1):
2014-06-05 12:36:20 +00:00
if not d.discount:
continue
frappe.get_doc({
"doctype": "Pricing Rule",
"apply_on": "Item Group",
2014-05-29 14:37:10 +00:00
"item_group": d.item_group or default_item_group,
"applicable_for": "Customer",
"customer": d.parent,
2014-05-10 16:47:04 +00:00
"price_or_discount": "Discount Percentage",
2014-06-24 09:56:40 +00:00
"discount_percentage": d.discount,
"selling": 1
}).insert()
2014-05-29 14:37:10 +00:00
frappe.db.auto_commit_on_many_writes = False
2014-05-10 16:47:04 +00:00
frappe.delete_doc("DocType", "Customer Discount")