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 20:07:10 +05:30
from frappe.utils.nestedset import get_root_of
def execute():
frappe.reload_doc("accounts", "doctype", "pricing_rule")
2014-05-29 20:07:10 +05:30
2014-03-05 17:31:37 +05:30
frappe.db.auto_commit_on_many_writes = True
2014-05-29 20:07:10 +05:30
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 18:06:20 +05:30
if not d.discount:
continue
frappe.get_doc({
"doctype": "Pricing Rule",
"apply_on": "Item Group",
2014-05-29 20:07:10 +05:30
"item_group": d.item_group or default_item_group,
"applicable_for": "Customer",
"customer": d.parent,
2014-05-10 22:17:04 +05:30
"price_or_discount": "Discount Percentage",
2014-06-24 15:26:40 +05:30
"discount_percentage": d.discount,
"selling": 1
}).insert()
2014-05-29 20:07:10 +05:30
frappe.db.auto_commit_on_many_writes = False
2014-05-10 22:17:04 +05:30
frappe.delete_doc("DocType", "Customer Discount")