Merge pull request #53128 from frappe/mergify/bp/version-15-hotfix/pr-53037

fix(stock): pass company to avoid document naming rule issue in QI (backport #53037)
This commit is contained in:
mergify[bot]
2026-03-03 15:56:44 +00:00
committed by GitHub
parent bd76ef29cc
commit 10b40836a9
4 changed files with 52 additions and 2 deletions

View File

@@ -1702,7 +1702,7 @@ def check_item_quality_inspection(doctype, items):
@frappe.whitelist()
def make_quality_inspections(doctype, docname, items):
def make_quality_inspections(company, doctype, docname, items):
if isinstance(items, str):
items = json.loads(items)
@@ -1721,6 +1721,7 @@ def make_quality_inspections(doctype, docname, items):
quality_inspection = frappe.get_doc(
{
"company": company,
"doctype": "Quality Inspection",
"inspection_type": "Incoming",
"inspected_by": frappe.session.user,

View File

@@ -2476,6 +2476,7 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
frappe.call({
method: "erpnext.controllers.stock_controller.make_quality_inspections",
args: {
company: me.frm.doc.company,
doctype: me.frm.doc.doctype,
docname: me.frm.doc.name,
items: selected_data,

View File

@@ -140,7 +140,8 @@ class TestQualityInspection(FrappeTestCase):
dn = create_delivery_note(item_code="_Test Item with QA", do_not_submit=True)
for item in dn.items:
item.sample_size = item.qty
quality_inspections = make_quality_inspections(dn.doctype, dn.name, dn.items)
quality_inspections = make_quality_inspections(dn.company, dn.doctype, dn.name, dn.items)
self.assertEqual(len(dn.items), len(quality_inspections))
# cleanup

View File

@@ -2258,6 +2258,53 @@ class TestStockEntry(FrappeTestCase):
frappe.db.set_single_value("Manufacturing Settings", "material_consumption", original_value)
def test_qi_creation_with_naming_rule_company_condition(self):
"""
Unit test case to check the document naming rule with company condition
For Quality Inspection, when created from Stock Entry.
"""
from erpnext.accounts.report.trial_balance.test_trial_balance import create_company
from erpnext.controllers.stock_controller import make_quality_inspections
from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse
# create a separate company to handle document naming rule with company condition
qc_company = create_company(company_name="Test Quality Company")
# create document naming rule based on that for Quality Inspection Doctype
qc_naming_rule = frappe.new_doc(
"Document Naming Rule", document_type="Quality Inspection", prefix="NQC.-ST-", prefix_digits=5
)
qc_naming_rule.append("conditions", {"field": "company", "condition": "=", "value": qc_company})
qc_naming_rule.save()
warehouse = create_warehouse(warehouse_name="Test QI Warehouse", company=qc_company)
item = create_item(
item_code="Test QI DNR Item",
is_stock_item=1,
)
# create inward stock entry
stock_entry = make_stock_entry(
item_code=item.item_code,
target=warehouse,
qty=10,
basic_rate=100,
inspection_required=True,
do_not_submit=True,
)
# create QI from Stock Entry and check the naming series generated.
qi = make_quality_inspections(
stock_entry.company,
stock_entry.doctype,
stock_entry.name,
stock_entry.as_dict().get("items"),
)
self.assertEqual(qi[0], "NQC-ST-00001")
# delete naming rule
frappe.delete_doc("Document Naming Rule", qc_naming_rule.name)
def make_serialized_item(**args):
args = frappe._dict(args)