2015-03-03 09:25:30 +00:00
|
|
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
2014-02-28 06:26:02 +00:00
|
|
|
# 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
|
2014-02-28 06:26:02 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2014-04-04 06:46:26 +00:00
|
|
|
frappe.get_doc({
|
2014-02-28 06:26:02 +00:00
|
|
|
"doctype": "Pricing Rule",
|
|
|
|
"apply_on": "Item Group",
|
2014-05-29 14:37:10 +00:00
|
|
|
"item_group": d.item_group or default_item_group,
|
2014-02-28 06:26:02 +00:00
|
|
|
"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
|
2014-04-04 06:46:26 +00:00
|
|
|
}).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")
|