Patch: copy customer discount to pricing rule

This commit is contained in:
Nabin Hait 2014-02-28 11:56:02 +05:30
parent 08222150f2
commit 311079a311
7 changed files with 25 additions and 87 deletions

View File

@ -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

View File

@ -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")

View File

@ -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",

View File

@ -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

View File

@ -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": "<a href=\"#Sales Browser/Item Group\">Add / Edit</a>",
"doctype": "DocField",
"fieldname": "item_group",
"fieldtype": "Link",
"label": "Item Group",
"options": "Item Group"
},
{
"doctype": "DocField",
"fieldname": "discount",
"fieldtype": "Float",
"label": "Discount (%)"
}
]

View File

@ -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":