Merge pull request #6003 from neilLasrado/bug-fix

[bug fix] Fixed bug in fee caclulation, renamed functions
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py
index 94709a7..4e00c32 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.py
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py
@@ -772,6 +772,9 @@
 	company_currency = get_company_currency(company)
 	account_details = frappe.db.get_value("Account", account, ["account_type", "account_currency"], as_dict=1)
 
+	if not account_details:
+		return
+
 	if account_details.account_type == "Receivable":
 		party_type = "Customer"
 	elif account_details.account_type == "Payable":
diff --git a/erpnext/accounts/doctype/pos_profile/pos_profile.json b/erpnext/accounts/doctype/pos_profile/pos_profile.json
index a7e49dd..cb637d2 100644
--- a/erpnext/accounts/doctype/pos_profile/pos_profile.json
+++ b/erpnext/accounts/doctype/pos_profile/pos_profile.json
@@ -8,6 +8,7 @@
  "custom": 0, 
  "docstatus": 0, 
  "doctype": "DocType", 
+ "editable_grid": 0, 
  "fields": [
   {
    "allow_on_submit": 0, 
@@ -832,7 +833,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-06-13 21:20:13.805101", 
+ "modified": "2016-08-06 17:05:59.990031", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "POS Profile", 
@@ -879,7 +880,7 @@
    "write": 0
   }
  ], 
- "quick_entry": 1, 
+ "quick_entry": 0, 
  "read_only": 0, 
  "read_only_onload": 0, 
  "sort_field": "modified", 
diff --git a/erpnext/accounts/doctype/sales_invoice/pos.py b/erpnext/accounts/doctype/sales_invoice/pos.py
index 9643764..53144cb 100644
--- a/erpnext/accounts/doctype/sales_invoice/pos.py
+++ b/erpnext/accounts/doctype/sales_invoice/pos.py
@@ -91,7 +91,7 @@
 
 def get_mode_of_payment(doc):
 	return frappe.db.sql(""" select mpa.default_account, mpa.parent, mp.type as type from `tabMode of Payment Account` mpa,
-		 `tabMode of Payment` mp where mpa.parent = mp.name and company = %(company)s""", {'company': doc.company}, as_dict=1)
+		 `tabMode of Payment` mp where mpa.parent = mp.name and mpa.company = %(company)s""", {'company': doc.company}, as_dict=1)
 
 def update_tax_table(doc):
 	taxes = get_taxes_and_charges('Sales Taxes and Charges Template', doc.taxes_and_charges)
diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
index 3a594c8..843937f 100644
--- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
+++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
@@ -52,10 +52,10 @@
 		if not "range3" in self.filters:
 			self.filters["range3"] = "90"
 			
-		for label in ("0-{range1}".format(**self.filters),
-			"{range1}-{range2}".format(**self.filters),
-			"{range2}-{range3}".format(**self.filters),
-			"{range3}-{above}".format(range3=self.filters.range3, above=_("Above"))):
+		for label in ("0-{range1}".format(range1=self.filters["range1"]),
+			"{range1}-{range2}".format(range1=self.filters["range1"]+1, range2=self.filters["range2"]),
+			"{range2}-{range3}".format(range2=self.filters["range2"]+1, range3=self.filters["range3"]),
+			"{range3}-{above}".format(range3=self.filters["range3"] + 1, above=_("Above"))):
 				columns.append({
 					"label": label,
 					"fieldtype": "Currency",
diff --git a/erpnext/manufacturing/doctype/production_order/production_order.js b/erpnext/manufacturing/doctype/production_order/production_order.js
index d42f735..9b97bd1 100644
--- a/erpnext/manufacturing/doctype/production_order/production_order.js
+++ b/erpnext/manufacturing/doctype/production_order/production_order.js
@@ -38,7 +38,7 @@
 			frm.trigger('show_progress');
 		}
 		
-		if(frm.doc.docstatus == 1){
+		if(frm.doc.docstatus == 1 && frm.doc.status != 'Stopped'){
 			frm.add_custom_button(__('Make Timesheet'), function(){
 				frappe.model.open_mapped_doc({
 					method: "erpnext.manufacturing.doctype.production_order.production_order.make_new_timesheet",
@@ -124,20 +124,20 @@
 			}
 
 			// opertions
-			if ((doc.operations || []).length) {
+			if (((doc.operations || []).length) && frm.doc.status != 'Stopped') {
 				frm.add_custom_button(__('Timesheet'), function() {
 					frappe.route_options = {"production_order": frm.doc.name};
 					frappe.set_route("List", "Timesheet");
 				}, __("View"));
 			}
 
-			if (flt(doc.material_transferred_for_manufacturing) < flt(doc.qty)) {
+			if ((flt(doc.material_transferred_for_manufacturing) < flt(doc.qty)) && frm.doc.status != 'Stopped') {
 				var btn = frm.add_custom_button(__('Start'),
 					cur_frm.cscript['Transfer Raw Materials']);
 				btn.addClass('btn-primary');
 			}
 
-			if (flt(doc.produced_qty) < flt(doc.material_transferred_for_manufacturing)) {
+			if ((flt(doc.produced_qty) < flt(doc.material_transferred_for_manufacturing)) && frm.doc.status != 'Stopped') {
 				var btn = frm.add_custom_button(__('Finish'),
 					cur_frm.cscript['Update Finished Goods']);
 
diff --git a/erpnext/manufacturing/doctype/production_order/production_order.py b/erpnext/manufacturing/doctype/production_order/production_order.py
index 0f6dae6..2bf3204 100644
--- a/erpnext/manufacturing/doctype/production_order/production_order.py
+++ b/erpnext/manufacturing/doctype/production_order/production_order.py
@@ -105,7 +105,7 @@
 
 	def stop_unstop(self, status):
 		""" Called from client side on Stop/Unstop event"""
-		self.update_status(status)
+		status = self.update_status(status)
 		self.update_planned_qty()
 		frappe.msgprint(_("Production Order status is {0}").format(status))
 		self.notify_update()
@@ -114,13 +114,15 @@
 	def update_status(self, status=None):
 		'''Update status of production order if unknown'''
 		if not status:
-			status = self.get_status()
+			status = self.get_status(status)
 			
 		if status != self.status:
 			self.db_set("status", status)
 
 		self.update_required_items()
 
+		return status
+
 	def get_status(self, status=None):
 		'''Return the status based on stock entries against this production order'''
 		if not status: