From 311079a31103c7e1b70b100251beea8f0994c983 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 28 Feb 2014 11:56:02 +0530 Subject: [PATCH] Patch: copy customer discount to pricing rule --- erpnext/patches.txt | 1 + .../4_0/customer_discount_to_pricing_rule.py | 23 ++++++++++ erpnext/selling/doctype/customer/customer.txt | 17 +------- .../doctype/customer_discount/__init__.py | 0 .../customer_discount/customer_discount.py | 11 ----- .../customer_discount/customer_discount.txt | 43 ------------------- erpnext/stock/get_item_details.py | 17 -------- 7 files changed, 25 insertions(+), 87 deletions(-) create mode 100644 erpnext/patches/4_0/customer_discount_to_pricing_rule.py delete mode 100644 erpnext/selling/doctype/customer_discount/__init__.py delete mode 100644 erpnext/selling/doctype/customer_discount/customer_discount.py delete mode 100644 erpnext/selling/doctype/customer_discount/customer_discount.txt diff --git a/erpnext/patches.txt b/erpnext/patches.txt index f88c84e718..3034d36812 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -22,3 +22,4 @@ execute:frappe.db.sql("update tabPage set module='Core' where name='Setup'") erpnext.patches.4_0.fields_to_be_renamed erpnext.patches.4_0.rename_sitemap_to_route erpnext.patches.4_0.fix_contact_address +erpnext.patches.4_0.customer_discount_to_pricing_rule diff --git a/erpnext/patches/4_0/customer_discount_to_pricing_rule.py b/erpnext/patches/4_0/customer_discount_to_pricing_rule.py new file mode 100644 index 0000000000..8ed7896371 --- /dev/null +++ b/erpnext/patches/4_0/customer_discount_to_pricing_rule.py @@ -0,0 +1,23 @@ +# 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") + + for d in frappe.db.sql("""select * from `tabCustomer Discount` + where ifnull(parent, '') != '' and docstatus < 2""", as_dict=1): + frappe.bean([{ + "doctype": "Pricing Rule", + "apply_on": "Item Group", + "item_group": d.item_group, + "applicable_for": "Customer", + "customer": d.parent, + "price_or_discount": "Discount", + "discount_percentage": d.discount + }]).insert() + + + frappe.delete_doc("DocType", "Customer Discount") \ No newline at end of file diff --git a/erpnext/selling/doctype/customer/customer.txt b/erpnext/selling/doctype/customer/customer.txt index c6c0e9ff34..2648ab24a3 100644 --- a/erpnext/selling/doctype/customer/customer.txt +++ b/erpnext/selling/doctype/customer/customer.txt @@ -2,7 +2,7 @@ { "creation": "2013-06-11 14:26:44", "docstatus": 0, - "modified": "2014-01-28 19:06:18", + "modified": "2014-02-28 11:39:53", "modified_by": "Administrator", "owner": "Administrator" }, @@ -325,21 +325,6 @@ "options": "Sales Team", "permlevel": 0 }, - { - "doctype": "DocField", - "fieldname": "customer_discount_section", - "fieldtype": "Section Break", - "label": "Customer Discount", - "permlevel": 0 - }, - { - "doctype": "DocField", - "fieldname": "customer_discounts", - "fieldtype": "Table", - "label": "Customer Discounts", - "options": "Customer Discount", - "permlevel": 0 - }, { "doctype": "DocField", "fieldname": "communications", diff --git a/erpnext/selling/doctype/customer_discount/__init__.py b/erpnext/selling/doctype/customer_discount/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/erpnext/selling/doctype/customer_discount/customer_discount.py b/erpnext/selling/doctype/customer_discount/customer_discount.py deleted file mode 100644 index 968a25b613..0000000000 --- a/erpnext/selling/doctype/customer_discount/customer_discount.py +++ /dev/null @@ -1,11 +0,0 @@ -# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors -# License: GNU General Public License v3. See license.txt - -# For license information, please see license.txt - -from __future__ import unicode_literals -import frappe - -class DocType: - def __init__(self, d, dl): - self.doc, self.doclist = d, dl \ No newline at end of file diff --git a/erpnext/selling/doctype/customer_discount/customer_discount.txt b/erpnext/selling/doctype/customer_discount/customer_discount.txt deleted file mode 100644 index 5abe3b6ac9..0000000000 --- a/erpnext/selling/doctype/customer_discount/customer_discount.txt +++ /dev/null @@ -1,43 +0,0 @@ -[ - { - "creation": "2013-07-22 12:43:40", - "docstatus": 0, - "modified": "2013-12-20 19:23:04", - "modified_by": "Administrator", - "owner": "Administrator" - }, - { - "doctype": "DocType", - "istable": 1, - "module": "Selling", - "name": "__common__" - }, - { - "doctype": "DocField", - "in_list_view": 1, - "name": "__common__", - "parent": "Customer Discount", - "parentfield": "fields", - "parenttype": "DocType", - "permlevel": 0, - "reqd": 1 - }, - { - "doctype": "DocType", - "name": "Customer Discount" - }, - { - "description": "Add / Edit", - "doctype": "DocField", - "fieldname": "item_group", - "fieldtype": "Link", - "label": "Item Group", - "options": "Item Group" - }, - { - "doctype": "DocField", - "fieldname": "discount", - "fieldtype": "Float", - "label": "Discount (%)" - } -] \ No newline at end of file diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index c5bce47b58..fd95f74133 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -206,23 +206,6 @@ def validate_conversion_rate(args, meta): args.plc_conversion_rate = flt(args.plc_conversion_rate, get_field_precision(meta.get_field("plc_conversion_rate"), frappe._dict({"fields": args}))) - -def get_item_discount(item_group, customer): - parent_item_groups = [x[0] for x in frappe.db.sql("""SELECT parent.name - FROM `tabItem Group` AS node, `tabItem Group` AS parent - WHERE parent.lft <= node.lft and parent.rgt >= node.rgt and node.name = %s - GROUP BY parent.name - ORDER BY parent.lft desc""", (item_group,))] - - discount = 0 - for d in parent_item_groups: - res = frappe.db.sql("""select discount, name from `tabCustomer Discount` - where parent = %s and item_group = %s""", (customer, d)) - if res: - discount = flt(res[0][0]) - break - - return {"discount_percentage": discount} def get_party_item_code(args, item_bean, out): if args.transaction_type == "selling":