Merge pull request #22454 from wojosc/patch-10

refactor: update customs_tariff_number.json
diff --git a/erpnext/controllers/trends.py b/erpnext/controllers/trends.py
index 092baa4..9b4b0eb 100644
--- a/erpnext/controllers/trends.py
+++ b/erpnext/controllers/trends.py
@@ -33,7 +33,7 @@
 			frappe.throw(_("{0} is mandatory").format(f))
 
 	if not frappe.db.exists("Fiscal Year", filters.get("fiscal_year")):
-		frappe.throw(_("Fiscal Year: {0} does not exists").format(filters.get("fiscal_year")))
+		frappe.throw(_("Fiscal Year {0} Does Not Exist").format(filters.get("fiscal_year")))
 
 	if filters.get("based_on") == filters.get("group_by"):
 		frappe.throw(_("'Based On' and 'Group By' can not be same"))
diff --git a/erpnext/loan_management/doctype/loan/loan.py b/erpnext/loan_management/doctype/loan/loan.py
index 76e10e5..4e805d4 100644
--- a/erpnext/loan_management/doctype/loan/loan.py
+++ b/erpnext/loan_management/doctype/loan/loan.py
@@ -235,8 +235,10 @@
 @frappe.whitelist()
 def create_loan_security_unpledge(loan, applicant_type, applicant, company, as_dict=1):
 	loan_security_pledge_details = frappe.db.sql("""
-		SELECT p.parent, p.loan_security, p.qty as qty FROM `tabLoan Security Pledge` lsp , `tabPledge` p
+		SELECT p.loan_security, sum(p.qty) as qty
+		FROM `tabLoan Security Pledge` lsp , `tabPledge` p
 		WHERE p.parent = lsp.name AND lsp.loan = %s AND lsp.docstatus = 1
+		GROUP BY p.loan_security
 	""",(loan), as_dict=1)
 
 	unpledge_request = frappe.new_doc("Loan Security Unpledge")
diff --git a/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py b/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py
index c28994e..9605045 100644
--- a/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py
+++ b/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py
@@ -116,7 +116,7 @@
 	def allocate_amounts(self, paid_entries):
 		self.set('repayment_details', [])
 		self.principal_amount_paid = 0
-		interest_paid = 0
+		interest_paid = self.amount_paid - self.penalty_amount
 
 		if self.amount_paid - self.penalty_amount > 0 and paid_entries:
 			interest_paid = self.amount_paid - self.penalty_amount
diff --git a/erpnext/loan_management/doctype/loan_security_price/loan_security_price.json b/erpnext/loan_management/doctype/loan_security_price/loan_security_price.json
index db260a4..a55b482 100644
--- a/erpnext/loan_management/doctype/loan_security_price/loan_security_price.json
+++ b/erpnext/loan_management/doctype/loan_security_price/loan_security_price.json
@@ -1,4 +1,5 @@
 {
+ "actions": [],
  "autoname": "LM-LSP-.####",
  "creation": "2019-09-03 18:20:31.382887",
  "doctype": "DocType",
@@ -46,6 +47,7 @@
    "fieldtype": "Currency",
    "in_list_view": 1,
    "label": "Loan Security Price",
+   "options": "Company:company:default_currency",
    "reqd": 1
   },
   {
@@ -79,7 +81,8 @@
    "read_only": 1
   }
  ],
- "modified": "2019-10-26 09:46:46.069667",
+ "links": [],
+ "modified": "2020-06-11 03:41:33.900340",
  "modified_by": "Administrator",
  "module": "Loan Management",
  "name": "Loan Security Price",
diff --git a/erpnext/loan_management/doctype/loan_security_shortfall/loan_security_shortfall.py b/erpnext/loan_management/doctype/loan_security_shortfall/loan_security_shortfall.py
index 308c438..ffd9673 100644
--- a/erpnext/loan_management/doctype/loan_security_shortfall/loan_security_shortfall.py
+++ b/erpnext/loan_management/doctype/loan_security_shortfall/loan_security_shortfall.py
@@ -19,7 +19,9 @@
 		return
 
 	if security_value >= loan_security_shortfall.shortfall_amount:
-		frappe.db.set_value("Loan Security Shortfall", loan_security_shortfall.name, "status", "Completed")
+		frappe.db.set_value("Loan Security Shortfall", loan_security_shortfall.name, {
+			"status": "Completed",
+			"shortfall_value": loan_security_shortfall.shortfall_amount})
 	else:
 		frappe.db.set_value("Loan Security Shortfall", loan_security_shortfall.name,
 			"shortfall_amount", loan_security_shortfall.shortfall_amount - security_value)
diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.py b/erpnext/manufacturing/doctype/production_plan/production_plan.py
index 560286e..c889237 100644
--- a/erpnext/manufacturing/doctype/production_plan/production_plan.py
+++ b/erpnext/manufacturing/doctype/production_plan/production_plan.py
@@ -98,11 +98,17 @@
 		elif self.get_items_from == "Material Request":
 			self.get_mr_items()
 
+	def get_so_mr_list(self, field, table):
+		"""Returns a list of Sales Orders or Material Requests from the respective tables"""
+		so_mr_list = [d.get(field) for d in self.get(table) if d.get(field)]
+		return so_mr_list
+
 	def get_so_items(self):
-		so_list = [d.sales_order for d in self.sales_orders if d.sales_order]
-		if not so_list:
-			msgprint(_("Please enter Sales Orders in the above table"))
-			return []
+		# Check for empty table or empty rows
+		if not self.get("sales_orders") or not self.get_so_mr_list("sales_order", "sales_orders"):
+			frappe.throw(_("Please fill the Sales Orders table"), title=_("Sales Orders Required"))
+
+		so_list = self.get_so_mr_list("sales_order", "sales_orders")
 
 		item_condition = ""
 		if self.item_code:
@@ -134,10 +140,11 @@
 		self.calculate_total_planned_qty()
 
 	def get_mr_items(self):
-		mr_list = [d.material_request for d in self.material_requests if d.material_request]
-		if not mr_list:
-			msgprint(_("Please enter Material Requests in the above table"))
-			return []
+		# Check for empty table or empty rows
+		if not self.get("material_requests") or not self.get_so_mr_list("material_request", "material_requests"):
+			frappe.throw(_("Please fill the Material Requests table"), title=_("Material Requests Required"))
+
+		mr_list = self.get_so_mr_list("material_request", "material_requests")
 
 		item_condition = ""
 		if self.item_code:
@@ -628,16 +635,19 @@
 
 	if warehouse_list:
 		warehouses = list(set(warehouse_list))
-	
+
 		if doc.get("for_warehouse") and doc.get("for_warehouse") in warehouses:
 			warehouses.remove(doc.get("for_warehouse"))
 
 		warehouse_list = None
 
 	doc['mr_items'] = []
+
 	po_items = doc.get('po_items') if doc.get('po_items') else doc.get('items')
-	if not po_items:
-		frappe.throw(_("Items are required to pull the raw materials which is associated with it."))
+	# Check for empty table or empty rows
+	if not po_items or not [row.get('item_code') for row in po_items if row.get('item_code')]:
+		frappe.throw(_("Items to Manufacture are required to pull the Raw Materials associated with it."),
+			title=_("Items Required"))
 
 	company = doc.get('company')
 	ignore_existing_ordered_qty = doc.get('ignore_existing_ordered_qty')
