fix: conflicts
diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js
index 28fb649..9a5b750 100644
--- a/erpnext/public/js/controllers/taxes_and_totals.js
+++ b/erpnext/public/js/controllers/taxes_and_totals.js
@@ -3,6 +3,7 @@
 
 erpnext.taxes_and_totals = erpnext.payments.extend({
 	setup: function() {},
+
 	apply_pricing_rule_on_item: function(item){
 		let effective_item_rate = item.price_list_rate;
 		if (item.parenttype === "Sales Order" && item.blanket_order_rate) {
@@ -38,6 +39,11 @@
 			this.calculate_total_advance(update_paid_amount);
 		}
 
+		if (this.frm.doc.doctype == "Sales Invoice" && this.frm.doc.is_pos &&
+			this.frm.doc.is_return) {
+			this.update_paid_amount_for_return();
+		}
+
 		// Sales person's commission
 		if(in_list(["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"], this.frm.doc.doctype)) {
 			this.calculate_commission();
@@ -634,23 +640,58 @@
 		}
 	},
 
-	set_default_payment: function(total_amount_to_pay, update_paid_amount){
+	update_paid_amount_for_return: function() {
+		var grand_total = this.frm.doc.rounded_total || this.frm.doc.grand_total;
+
+		if(this.frm.doc.party_account_currency == this.frm.doc.currency) {
+			var total_amount_to_pay = flt((grand_total - this.frm.doc.total_advance
+				- this.frm.doc.write_off_amount), precision("grand_total"));
+		} else {
+			var total_amount_to_pay = flt(
+				(flt(grand_total*this.frm.doc.conversion_rate, precision("grand_total"))
+					- this.frm.doc.total_advance - this.frm.doc.base_write_off_amount),
+				precision("base_grand_total")
+			);
+		}
+
+		frappe.db.get_value('Sales Invoice Payment', {'parent': this.frm.doc.pos_profile, 'default': 1},
+			['mode_of_payment', 'account', 'type'], (value) => {
+				if (this.frm.is_dirty()) {
+					frappe.model.clear_table(this.frm.doc, 'payments');
+					if (value) {
+						let row = frappe.model.add_child(this.frm.doc, 'Sales Invoice Payment', 'payments');
+						row.mode_of_payment = value.mode_of_payment;
+						row.type = value.type;
+						row.account = value.account;
+						row.default = 1;
+						row.amount = total_amount_to_pay;
+					} else {
+						this.frm.set_value('is_pos', 1);
+					}
+					this.frm.refresh_fields();
+				}
+			}, 'Sales Invoice');
+
+		this.calculate_paid_amount();
+	},
+
+	set_default_payment: function(total_amount_to_pay, update_paid_amount) {
 		var me = this;
 		var payment_status = true;
-		if(this.frm.doc.is_pos && (update_paid_amount===undefined || update_paid_amount)){
-			$.each(this.frm.doc['payments'] || [], function(index, data){
+		if(this.frm.doc.is_pos && (update_paid_amount===undefined || update_paid_amount)) {
+			$.each(this.frm.doc['payments'] || [], function(index, data) {
 				if(data.default && payment_status && total_amount_to_pay > 0) {
 					data.base_amount = flt(total_amount_to_pay, precision("base_amount"));
 					data.amount = flt(total_amount_to_pay / me.frm.doc.conversion_rate, precision("amount"));
 					payment_status = false;
-				}else if(me.frm.doc.paid_amount){
+				} else if(me.frm.doc.paid_amount) {
 					data.amount = 0.0;
 				}
 			});
 		}
 	},
 
-	calculate_paid_amount: function(){
+	calculate_paid_amount: function() {
 		var me = this;
 		var paid_amount = 0.0;
 		var base_paid_amount = 0.0;
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index 51ab48a..fea2d5e 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -490,7 +490,7 @@
 							cost_center: item.cost_center,
 							tax_category: me.frm.doc.tax_category,
 							item_tax_template: item.item_tax_template,
-							child_docname: item.name,
+							child_docname: item.name
 						}
 					},
 
@@ -504,7 +504,20 @@
 										me.apply_product_discount(d.free_item_data);
 									}
 								},
-								() => me.frm.script_manager.trigger("price_list_rate", cdt, cdn),
+								() => {
+									// for internal customer instead of pricing rule directly apply valuation rate on item
+									if (me.frm.doc.is_internal_customer || me.frm.doc.is_internal_supplier) {
+										me.get_incoming_rate(item, me.frm.posting_date, me.frm.posting_time,
+											me.frm.doc.doctype, me.frm.doc.company);
+									} else {
+										me.frm.script_manager.trigger("price_list_rate", cdt, cdn);
+									}
+								},
+								() => {
+									if (me.frm.doc.is_internal_customer || me.frm.doc.is_internal_supplier) {
+										me.calculate_taxes_and_totals();
+									}
+								},
 								() => me.toggle_conversion_factor(item),
 								() => {
 									if(show_batch_dialog && !frappe.flags.hide_serial_batch_dialog) {
@@ -528,6 +541,31 @@
 		}
 	},
 
+	get_incoming_rate: function(item, posting_date, posting_time, voucher_type, company) {
+
+		let item_args = {
+			'item_code': item.item_code,
+			'warehouse': in_list('Purchase Receipt', 'Purchase Invoice') ? item.from_warehouse : item.warehouse,
+			'posting_date': posting_date,
+			'posting_time': posting_time,
+			'qty': item.qty * item.conversion_factor,
+			'serial_no': item.serial_no,
+			'voucher_type': voucher_type,
+			'company': company,
+			'allow_zero_valuation_rate': item.allow_zero_valuation_rate
+		}
+
+		frappe.call({
+			method: 'erpnext.stock.utils.get_incoming_rate',
+			args: {
+				args: item_args
+			},
+			callback: function(r) {
+				frappe.model.set_value(item.doctype, item.name, 'rate', r.message);
+			}
+		});
+	},
+
 	add_taxes_from_item_tax_template: function(item_tax_map) {
 		let me = this;
 
@@ -941,15 +979,19 @@
 	},
 
 	conversion_factor: function(doc, cdt, cdn, dont_fetch_price_list_rate) {
-		if(doc.doctype != 'Material Request' && frappe.meta.get_docfield(cdt, "stock_qty", cdn)) {
+		if(frappe.meta.get_docfield(cdt, "stock_qty", cdn)) {
 			var item = frappe.get_doc(cdt, cdn);
 			frappe.model.round_floats_in(item, ["qty", "conversion_factor"]);
 			item.stock_qty = flt(item.qty * item.conversion_factor, precision("stock_qty", item));
-			item.total_weight = flt(item.stock_qty * item.weight_per_unit);
 			refresh_field("stock_qty", item.name, item.parentfield);
-			refresh_field("total_weight", item.name, item.parentfield);
 			this.toggle_conversion_factor(item);
-			this.calculate_net_weight();
+
+			if(doc.doctype != "Material Request") {
+				item.total_weight = flt(item.stock_qty * item.weight_per_unit);
+				refresh_field("total_weight", item.name, item.parentfield);
+				this.calculate_net_weight();
+			}
+
 			if (!dont_fetch_price_list_rate &&
 				frappe.meta.has_field(doc.doctype, "price_list_currency")) {
 				this.apply_price_list(item, true);