brotherton-erpnext/erpnext/patches/4_0/customer_discount_to_pricing_rule.py

32 lines
994 B
Python
Raw Normal View History

# 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
def execute():
frappe.reload_doc("accounts", "doctype", "pricing_rule")
2014-03-05 12:01:37 +00:00
frappe.db.auto_commit_on_many_writes = True
for d in frappe.db.sql("""select * from `tabCustomer Discount`
where ifnull(parent, '') != '' and docstatus < 2""", as_dict=1):
2014-02-28 13:32:27 +00:00
if not d.item_group:
item_group = frappe.db.sql("""select name from `tabItem Group`
where ifnull(parent_item_group, '') = ''""")[0][0]
else:
item_group = d.item_group
frappe.bean([{
"doctype": "Pricing Rule",
"apply_on": "Item Group",
2014-02-28 13:32:27 +00:00
"item_group": item_group,
"applicable_for": "Customer",
"customer": d.parent,
"price_or_discount": "Discount",
"discount_percentage": d.discount
}]).insert()
2014-03-05 12:01:37 +00:00
frappe.db.auto_commit_on_many_writes = False
frappe.delete_doc("DocType", "Customer Discount")