diff --git a/erpnext/payroll/doctype/salary_slip/salary_slip.json b/erpnext/payroll/doctype/salary_slip/salary_slip.json
index 663a3ef..88931c2 100644
--- a/erpnext/payroll/doctype/salary_slip/salary_slip.json
+++ b/erpnext/payroll/doctype/salary_slip/salary_slip.json
@@ -381,7 +381,6 @@
   {
    "fieldname": "earning",
    "fieldtype": "Column Break",
-   "label": "Earning",
    "oldfieldtype": "Column Break",
    "show_days": 1,
    "show_seconds": 1,
@@ -400,7 +399,6 @@
   {
    "fieldname": "deduction",
    "fieldtype": "Column Break",
-   "label": "Deduction",
    "oldfieldtype": "Column Break",
    "show_days": 1,
    "show_seconds": 1,
@@ -616,7 +614,7 @@
  "idx": 9,
  "is_submittable": 1,
  "links": [],
- "modified": "2020-06-22 14:42:43.921828",
+ "modified": "2020-06-25 14:42:43.921828",
  "modified_by": "Administrator",
  "module": "Payroll",
  "name": "Salary Slip",
diff --git a/erpnext/projects/doctype/timesheet/test_timesheet.py b/erpnext/projects/doctype/timesheet/test_timesheet.py
index 03b67b1..a5ce44d 100644
--- a/erpnext/projects/doctype/timesheet/test_timesheet.py
+++ b/erpnext/projects/doctype/timesheet/test_timesheet.py
@@ -140,52 +140,6 @@
 		settings.ignore_employee_time_overlap = initial_setting
 		settings.save()
 
-	def test_timesheet_std_working_hours(self):
-		emp = make_employee("test_employee_6@salary.com")
-
-		company = frappe.get_doc('Company', "_Test Company")
-		company.standard_working_hours = 8
-		company.save()
-
-		timesheet = frappe.new_doc("Timesheet")
-		timesheet.employee = emp
-		timesheet.company = '_Test Company'
-		timesheet.append(
-			'time_logs',
-			{
-				"activity_type": "_Test Activity Type",
-				"from_time": now_datetime(),
-				"to_time": now_datetime() + datetime.timedelta(days= 4)
-			}
-		)
-		timesheet.save()
-
-		ts = frappe.get_doc('Timesheet', timesheet.name)
-		self.assertEqual(ts.total_hours, 32)
-		ts.submit()
-		ts.cancel()
-
-		company = frappe.get_doc('Company', "_Test Company")
-		company.standard_working_hours = 0
-		company.save()
-
-		timesheet = frappe.new_doc("Timesheet")
-		timesheet.employee = emp
-		timesheet.company = '_Test Company'
-		timesheet.append(
-			'time_logs',
-			{
-				"activity_type": "_Test Activity Type",
-				"from_time": now_datetime(),
-				"to_time": now_datetime() + datetime.timedelta(days= 4)
-			}
-		)
-		timesheet.save()
-
-		ts = frappe.get_doc('Timesheet', timesheet.name)
-		self.assertEqual(ts.total_hours, 96)
-		ts.submit()
-		ts.cancel()
 
 def make_salary_structure_for_timesheet(employee):
 	salary_structure_name = "Timesheet Salary Structure Test"
diff --git a/erpnext/projects/doctype/timesheet/timesheet.js b/erpnext/projects/doctype/timesheet/timesheet.js
index defc18b..5de2930 100644
--- a/erpnext/projects/doctype/timesheet/timesheet.js
+++ b/erpnext/projects/doctype/timesheet/timesheet.js
@@ -162,19 +162,11 @@
 
 	to_time: function(frm, cdt, cdn) {
 		var child = locals[cdt][cdn];
-		var time_diff = (moment(child.to_time).diff(moment(child.from_time),"seconds")) / ( 60 * 60 * 24);
-		var std_working_hours = 0;
 
 		if(frm._setting_hours) return;
 
 		var hours = moment(child.to_time).diff(moment(child.from_time), "seconds") / 3600;
-		std_working_hours = time_diff * frappe.working_hours;
-
-		if (std_working_hours < hours && std_working_hours > 0) {
-			frappe.model.set_value(cdt, cdn, "hours", std_working_hours);
-		} else {
-			frappe.model.set_value(cdt, cdn, "hours", hours);
-		}
+		frappe.model.set_value(cdt, cdn, "hours", hours);
 	},
 
 	time_logs_add: function(frm) {
@@ -236,23 +228,12 @@
 
 	let d = moment(child.from_time);
 	if(child.hours) {
-		var time_diff = (moment(child.to_time).diff(moment(child.from_time),"seconds")) / (60 * 60 * 24);
-		var std_working_hours = 0;
-		var hours = moment(child.to_time).diff(moment(child.from_time), "seconds") / 3600;
-
-		std_working_hours = time_diff * frappe.working_hours;
-
-		if (std_working_hours < hours && std_working_hours > 0) {
-			frappe.model.set_value(cdt, cdn, "hours", std_working_hours);
-			frappe.model.set_value(cdt, cdn, "to_time", d.add(hours, "hours").format(frappe.defaultDatetimeFormat));
-		} else {
-			d.add(child.hours, "hours");
-			frm._setting_hours = true;
-			frappe.model.set_value(cdt, cdn, "to_time",
-				d.format(frappe.defaultDatetimeFormat)).then(() => {
-				frm._setting_hours = false;
-			});
-		}
+		d.add(child.hours, "hours");
+		frm._setting_hours = true;
+		frappe.model.set_value(cdt, cdn, "to_time",
+			d.format(frappe.defaultDatetimeFormat)).then(() => {
+			frm._setting_hours = false;
+		});
 	}
 };
 
diff --git a/erpnext/projects/doctype/timesheet/timesheet.py b/erpnext/projects/doctype/timesheet/timesheet.py
index e908216..7fe22be 100644
--- a/erpnext/projects/doctype/timesheet/timesheet.py
+++ b/erpnext/projects/doctype/timesheet/timesheet.py
@@ -24,7 +24,6 @@
 		self.set_status()
 		self.validate_dates()
 		self.validate_time_logs()
-		self.calculate_std_hours()
 		self.update_cost()
 		self.calculate_total_amounts()
 		self.calculate_percentage_billed()
@@ -91,17 +90,6 @@
 				self.start_date = getdate(start_date)
 				self.end_date = getdate(end_date)
 
-	def calculate_std_hours(self):
-		std_working_hours = frappe.get_value("Company", self.company, 'standard_working_hours')
-
-		for time in self.time_logs:
-			if time.from_time and time.to_time:
-				if flt(std_working_hours) and date_diff(time.to_time, time.from_time):
-					time.hours = flt(std_working_hours) * date_diff(time.to_time, time.from_time)
-				else:
-					if not time.hours:
-						time.hours = time_diff_in_hours(time.to_time, time.from_time)
-
 	def before_cancel(self):
 		self.set_status()
 
diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py
index 682dfed..d70c64f 100644
--- a/erpnext/selling/doctype/customer/customer.py
+++ b/erpnext/selling/doctype/customer/customer.py
@@ -388,8 +388,7 @@
 			credit_controller_users = get_users_with_role(credit_controller_role or "Sales Master Manager")
 
 			# form a list of emails and names to show to the user
-			credit_controller_users_list = [user for user in credit_controller_users if frappe.db.exists("Employee", {"prefered_email": user})]
-			credit_controller_users = [get_formatted_email(user).replace("<", "(").replace(">", ")") for user in credit_controller_users_list]
+			credit_controller_users = [get_formatted_email(user).replace("<", "(").replace(">", ")") for user in credit_controller_users]
 
 			if not credit_controller_users:
 				frappe.throw(_("Please contact your administrator to extend the credit limits for {0}.".format(customer)))
@@ -409,7 +408,7 @@
 						'customer': customer,
 						'customer_outstanding': customer_outstanding,
 						'credit_limit': credit_limit,
-						'credit_controller_users_list': credit_controller_users_list
+						'credit_controller_users_list': credit_controller_users
 					}
 				}
 			)
