fix: validation for internal transfer entry
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
index 56e412b..8cb2950 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
@@ -334,6 +334,7 @@
}
make_inter_company_invoice() {
+ let me = this;
frappe.model.open_mapped_doc({
method: "erpnext.accounts.doctype.sales_invoice.sales_invoice.make_inter_company_purchase_invoice",
frm: me.frm
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index c741622..642d51c 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -5,7 +5,7 @@
import json
import frappe
-from frappe import _, throw
+from frappe import _, bold, throw
from frappe.model.workflow import get_workflow_name, is_transition_condition_satisfied
from frappe.query_builder.functions import Abs, Sum
from frappe.utils import (
@@ -405,6 +405,15 @@
msg += _("Please create purchase from internal sale or delivery document itself")
frappe.throw(msg, title=_("Internal Sales Reference Missing"))
+ label = "Delivery Note Item" if self.doctype == "Purchase Receipt" else "Sales Invoice Item"
+
+ field = frappe.scrub(label)
+
+ for row in self.get("items"):
+ if not row.get(field):
+ msg = f"At Row {row.idx}: The field {bold(label)} is mandatory for internal transfer"
+ frappe.throw(_(msg), title=_("Internal Transfer Reference Missing"))
+
def disable_pricing_rule_on_internal_transfer(self):
if not self.get("ignore_pricing_rule") and self.is_internal_transfer():
self.ignore_pricing_rule = 1
diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
index 8af279a..c34f9da 100644
--- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
+++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
@@ -1693,6 +1693,64 @@
# Value of Stock Account should be equal to the sum of Stock Value Difference
self.assertEqual(stock_account_value, stock_diff)
+ def test_internal_pr_reference(self):
+ item = make_item(properties={"is_stock_item": 1, "valuation_rate": 100})
+ customer = "_Test Internal Customer 2"
+ company = "_Test Company with perpetual inventory"
+ from_warehouse = create_warehouse("_Test Internal From Warehouse New 1", company=company)
+ target_warehouse = create_warehouse("_Test Internal GIT Warehouse New 1", company=company)
+ to_warehouse = create_warehouse("_Test Internal To Warehouse New 1", company=company)
+
+ # Step 2: Create Stock Entry (Material Receipt)
+ from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry
+
+ make_stock_entry(
+ purpose="Material Receipt",
+ item_code=item.name,
+ qty=15,
+ company=company,
+ to_warehouse=from_warehouse,
+ )
+
+ # Step 3: Create Delivery Note with Internal Customer
+ from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note
+
+ dn = create_delivery_note(
+ item_code=item.name,
+ company=company,
+ customer=customer,
+ cost_center="Main - TCP1",
+ expense_account="Cost of Goods Sold - TCP1",
+ qty=10,
+ rate=100,
+ warehouse=from_warehouse,
+ target_warehouse=target_warehouse,
+ )
+
+ # Step 4: Create Internal Purchase Receipt
+ from erpnext.controllers.status_updater import OverAllowanceError
+ from erpnext.stock.doctype.delivery_note.delivery_note import make_inter_company_purchase_receipt
+
+ pr = make_inter_company_purchase_receipt(dn.name)
+ pr.inter_company_reference = ""
+ self.assertRaises(frappe.ValidationError, pr.save)
+
+ pr.inter_company_reference = dn.name
+ pr.items[0].qty = 10
+ pr.items[0].from_warehouse = target_warehouse
+ pr.items[0].warehouse = to_warehouse
+ pr.items[0].rejected_warehouse = from_warehouse
+ pr.save()
+
+ delivery_note_item = pr.items[0].delivery_note_item
+ pr.items[0].delivery_note_item = ""
+
+ self.assertRaises(frappe.ValidationError, pr.save)
+
+ pr.load_from_db()
+ pr.items[0].delivery_note_item = delivery_note_item
+ pr.save()
+
def prepare_data_for_internal_transfer():
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_internal_supplier