Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: validation for internal transfer entry #34980

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions erpnext/accounts/doctype/sales_invoice/sales_invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ erpnext.accounts.SalesInvoiceController = class SalesInvoiceController extends e
}

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
Expand Down
11 changes: 10 additions & 1 deletion erpnext/controllers/accounts_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -405,6 +405,15 @@ def validate_inter_company_reference(self):
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
Expand Down
58 changes: 58 additions & 0 deletions erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1693,6 +1693,64 @@ def test_internal_pr_gl_entries(self):
# 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
Expand Down