[fix] make demo for price list

This commit is contained in:
Akhilesh Darjee
2013-09-12 19:19:46 +05:30
17 changed files with 207 additions and 215 deletions

View File

@@ -1,19 +1,27 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import webnotes
from webnotes.utils import cint
import MySQLdb
def execute():
webnotes.reload_doc("setup", "doctype", "price_list")
webnotes.reload_doc("setup", "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 = "Buying" if buying else "Selling"
webnotes.conn.set_value("Price List", price_list, "buying_or_selling", buying_or_selling)
buying_or_selling = "Selling" if selling else "Buying"
webnotes.conn.set_value("Price List", price_list, "buying_or_selling", buying_or_selling)
except MySQLdb.OperationalError, e:
if e.args[0] == 1054:
webnotes.conn.set_value("Price List", price_list, "buying_or_selling", "Selling")
else:
raise e