Merge branch 'develop' of https://github.com/frappe/erpnext into internal_transfer_precision_fixes
diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py
index 5e9c069..e8e9076 100644
--- a/erpnext/controllers/selling_controller.py
+++ b/erpnext/controllers/selling_controller.py
@@ -442,11 +442,17 @@
 				# For internal transfers use incoming rate as the valuation rate
 				if self.is_internal_transfer():
 					if d.doctype == "Packed Item":
-						incoming_rate = flt(d.incoming_rate * d.conversion_factor, d.precision("incoming_rate"))
+						incoming_rate = flt(
+							flt(d.incoming_rate, d.precision("incoming_rate")) * d.conversion_factor,
+							d.precision("incoming_rate"),
+						)
 						if d.incoming_rate != incoming_rate:
 							d.incoming_rate = incoming_rate
 					else:
-						rate = flt(d.incoming_rate * d.conversion_factor, d.precision("rate"))
+						rate = flt(
+							flt(d.incoming_rate, d.precision("incoming_rate")) * d.conversion_factor,
+							d.precision("rate"),
+						)
 						if d.rate != rate:
 							d.rate = rate
 							frappe.msgprint(
diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py
index 9149b4d..58cfc4f 100644
--- a/erpnext/controllers/stock_controller.py
+++ b/erpnext/controllers/stock_controller.py
@@ -142,13 +142,15 @@
 		warehouse_with_no_account = []
 		precision = self.get_debit_field_precision()
 		for item_row in voucher_details:
-
 			sle_list = sle_map.get(item_row.name)
+			sle_rounding_diff = 0.0
 			if sle_list:
 				for sle in sle_list:
 					if warehouse_account.get(sle.warehouse):
 						# from warehouse account
 
+						sle_rounding_diff += flt(sle.stock_value_difference, precision)
+
 						self.check_expense_account(item_row)
 
 						# expense account/ target_warehouse / source_warehouse
@@ -191,6 +193,42 @@
 					elif sle.warehouse not in warehouse_with_no_account:
 						warehouse_with_no_account.append(sle.warehouse)
 
+			if sle_rounding_diff > 0:
+				expense_account = item_row.get("expense_account")
+				target_warehouse_account = warehouse_account[item_row.get("target_warehouse")]["account"]
+				source_warehouse_account = warehouse_account[item_row.get("warehouse")]["account"]
+
+				gl_list.append(
+					self.get_gl_dict(
+						{
+							"account": target_warehouse_account or expense_account,
+							"against": expense_account,
+							"cost_center": item_row.cost_center,
+							"project": item_row.project or self.get("project"),
+							"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
+							"debit": sle_rounding_diff,
+							"is_opening": item_row.get("is_opening") or self.get("is_opening") or "No",
+						},
+						warehouse_account[sle.warehouse]["account_currency"],
+						item=item_row,
+					)
+				)
+
+				gl_list.append(
+					self.get_gl_dict(
+						{
+							"account": source_warehouse_account or expense_account,
+							"against": target_warehouse_account,
+							"cost_center": item_row.cost_center,
+							"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
+							"debit": -1 * sle_rounding_diff,
+							"project": item_row.get("project") or self.get("project"),
+							"is_opening": item_row.get("is_opening") or self.get("is_opening") or "No",
+						},
+						item=item_row,
+					)
+				)
+
 		if warehouse_with_no_account:
 			for wh in warehouse_with_no_account:
 				if frappe.db.get_value("Warehouse", wh, "company"):