Merge pull request #19127 from rohitwaghchaure/removed_mandatory_property_for_address_field_in_quick_entry_develop

fix: removed mandatory property for address field in quick entry
diff --git a/erpnext/__init__.py b/erpnext/__init__.py
index fbf230a..ff08a72 100644
--- a/erpnext/__init__.py
+++ b/erpnext/__init__.py
@@ -5,7 +5,7 @@
 from erpnext.hooks import regional_overrides
 from frappe.utils import getdate
 
-__version__ = '12.1.3'
+__version__ = '12.1.4'
 
 def get_default_company(user=None):
 	'''Get default company for user'''
diff --git a/erpnext/accounts/doctype/bank_account/bank_account_dashboard.py b/erpnext/accounts/doctype/bank_account/bank_account_dashboard.py
index 3d149eb..a959cea 100644
--- a/erpnext/accounts/doctype/bank_account/bank_account_dashboard.py
+++ b/erpnext/accounts/doctype/bank_account/bank_account_dashboard.py
@@ -9,12 +9,11 @@
 		'non_standard_fieldnames': {
 			'Customer': 'default_bank_account',
 			'Supplier': 'default_bank_account',
-			'Journal Entry': 'bank_account_no'
 		},
 		'transactions': [
 			{
 				'label': _('Payments'),
-				'items': ['Payment Entry', 'Payment Request', 'Payment Order']
+				'items': ['Payment Entry', 'Payment Request', 'Payment Order', 'Payroll Entry']
 			},
 			{
 				'label': _('Party'),
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.js b/erpnext/accounts/doctype/journal_entry/journal_entry.js
index 3dbf4d4..5d88bfa 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.js
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.js
@@ -7,7 +7,7 @@
 
 frappe.ui.form.on("Journal Entry", {
 	setup: function(frm) {
-		frm.add_fetch("bank_account_no", "account", "account");
+		frm.add_fetch("bank_account", "account", "account");
 	},
 
 	refresh: function(frm) {
diff --git a/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json b/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json
index 8728950..c846ba2 100644
--- a/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json
+++ b/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json
@@ -10,7 +10,7 @@
   "account_type",
   "balance",
   "col_break1",
-  "bank_account_no",
+  "bank_account",
   "party_type",
   "party",
   "party_balance",
@@ -90,12 +90,6 @@
    "fieldtype": "Column Break"
   },
   {
-   "fieldname": "bank_account_no",
-   "fieldtype": "Link",
-   "label": "Bank Account No",
-   "options": "Bank Account"
-  },
-  {
    "fieldname": "party_type",
    "fieldtype": "Link",
    "label": "Party Type",
@@ -266,11 +260,17 @@
   {
    "fieldname": "dimension_col_break",
    "fieldtype": "Column Break"
+  },
+  {
+   "fieldname": "bank_account",
+   "fieldtype": "Link",
+   "label": "Bank Account",
+   "options": "Bank Account"
   }
  ],
  "idx": 1,
  "istable": 1,
- "modified": "2019-07-16 17:12:08.238334",
+ "modified": "2019-09-12 12:16:17.588399",
  "modified_by": "Administrator",
  "module": "Accounts",
  "name": "Journal Entry Account",
diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
index a7279f7..8cbf845 100755
--- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
+++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
@@ -446,6 +446,10 @@
 
 		row.age = (getdate(self.age_as_on) - getdate(entry_date)).days or 0
 		index = None
+
+		if not (self.filters.range1 and self.filters.range2 and self.filters.range3 and self.filters.range4):
+			self.filters.range1, self.filters.range2, self.filters.range3, self.filters.range4 = 30, 60, 90, 120
+
 		for i, days in enumerate([self.filters.range1, self.filters.range2, self.filters.range3, self.filters.range4]):
 			if row.age <= days:
 				index = i
diff --git a/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py b/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py
index e8b19b4..9da89ff 100644
--- a/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py
+++ b/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py
@@ -17,7 +17,7 @@
 	filters.update({"from_date": filters.get("date_range") and filters.get("date_range")[0], "to_date": filters.get("date_range") and filters.get("date_range")[1]})
 	columns = get_columns(additional_table_columns)
 
-	company_currency = erpnext.get_company_currency(filters.get('company'))
+	company_currency = frappe.get_cached_value('Company',  filters.get("company"),  "default_currency")
 
 	item_list = get_items(filters, additional_query_columns)
 	if item_list:
diff --git a/erpnext/accounts/report/payment_period_based_on_invoice_date/payment_period_based_on_invoice_date.py b/erpnext/accounts/report/payment_period_based_on_invoice_date/payment_period_based_on_invoice_date.py
index 24b5d87..57a1231 100644
--- a/erpnext/accounts/report/payment_period_based_on_invoice_date/payment_period_based_on_invoice_date.py
+++ b/erpnext/accounts/report/payment_period_based_on_invoice_date/payment_period_based_on_invoice_date.py
@@ -4,11 +4,14 @@
 from __future__ import unicode_literals
 import frappe
 from frappe import _
-from erpnext.accounts.report.accounts_receivable.accounts_receivable import get_ageing_data
+from erpnext.accounts.report.accounts_receivable.accounts_receivable import ReceivablePayableReport
 from frappe.utils import getdate, flt
 
+
 def execute(filters=None):
-	if not filters: filters = {}
+	if not filters:
+		filters = {}
+
 	validate_filters(filters)
 
 	columns = get_columns(filters)
@@ -19,18 +22,28 @@
 	for d in entries:
 		invoice = invoice_details.get(d.against_voucher) or frappe._dict()
 
-		if d.reference_type=="Purchase Invoice":
+		if d.reference_type == "Purchase Invoice":
 			payment_amount = flt(d.debit) or -1 * flt(d.credit)
 		else:
 			payment_amount = flt(d.credit) or -1 * flt(d.debit)
 
-		row = [d.voucher_type, d.voucher_no, d.party_type, d.party, d.posting_date, d.against_voucher,
-			invoice.posting_date, invoice.due_date, d.debit, d.credit, d.remarks]
+		d.update({
+			"range1": 0,
+			"range2": 0,
+			"range3": 0,
+			"range4": 0,
+			"outstanding": payment_amount
+		})
 
 		if d.against_voucher:
-			row += get_ageing_data(30, 60, 90, 120, d.posting_date, invoice.posting_date, payment_amount)
-		else:
-			row += ["", "", "", "", ""]
+			ReceivablePayableReport(filters).get_ageing_data(invoice.posting_date, d)
+
+		row = [
+			d.voucher_type, d.voucher_no, d.party_type, d.party, d.posting_date, d.against_voucher,
+			invoice.posting_date, invoice.due_date, d.debit, d.credit, d.remarks, 
+			d.age, d.range1, d.range2, d.range3, d.range4
+		]
+
 		if invoice.due_date:
 			row.append((getdate(d.posting_date) - getdate(invoice.due_date)).days or 0)
 
diff --git a/erpnext/accounts/report/sales_register/sales_register.py b/erpnext/accounts/report/sales_register/sales_register.py
index d08056f..2b32fa9 100644
--- a/erpnext/accounts/report/sales_register/sales_register.py
+++ b/erpnext/accounts/report/sales_register/sales_register.py
@@ -68,7 +68,8 @@
 		total_tax = 0
 		for tax_acc in tax_accounts:
 			if tax_acc not in income_accounts:
-				tax_amount = flt(invoice_tax_map.get(inv.name, {}).get(tax_acc))
+				tax_amount_precision = get_field_precision(frappe.get_meta("Sales Taxes and Charges").get_field("tax_amount"), currency=company_currency) or 2
+				tax_amount = flt(invoice_tax_map.get(inv.name, {}).get(tax_acc), tax_amount_precision)
 				total_tax += tax_amount
 				row.append(tax_amount)
 
diff --git a/erpnext/assets/doctype/asset_maintenance/asset_maintenance.py b/erpnext/assets/doctype/asset_maintenance/asset_maintenance.py
index 7551eae..ecb55dd 100644
--- a/erpnext/assets/doctype/asset_maintenance/asset_maintenance.py
+++ b/erpnext/assets/doctype/asset_maintenance/asset_maintenance.py
@@ -57,7 +57,7 @@
 	if not start_date and not last_completion_date:
 		start_date = frappe.utils.now()
 
-	if last_completion_date and (last_completion_date > start_date or not start_date):
+	if last_completion_date and ((start_date and last_completion_date > start_date) or not start_date):
 		start_date = last_completion_date
 	if periodicity == 'Daily':
 		next_due_date = add_days(start_date, 1)
@@ -71,10 +71,11 @@
 		next_due_date = add_years(start_date, 2)
 	if periodicity == 'Quarterly':
 		next_due_date = add_months(start_date, 3)
-	if end_date and (start_date >= end_date or last_completion_date >= end_date or next_due_date):
+	if end_date and ((start_date and start_date >= end_date) or (last_completion_date and last_completion_date >= end_date) or next_due_date):
 		next_due_date = ""
 	return next_due_date
 
+
 def update_maintenance_log(asset_maintenance, item_code, item_name, task):
 	asset_maintenance_log = frappe.get_value("Asset Maintenance Log", {"asset_maintenance": asset_maintenance,
 		"task": task.maintenance_task, "maintenance_status": ('in',['Planned','Overdue'])})
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.js b/erpnext/buying/doctype/purchase_order/purchase_order.js
index b2a2f01..c5fa98d 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.js
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.js
@@ -10,7 +10,8 @@
 		frm.custom_make_buttons = {
 			'Purchase Receipt': 'Receipt',
 			'Purchase Invoice': 'Invoice',
-			'Stock Entry': 'Material to Supplier'
+			'Stock Entry': 'Material to Supplier',
+			'Payment Entry': 'Payment'
 		}
 
 		frm.set_query("reserve_warehouse", "supplied_items", function() {
@@ -196,10 +197,10 @@
 		if(items.length >= 1){
 			me.raw_material_data = [];
 			me.show_dialog = 1;
-			let title = "";
+			let title = __('Transfer Material to Supplier');
 			let fields = [
 			{fieldtype:'Section Break', label: __('Raw Materials')},
-			{fieldname: 'sub_con_rm_items', fieldtype: 'Table',
+			{fieldname: 'sub_con_rm_items', fieldtype: 'Table', label: __('Items'),
 				fields: [
 					{
 						fieldtype:'Data',
@@ -271,7 +272,7 @@
 						'item_code': item.main_item_code,
 						'rm_item_code': item.rm_item_code,
 						'item_name': item.rm_item_code,
-						'qty': item.required_qty,
+						'qty': item.required_qty - item.supplied_qty,
 						'warehouse':item.reserve_warehouse,
 						'rate':item.rate,
 						'amount':item.amount,
diff --git a/erpnext/hr/doctype/payroll_entry/payroll_entry.json b/erpnext/hr/doctype/payroll_entry/payroll_entry.json
index 5ae5374..9356f3e 100644
--- a/erpnext/hr/doctype/payroll_entry/payroll_entry.json
+++ b/erpnext/hr/doctype/payroll_entry/payroll_entry.json
@@ -37,8 +37,9 @@
   "cost_center",
   "account",
   "payment_account",
-  "section_break2",
   "amended_from",
+  "column_break_33",
+  "bank_account",
   "salary_slips_created",
   "salary_slips_submitted"
  ],
@@ -206,16 +207,13 @@
   {
    "allow_on_submit": 1,
    "description": "Select Payment Account to make Bank Entry",
+   "fetch_from": "bank_account.account",
    "fieldname": "payment_account",
    "fieldtype": "Link",
    "label": "Payment Account",
    "options": "Account"
   },
   {
-   "fieldname": "section_break2",
-   "fieldtype": "Section Break"
-  },
-  {
    "fieldname": "amended_from",
    "fieldtype": "Link",
    "label": "Amended From",
@@ -248,11 +246,21 @@
   {
    "fieldname": "dimension_col_break",
    "fieldtype": "Column Break"
+  },
+  {
+   "fieldname": "bank_account",
+   "fieldtype": "Link",
+   "label": "Bank Account",
+   "options": "Bank Account"
+  },
+  {
+   "fieldname": "column_break_33",
+   "fieldtype": "Column Break"
   }
  ],
  "icon": "fa fa-cog",
  "is_submittable": 1,
- "modified": "2019-05-25 22:47:49.977955",
+ "modified": "2019-09-12 15:46:31.436381",
  "modified_by": "Administrator",
  "module": "HR",
  "name": "Payroll Entry",
diff --git a/erpnext/hr/doctype/payroll_entry/payroll_entry.py b/erpnext/hr/doctype/payroll_entry/payroll_entry.py
index 97cfc84..2de01e6 100644
--- a/erpnext/hr/doctype/payroll_entry/payroll_entry.py
+++ b/erpnext/hr/doctype/payroll_entry/payroll_entry.py
@@ -39,7 +39,7 @@
 			and for which salary structure exists
 		"""
 		cond = self.get_filter_condition()
-		cond += self.get_joining_releiving_condition()
+		cond += self.get_joining_relieving_condition()
 
 		condition = ''
 		if self.payroll_frequency:
@@ -93,7 +93,7 @@
 
 		return cond
 
-	def get_joining_releiving_condition(self):
+	def get_joining_relieving_condition(self):
 		cond = """
 			and ifnull(t1.date_of_joining, '0000-00-00') <= '%(end_date)s'
 			and ifnull(t1.relieving_date, '2199-12-31') >= '%(start_date)s'
@@ -341,6 +341,7 @@
 		journal_entry.set("accounts", [
 			{
 				"account": self.payment_account,
+				"bank_account": self.bank_account,
 				"credit_in_account_currency": payment_amount
 			},
 			{
diff --git a/erpnext/hr/doctype/upload_attendance/upload_attendance.py b/erpnext/hr/doctype/upload_attendance/upload_attendance.py
index f452155..1707e35 100644
--- a/erpnext/hr/doctype/upload_attendance/upload_attendance.py
+++ b/erpnext/hr/doctype/upload_attendance/upload_attendance.py
@@ -60,8 +60,8 @@
 			existing_attendance = {}
 			if existing_attendance_records \
 				and tuple([getdate(date), employee.name]) in existing_attendance_records \
-				and getdate(employee.date_of_joining) >= getdate(date) \
-				and getdate(employee.relieving_date) <= getdate(date):
+				and getdate(employee.date_of_joining) <= getdate(date) \
+				and getdate(employee.relieving_date) >= getdate(date):
 					existing_attendance = existing_attendance_records[tuple([getdate(date), employee.name])]
 			row = [
 				existing_attendance and existing_attendance.name or "",
diff --git a/erpnext/manufacturing/doctype/job_card/job_card.py b/erpnext/manufacturing/doctype/job_card/job_card.py
index a8faa13..9d2e620 100644
--- a/erpnext/manufacturing/doctype/job_card/job_card.py
+++ b/erpnext/manufacturing/doctype/job_card/job_card.py
@@ -105,7 +105,6 @@
 		for_quantity, time_in_mins = 0, 0
 		from_time_list, to_time_list = [], []
 
-
 		for d in frappe.get_all('Job Card',
 			filters = {'docstatus': 1, 'operation_id': self.operation_id}):
 			doc = frappe.get_doc('Job Card', d.name)
@@ -125,8 +124,8 @@
 				if data.name == self.operation_id:
 					data.completed_qty = for_quantity
 					data.actual_operation_time = time_in_mins
-					data.actual_start_time = min(from_time_list)
-					data.actual_end_time = max(to_time_list)
+					data.actual_start_time = min(from_time_list) if from_time_list else None
+					data.actual_end_time = max(to_time_list) if to_time_list else None
 
 			wo.flags.ignore_validate_update_after_submit = True
 			wo.update_operation_status()
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 8b3da8e..a001d16 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -635,4 +635,5 @@
 erpnext.patches.v12_0.generate_leave_ledger_entries
 erpnext.patches.v12_0.move_credit_limit_to_customer_credit_limit
 erpnext.patches.v12_0.add_variant_of_in_item_attribute_table
-erpnext.patches.v12_0.create_default_energy_point_rules
+erpnext.patches.v12_0.rename_bank_account_field_in_journal_entry_account
+erpnext.patches.v12_0.create_default_energy_point_rules
\ No newline at end of file
diff --git a/erpnext/patches/v12_0/rename_bank_account_field_in_journal_entry_account.py b/erpnext/patches/v12_0/rename_bank_account_field_in_journal_entry_account.py
new file mode 100644
index 0000000..4230cb8
--- /dev/null
+++ b/erpnext/patches/v12_0/rename_bank_account_field_in_journal_entry_account.py
@@ -0,0 +1,17 @@
+# Copyright (c) 2019, Frappe and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe.model.utils.rename_field import rename_field
+
+def execute():
+	''' Change the fieldname from bank_account_no to bank_account '''
+	if not frappe.get_meta("Journal Entry Account").has_field("bank_account"):
+		frappe.reload_doc("Accounts", "doctype", "Journal Entry Account")
+		update_journal_entry_account_fieldname()
+
+def update_journal_entry_account_fieldname():
+	''' maps data from old field to the new field '''
+	if frappe.db.has_column('Journal Entry Account', 'bank_account_no'):
+		rename_field("Journal Entry Account", "bank_account_no", "bank_account")
\ No newline at end of file
diff --git a/erpnext/selling/doctype/sales_order/sales_order.js b/erpnext/selling/doctype/sales_order/sales_order.js
index e86cadd..d6fd8a1 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.js
+++ b/erpnext/selling/doctype/sales_order/sales_order.js
@@ -11,7 +11,8 @@
 			'Sales Invoice': 'Invoice',
 			'Material Request': 'Material Request',
 			'Purchase Order': 'Purchase Order',
-			'Project': 'Project'
+			'Project': 'Project',
+			'Payment Entry': "Payment"
 		}
 		frm.add_fetch('customer', 'tax_id', 'tax_id');
 
diff --git a/erpnext/selling/report/customer_credit_balance/customer_credit_balance.py b/erpnext/selling/report/customer_credit_balance/customer_credit_balance.py
index cd50568..f396705 100644
--- a/erpnext/selling/report/customer_credit_balance/customer_credit_balance.py
+++ b/erpnext/selling/report/customer_credit_balance/customer_credit_balance.py
@@ -60,7 +60,7 @@
 	conditions = ""
 
 	if filters.get("customer"):
-		conditions += " AND c.name = " + filters.get("customer")
+		conditions += " AND c.name = '" + filters.get("customer") + "'"
 
 	return frappe.db.sql("""SELECT
 			c.name, c.customer_name,
@@ -69,6 +69,6 @@
 		FROM `tabCustomer` c, `tabCustomer Credit Limit` ccl
 		WHERE
 			c.name = ccl.parent
-			AND ccl.company = %s
-			{0}
-	""".format(conditions), (filters.get("company")), as_dict=1) #nosec
+			AND ccl.company = '{0}'
+			{1}
+	""".format( filters.get("company"),conditions), as_dict=1) #nosec
diff --git a/erpnext/selling/sales_common.js b/erpnext/selling/sales_common.js
index 000d666..e508476 100644
--- a/erpnext/selling/sales_common.js
+++ b/erpnext/selling/sales_common.js
@@ -234,7 +234,7 @@
 					args: {
 						item_code: item.item_code,
 						warehouse: item.warehouse,
-						has_batch_no: has_batch_no,
+						has_batch_no: has_batch_no || 0,
 						stock_qty: item.stock_qty,
 						serial_no: item.serial_no || "",
 					},
diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py
index 35c0bb6..7c2e09e 100644
--- a/erpnext/stock/get_item_details.py
+++ b/erpnext/stock/get_item_details.py
@@ -808,7 +808,7 @@
 	return {'serial_no': serial_no}
 
 @frappe.whitelist()
-def get_bin_details_and_serial_nos(item_code, warehouse, has_batch_no, stock_qty=None, serial_no=None):
+def get_bin_details_and_serial_nos(item_code, warehouse, has_batch_no=None, stock_qty=None, serial_no=None):
 	bin_details_and_serial_nos = {}
 	bin_details_and_serial_nos.update(get_bin_details(item_code, warehouse))
 	if flt(stock_qty) > 0:
diff --git a/erpnext/stock/report/purchase_order_items_to_be_received_or_billed/__init__.py b/erpnext/stock/report/purchase_order_items_to_be_received_or_billed/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/stock/report/purchase_order_items_to_be_received_or_billed/__init__.py
diff --git a/erpnext/stock/report/purchase_order_items_to_be_received_or_billed/purchase_order_items_to_be_received_or_billed.json b/erpnext/stock/report/purchase_order_items_to_be_received_or_billed/purchase_order_items_to_be_received_or_billed.json
new file mode 100644
index 0000000..dca4db4
--- /dev/null
+++ b/erpnext/stock/report/purchase_order_items_to_be_received_or_billed/purchase_order_items_to_be_received_or_billed.json
@@ -0,0 +1,35 @@
+{
+ "add_total_row": 0,
+ "creation": "2019-09-16 14:10:33.102865",
+ "disable_prepared_report": 0,
+ "disabled": 0,
+ "docstatus": 0,
+ "doctype": "Report",
+ "idx": 0,
+ "is_standard": "Yes",
+ "letter_head": "sapcon-old",
+ "modified": "2019-09-20 15:19:55.710578",
+ "modified_by": "Administrator",
+ "module": "Stock",
+ "name": "Purchase Order Items To Be Received or Billed",
+ "owner": "Administrator",
+ "prepared_report": 0,
+ "query": "SELECT\n\t`poi_pri`.`purchase_order` as \"Purchase Order:Link/Purchase Order:120\",\n\t`poi_pri`.`status` as \"Status:Data:120\",\n\t`poi_pri`.`transaction_date` as \"Date:Date:100\",\n\t`poi_pri`.`schedule_date` as \"Reqd by Date:Date:110\",\n\t`poi_pri`.`supplier` as \"Supplier:Link/Supplier:120\",\n\t`poi_pri`.`supplier_name` as \"Supplier Name::150\",\n\t`poi_pri`.`item_code` as \"Item Code:Link/Item:120\",\n\t`poi_pri`.`qty` as \"Qty:Float:100\",\n\t`poi_pri`.`base_amount` as  \"Base Amount:Currency:100\",\n\t`poi_pri`.`received_qty` as \"Received Qty:Float:100\",\n\t`poi_pri`.`received_amount` as \"Received Qty Amount:Currency:100\",\n\t`poi_pri`.`qty_to_receive` as \"Qty to Receive:Float:100\",\n\t`poi_pri`.`amount_to_be_received` as \"Amount to Receive:Currency:100\",\n\t`poi_pri`.`billed_amount` as  \"Billed Amount:Currency:100\",\n\t`poi_pri`.`amount_to_be_billed` as  \"Amount To Be Billed:Currency:100\",\n\tSUM(`pii`.`qty`) AS \"Billed Qty:Float:100\",\n\t`poi_pri`.qty - SUM(`pii`.`qty`) AS \"Qty To Be Billed:Float:100\",\n\t`poi_pri`.`warehouse` as \"Warehouse:Link/Warehouse:150\",\n\t`poi_pri`.`item_name` as \"Item Name::150\",\n\t`poi_pri`.`description` as \"Description::200\",\n\t`poi_pri`.`brand` as \"Brand::100\",\n\t`poi_pri`.`project` as \"Project\",\n\t`poi_pri`.`company` as \"Company:Link/Company:\"\nFROM\n\t(SELECT\n\t\t`po`.`name` AS 'purchase_order',\n\t\t`po`.`status`,\n\t\t`po`.`company`,\n\t\t`poi`.`warehouse`,\n\t\t`poi`.`brand`,\n\t\t`poi`.`description`,\n\t\t`po`.`transaction_date`,\n\t\t`poi`.`schedule_date`,\n\t\t`po`.`supplier`,\n\t\t`po`.`supplier_name`,\n\t\t`poi`.`project`,\n\t\t`poi`.`item_code`,\n\t\t`poi`.`item_name`,\n\t\t`poi`.`qty`,\n\t\t`poi`.`base_amount`,\n\t\t`poi`.`received_qty`,\n\t\t(`poi`.billed_amt * ifnull(`po`.conversion_rate, 1)) as billed_amount,\n\t\t(`poi`.base_amount - (`poi`.billed_amt * ifnull(`po`.conversion_rate, 1))) as amount_to_be_billed,\n\t\t`poi`.`qty` - IFNULL(`poi`.`received_qty`, 0) AS 'qty_to_receive',\n\t\t(`poi`.`qty` - IFNULL(`poi`.`received_qty`, 0)) * `poi`.`rate` AS 'amount_to_be_received',\n\t\tSUM(`pri`.`amount`) AS 'received_amount',\n\t\t`poi`.`name` AS 'poi_name',\n\t\t`pri`.`name` AS 'pri_name'\n\tFROM\n\t\t`tabPurchase Order` po\n\t\tLEFT JOIN `tabPurchase Order Item` poi\n\t\tON `poi`.`parent` = `po`.`name`\n\t\tLEFT JOIN `tabPurchase Receipt Item` pri\n\t\tON `pri`.`purchase_order_item` = `poi`.`name`\n\t\t\tAND `pri`.`docstatus`=1\n\tWHERE\n\t\t`po`.`status` not in ('Stopped', 'Closed')\n\t\tAND `po`.`docstatus` = 1\n\t\tAND IFNULL(`poi`.`received_qty`, 0) < IFNULL(`poi`.`qty`, 0)\n\tGROUP BY `poi`.`name`\n\tORDER BY `po`.`transaction_date` ASC\n\t) poi_pri\n\tLEFT JOIN `tabPurchase Invoice Item` pii\n\tON `pii`.`po_detail` = `poi_pri`.`poi_name`\n\t\tAND `pii`.`docstatus`=1\nGROUP BY `poi_pri`.`poi_name`",
+ "ref_doctype": "Purchase Order",
+ "report_name": "Purchase Order Items To Be Received or Billed1",
+ "report_type": "Query Report",
+ "roles": [
+  {
+   "role": "Purchase Manager"
+  },
+  {
+   "role": "Purchase User"
+  },
+  {
+   "role": "Stock User"
+  },
+  {
+   "role": "Stock Manager"
+  }
+ ]
+}
\ No newline at end of file
diff --git a/erpnext/stock/report/total_stock_summary/total_stock_summary.py b/erpnext/stock/report/total_stock_summary/total_stock_summary.py
index b25e096..41e2f86 100644
--- a/erpnext/stock/report/total_stock_summary/total_stock_summary.py
+++ b/erpnext/stock/report/total_stock_summary/total_stock_summary.py
@@ -15,8 +15,8 @@
 
 def get_columns():
 	columns = [
-		_("Company") + ":Link/Item:250",
-		_("Warehouse") + ":Link/Item:150",
+		_("Company") + ":Link/Company:250",
+		_("Warehouse") + ":Link/Warehouse:150",
 		_("Item") + ":Link/Item:150",
 		_("Description") + "::300",
 		_("Current Qty") + ":Float:100",
@@ -30,7 +30,7 @@
 
 	if filters.get("group_by") == "Warehouse":
 		if filters.get("company"):
-			conditions += " AND warehouse.company = %s" % frappe.db.escape(filters.get("company"), percent=False)
+			conditions += " AND warehouse.company = '%s'" % frappe.db.escape(filters.get("company"), percent=False)
 
 		conditions += " GROUP BY ledger.warehouse, item.item_code"
 		columns += "'' as company, ledger.warehouse"