From 94d62a8d9f5aa76f008d0d6f820e3261876a6762 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 12 Sep 2013 17:39:36 +0530 Subject: [PATCH] [minor] [patch] fixed old patch --- .../p03_buying_selling_for_price_list.py | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/patches/june_2013/p03_buying_selling_for_price_list.py b/patches/june_2013/p03_buying_selling_for_price_list.py index c71646a8f5..c5a143511c 100644 --- a/patches/june_2013/p03_buying_selling_for_price_list.py +++ b/patches/june_2013/p03_buying_selling_for_price_list.py @@ -3,19 +3,24 @@ import webnotes from webnotes.utils import cint +import MySQLdb def execute(): webnotes.reload_doc("setup", "doctype", "price_list") webnotes.reload_doc("stock", "doctype", "item_price") - for price_list in webnotes.conn.sql_list("""select name from `tabPrice List`"""): - buying, selling = False, False - for b, s in webnotes.conn.sql("""select distinct buying, selling - from `tabItem Price` where price_list_name=%s""", price_list): - buying = buying or cint(b) - selling = selling or cint(s) + try: + for price_list in webnotes.conn.sql_list("""select name from `tabPrice List`"""): + buying, selling = False, False + for b, s in webnotes.conn.sql("""select distinct buying, selling + from `tabItem Price` where price_list_name=%s""", price_list): + buying = buying or cint(b) + selling = selling or cint(s) - buying_or_selling = "Selling" if selling else "Buying" - webnotes.conn.set_value("Price List", price_list, "buying_or_selling", buying_or_selling) - webnotes.conn.sql("""update `tabItem Price` set buying_or_selling=%s - where price_list_name=%s""", (buying_or_selling, price_list)) + buying_or_selling = "Selling" if selling else "Buying" + webnotes.conn.set_value("Price List", price_list, "buying_or_selling", buying_or_selling) + webnotes.conn.sql("""update `tabItem Price` set buying_or_selling=%s + where price_list_name=%s""", (buying_or_selling, price_list)) + except MySQLdb.OperationalError, e: + if e.args[0] == 1054: + webnotes.conn.sql("""update `tabItem Price` set buying_or_selling="Selling" """)