Merge pull request #1342 from akhileshdarjee/hotfix

Item List refresh when price list changed in POS
diff --git a/accounts/report/accounts_receivable/accounts_receivable.py b/accounts/report/accounts_receivable/accounts_receivable.py
index de96abb..c826fcb 100644
--- a/accounts/report/accounts_receivable/accounts_receivable.py
+++ b/accounts/report/accounts_receivable/accounts_receivable.py
@@ -37,12 +37,15 @@
 		return columns
 
 	def get_data(self, customer_naming_by):
+		from accounts.utils import get_currency_precision
+		currency_precision = get_currency_precision() or 2
+
 		data = []
 		future_vouchers = self.get_entries_after(self.filters.report_date)
 		for gle in self.get_entries_till(self.filters.report_date):
 			if self.is_receivable(gle, future_vouchers):
 				outstanding_amount = self.get_outstanding_amount(gle, self.filters.report_date)
-				if abs(outstanding_amount) > 0.0:
+				if abs(outstanding_amount) > 0.1/10**currency_precision:
 					due_date = self.get_due_date(gle)
 					invoiced_amount = gle.debit if (gle.debit > 0) else 0
 					payment_received = invoiced_amount - outstanding_amount
diff --git a/accounts/report/general_ledger/general_ledger.py b/accounts/report/general_ledger/general_ledger.py
index 02e970b..af6a87c 100644
--- a/accounts/report/general_ledger/general_ledger.py
+++ b/accounts/report/general_ledger/general_ledger.py
@@ -51,7 +51,7 @@
 		
 	gl_entries = webnotes.conn.sql("""select posting_date, account, 
 			sum(ifnull(debit, 0)) as debit, sum(ifnull(credit, 0)) as credit, 
-			voucher_type, voucher_no, cost_center, remarks, is_advance, against 
+			voucher_type, voucher_no, cost_center, remarks, is_opening, against 
 		from `tabGL Entry`
 		where company=%(company)s {conditions}
 		{group_by_condition}
diff --git a/accounts/utils.py b/accounts/utils.py
index fdd57b3..a3557ae 100644
--- a/accounts/utils.py
+++ b/accounts/utils.py
@@ -378,4 +378,13 @@
 		account_for_field = "account_type"
 		
 	return webnotes.conn.get_value("Account", {account_for_field: account_for_doctype, 
-		"master_name": account_for})
\ No newline at end of file
+		"master_name": account_for})
+		
+def get_currency_precision(currency=None):
+	if not currency:
+		currency = webnotes.conn.get_value("Company", 
+			webnotes.conn.get_default("company"), "default_currency")
+	currency_format = webnotes.conn.get_value("Currency", currency, "number_format")
+	
+	from webnotes.utils import get_number_format_info
+	return get_number_format_info(currency_format)[2]
\ No newline at end of file
diff --git a/config.json b/config.json
index d454594..f71ed9b 100644
--- a/config.json
+++ b/config.json
@@ -1,6 +1,6 @@
 {
  "app_name": "ERPNext", 
- "app_version": "3.6.5", 
+ "app_version": "3.6.6", 
  "base_template": "app/portal/templates/base.html", 
  "modules": {
   "Accounts": {
@@ -74,5 +74,5 @@
    "type": "module"
   }
  }, 
- "requires_framework_version": "==3.7.4"
+ "requires_framework_version": "==3.7.5"
 }
\ No newline at end of file
diff --git a/portal/templates/sale.html b/portal/templates/sale.html
index 5dc72c7..c0996cc 100644
--- a/portal/templates/sale.html
+++ b/portal/templates/sale.html
@@ -10,9 +10,9 @@
     	<li class="active"><i class="icon-file icon-fixed-width"></i> {{ doc.name }}</li>
     </ul>
 	<h3><i class="icon-file icon-fixed-width"></i> {{ doc.name }}</h3>
-	{% if doc.name == "Not Allowed" -%}
+	{% if session_user == "Guest" -%}
 		<script>ask_to_login();</script>
-	{% else %}
+	{% elif doc.name != "Not Allowed"%}
 	<hr>
 	<div>
 	<div class="row">
diff --git a/portal/utils.py b/portal/utils.py
index 89800f3..e210f1a 100644
--- a/portal/utils.py
+++ b/portal/utils.py
@@ -41,21 +41,23 @@
 	}
 
 def get_transaction_context(doctype, name):
+	context = {"session_user": webnotes.session.user}
+	
 	customer = webnotes.conn.get_value("Contact", {"email_id": webnotes.session.user}, 
 		"customer")
 		
 	bean = webnotes.bean(doctype, name)
 	if bean.doc.customer != customer:
-		return {
-			"doc": {"name": "Not Allowed"}
-		}
+		context.update({"doc": {"name": "Not Allowed"}})
 	else:
-		return {
+		context.update({
 			"doc": bean.doc,
 			"doclist": bean.doclist,
 			"webnotes": webnotes,
 			"utils": webnotes.utils
-		}
+		})
+	
+	return context
 
 @webnotes.whitelist(allow_guest=True)
 def send_message(subject="Website Query", message="", sender="", status="Open"):
diff --git a/selling/doctype/sales_order/templates/pages/order.py b/selling/doctype/sales_order/templates/pages/order.py
index d53a8b0..9b4a83c 100644
--- a/selling/doctype/sales_order/templates/pages/order.py
+++ b/selling/doctype/sales_order/templates/pages/order.py
@@ -10,11 +10,12 @@
 def get_context():
 	from portal.utils import get_transaction_context
 	context = get_transaction_context("Sales Order", webnotes.form_dict.name)
-	modify_status(context.get("doc"))
-	context.update({
-		"parent_link": "orders",
-		"parent_title": "My Orders"
-	})
+	if context.get("doc").get("name") != "Not Allowed":
+		modify_status(context.get("doc"))
+		context.update({
+			"parent_link": "orders",
+			"parent_title": "My Orders"
+		})
 	return context
 	
 def modify_status(doc):
diff --git a/selling/utils/cart.py b/selling/utils/cart.py
index 3cd7b3c..7904627 100644
--- a/selling/utils/cart.py
+++ b/selling/utils/cart.py
@@ -282,7 +282,7 @@
 		party = get_lead_or_customer()
 	if not quotation:
 		quotation = _get_cart_quotation(party)
-	
+
 	cart_settings = webnotes.get_obj("Shopping Cart Settings")
 	
 	billing_territory = get_address_territory(quotation.doc.customer_address) or \
@@ -310,7 +310,8 @@
 	quotation.run_method("set_price_list_and_item_details")
 	
 	# set it in cookies for using in product page
-	webnotes.local._response.set_cookie("selling_price_list", quotation.doc.selling_price_list)
+	if quotation.doc.selling_price_list:
+		webnotes.local._response.set_cookie("selling_price_list", quotation.doc.selling_price_list)
 	
 def set_taxes(quotation, cart_settings, billing_territory):
 	"""set taxes based on billing territory"""
diff --git a/stock/doctype/warehouse/warehouse.py b/stock/doctype/warehouse/warehouse.py
index e1b0ef3..0b2fa84 100644
--- a/stock/doctype/warehouse/warehouse.py
+++ b/stock/doctype/warehouse/warehouse.py
@@ -92,23 +92,19 @@
 				exists for this warehouse."""))
 			
 	def before_rename(self, olddn, newdn, merge=False):