diff --git a/erpnext/setup/doctype/company/company.json b/erpnext/setup/doctype/company/company.json
index c25edc5..221044d 100644
--- a/erpnext/setup/doctype/company/company.json
+++ b/erpnext/setup/doctype/company/company.json
@@ -22,7 +22,6 @@
   "default_letter_head",
   "default_holiday_list",
   "default_finance_book",
-  "standard_working_hours",
   "default_selling_terms",
   "default_buying_terms",
   "default_warehouse_for_sales_return",
@@ -241,11 +240,6 @@
    "options": "Holiday List"
   },
   {
-   "fieldname": "standard_working_hours",
-   "fieldtype": "Float",
-   "label": "Standard Working Hours"
-  },
-  {
    "fieldname": "default_warehouse_for_sales_return",
    "fieldtype": "Link",
    "label": "Default warehouse for Sales Return",
@@ -746,7 +740,7 @@
  "image_field": "company_logo",
  "is_tree": 1,
  "links": [],
- "modified": "2020-06-20 11:38:43.178970",
+ "modified": "2020-06-24 12:45:31.462195",
  "modified_by": "Administrator",
  "module": "Setup",
  "name": "Company",
diff --git a/erpnext/setup/doctype/email_digest/email_digest.py b/erpnext/setup/doctype/email_digest/email_digest.py
index 7c0be3b..b30bd78 100644
--- a/erpnext/setup/doctype/email_digest/email_digest.py
+++ b/erpnext/setup/doctype/email_digest/email_digest.py
@@ -405,8 +405,8 @@
 
 		value, count = frappe.db.sql("""select ifnull((sum(grand_total)) - (sum(grand_total*per_billed/100)),0),
                     count(*) from `tabSales Order`
-					where (transaction_date <= %(to_date)s) and billing_status != "Fully Billed"
-					and status not in ('Closed','Cancelled', 'Completed') """, {"to_date": self.future_to_date})[0]
+					where (transaction_date <= %(to_date)s) and billing_status != "Fully Billed" and company = %(company)s
+					and status not in ('Closed','Cancelled', 'Completed') """, {"to_date": self.future_to_date, "company": self.company})[0]
 
 		label = get_link_to_report('Sales Order', label=self.meta.get_label("sales_orders_to_bill"),
 			report_type="Report Builder",
@@ -430,8 +430,8 @@
 
 		value, count = frappe.db.sql("""select ifnull((sum(grand_total)) - (sum(grand_total*per_delivered/100)),0),
 					count(*) from `tabSales Order`
-					where (transaction_date <= %(to_date)s) and delivery_status != "Fully Delivered"
-					and status not in ('Closed','Cancelled', 'Completed') """, {"to_date": self.future_to_date})[0]
+					where (transaction_date <= %(to_date)s) and delivery_status != "Fully Delivered" and company = %(company)s
+					and status not in ('Closed','Cancelled', 'Completed') """, {"to_date": self.future_to_date, "company": self.company})[0]
 
 		label = get_link_to_report('Sales Order', label=self.meta.get_label("sales_orders_to_deliver"),
 			report_type="Report Builder",
@@ -455,8 +455,8 @@
 
 		value, count = frappe.db.sql("""select ifnull((sum(grand_total))-(sum(grand_total*per_received/100)),0),
                     count(*) from `tabPurchase Order`
-					where (transaction_date <= %(to_date)s) and per_received < 100
-					and status not in ('Closed','Cancelled', 'Completed') """, {"to_date": self.future_to_date})[0]
+					where (transaction_date <= %(to_date)s) and per_received < 100 and company = %(company)s
+					and status not in ('Closed','Cancelled', 'Completed') """, {"to_date": self.future_to_date, "company": self.company})[0]
 
 		label = get_link_to_report('Purchase Order', label=self.meta.get_label("purchase_orders_to_receive"),
 			report_type="Report Builder",
@@ -480,8 +480,8 @@
 
 		value, count = frappe.db.sql("""select ifnull((sum(grand_total)) - (sum(grand_total*per_billed/100)),0),
                     count(*) from `tabPurchase Order`
-					where (transaction_date <= %(to_date)s) and per_billed < 100
-					and status not in ('Closed','Cancelled', 'Completed') """, {"to_date": self.future_to_date})[0]
+					where (transaction_date <= %(to_date)s) and per_billed < 100 and company = %(company)s
+					and status not in ('Closed','Cancelled', 'Completed') """, {"to_date": self.future_to_date, "company": self.company})[0]
 
 		label = get_link_to_report('Purchase Order', label=self.meta.get_label("purchase_orders_to_bill"),
 			report_type="Report Builder",
diff --git a/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.js b/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.js
index e1510f5..ffc5dab 100644
--- a/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.js
+++ b/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.js
@@ -13,6 +13,12 @@
 	},
 	enable_checkout: function(){
 		toggle_mandatory(cur_frm)
+	},
+	enabled: function() {
+		if (cur_frm.doc.enabled === 1) {
+			cur_frm.doc.show_configure_button = 1;
+			cur_frm.refresh_field('show_configure_button');
+		}
 	}
 });
 
diff --git a/erpnext/shopping_cart/product_info.py b/erpnext/shopping_cart/product_info.py
index 7c08f5b..29617a8 100644
--- a/erpnext/shopping_cart/product_info.py
+++ b/erpnext/shopping_cart/product_info.py
@@ -55,7 +55,7 @@
 
 def set_product_info_for_website(item):
 	"""set product price uom for website"""
-	product_info = get_product_info_for_website(item.item_code, skip_quotation_creation=True)
+	product_info = get_product_info_for_website(item.item_code, skip_quotation_creation=True).get("product_info")
 
 	if product_info:
 		item.update(product_info)
diff --git a/erpnext/stock/doctype/serial_no/serial_no.json b/erpnext/stock/doctype/serial_no/serial_no.json
index d9f8b62..2be14c8 100644
--- a/erpnext/stock/doctype/serial_no/serial_no.json
+++ b/erpnext/stock/doctype/serial_no/serial_no.json
@@ -1,7 +1,6 @@
 {
  "actions": [],
  "allow_import": 1,
- "allow_rename": 1,
  "autoname": "field:serial_no",
  "creation": "2013-05-16 10:59:15",
  "description": "Distinct unit of an Item",
@@ -427,7 +426,7 @@
  "icon": "fa fa-barcode",
  "idx": 1,
  "links": [],
- "modified": "2020-05-21 19:29:58.517772",
+ "modified": "2020-06-25 15:53:50.900855",
  "modified_by": "Administrator",
  "module": "Stock",
  "name": "Serial No",
diff --git a/erpnext/support/doctype/issue/issue.js b/erpnext/support/doctype/issue/issue.js
index e7e5bd3..9e15757 100644
--- a/erpnext/support/doctype/issue/issue.js
+++ b/erpnext/support/doctype/issue/issue.js
@@ -79,7 +79,7 @@
 					method: "erpnext.support.doctype.issue.issue.make_task",
 					frm: frm
 				});
-			}, __("Make"));
+			}, __("Create"));
 
 		} else {
 			if (frm.doc.service_level_agreement) {
@@ -232,4 +232,4 @@
 	} else {
 		return {"diff_display": "Failed", "indicator": "red"};
 	}
-}
\ No newline at end of file
+}