-		# Add company abbr if not provided
-		from setup.doctype.company.company import get_name_with_abbr
-		new_warehouse = get_name_with_abbr(newdn, self.doc.company)
-
 		if merge:
 			if not webnotes.conn.exists("Warehouse", newdn):
 				webnotes.throw(_("Warehouse ") + newdn +_(" does not exists"))
 				
-			if self.doc.company != webnotes.conn.get_value("Warehouse", new_warehouse, "company"):
+			if self.doc.company != webnotes.conn.get_value("Warehouse", newdn, "company"):
 				webnotes.throw(_("Both Warehouse must belong to same Company"))
 				
 			webnotes.conn.sql("delete from `tabBin` where warehouse=%s", olddn)
 			
 		from accounts.utils import rename_account_for
-		rename_account_for("Warehouse", olddn, new_warehouse, merge)
+		rename_account_for("Warehouse", olddn, newdn, merge)
 
-		return new_warehouse
+		return newdn
 
 	def after_rename(self, olddn, newdn, merge=False):
 		if merge:
diff --git a/stock/report/item_prices/item_prices.py b/stock/report/item_prices/item_prices.py
index c9efd69..50c923b 100644
--- a/stock/report/item_prices/item_prices.py
+++ b/stock/report/item_prices/item_prices.py
@@ -15,6 +15,7 @@
 	bom_rate = get_item_bom_rate()
 	val_rate_map = get_valuation_rate()
 
+	from accounts.utils import get_currency_precision
 	precision = get_currency_precision() or 2
 	data = []
 	for item in sorted(item_map):
@@ -29,14 +30,6 @@
 		])
 	
 	return columns, data
-	
-def get_currency_precision():
-	company_currency = webnotes.conn.get_value("Company", 
-		webnotes.conn.get_default("company"), "default_currency")
-	currency_format = webnotes.conn.get_value("Currency", company_currency, "number_format")
-	
-	from webnotes.utils import get_number_format_info
-	return get_number_format_info(currency_format)[2]
 
 def get_columns(filters):
 	"""return columns based on filters"""