Skip to content

Commit bffb7cf

Browse files
authored
Merge pull request #53129 from frappe/mergify/bp/version-16-hotfix/pr-53037
fix(stock): pass company to avoid document naming rule issue in QI (backport #53037)
2 parents a399b85 + 3e8ebf8 commit bffb7cf

4 files changed

Lines changed: 56 additions & 2 deletions

File tree

erpnext/controllers/stock_controller.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2128,7 +2128,9 @@ def check_item_quality_inspection(doctype, items):
21282128

21292129

21302130
@frappe.whitelist()
2131-
def make_quality_inspections(doctype, docname, items, inspection_type):
2131+
def make_quality_inspections(
2132+
company: str, doctype: str, docname: str, items: str | list, inspection_type: str
2133+
):
21322134
if isinstance(items, str):
21332135
items = json.loads(items)
21342136

@@ -2147,6 +2149,7 @@ def make_quality_inspections(doctype, docname, items, inspection_type):
21472149

21482150
quality_inspection = frappe.get_doc(
21492151
{
2152+
"company": company,
21502153
"doctype": "Quality Inspection",
21512154
"inspection_type": inspection_type,
21522155
"inspected_by": frappe.session.user,

erpnext/public/js/controllers/transaction.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2966,6 +2966,7 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
29662966
frappe.call({
29672967
method: "erpnext.controllers.stock_controller.make_quality_inspections",
29682968
args: {
2969+
company: me.frm.doc.company,
29692970
doctype: me.frm.doc.doctype,
29702971
docname: me.frm.doc.name,
29712972
items: selected_data,

erpnext/stock/doctype/quality_inspection/test_quality_inspection.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ def test_make_quality_inspections_from_linked_document(self):
142142
inspection_type = "Outgoing"
143143
for item in dn.items:
144144
item.sample_size = item.qty
145-
quality_inspections = make_quality_inspections(dn.doctype, dn.name, dn.items, inspection_type)
145+
quality_inspections = make_quality_inspections(
146+
dn.company, dn.doctype, dn.name, dn.items, inspection_type
147+
)
146148
self.assertEqual(len(dn.items), len(quality_inspections))
147149

148150
# cleanup

erpnext/stock/doctype/stock_entry/test_stock_entry.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2415,6 +2415,54 @@ def test_validation_as_per_bom_with_continuous_raw_material_consumption(self):
24152415
frappe.get_doc(_make_stock_entry(work_order.name, "Material Consumption for Manufacture", 5)).submit()
24162416
frappe.get_doc(_make_stock_entry(work_order.name, "Manufacture", 5)).submit()
24172417

2418+
def test_qi_creation_with_naming_rule_company_condition(self):
2419+
"""
2420+
Unit test case to check the document naming rule with company condition
2421+
For Quality Inspection, when created from Stock Entry.
2422+
"""
2423+
from erpnext.accounts.report.trial_balance.test_trial_balance import create_company
2424+
from erpnext.controllers.stock_controller import make_quality_inspections
2425+
from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse
2426+
2427+
# create a separate company to handle document naming rule with company condition
2428+
qc_company = create_company(company_name="Test Quality Company")
2429+
2430+
# create document naming rule based on that for Quality Inspection Doctype
2431+
qc_naming_rule = frappe.new_doc(
2432+
"Document Naming Rule", document_type="Quality Inspection", prefix="NQC.-ST-", prefix_digits=5
2433+
)
2434+
qc_naming_rule.append("conditions", {"field": "company", "condition": "=", "value": qc_company})
2435+
qc_naming_rule.save()
2436+
2437+
warehouse = create_warehouse(warehouse_name="Test QI Warehouse", company=qc_company)
2438+
item = create_item(
2439+
item_code="Test QI DNR Item",
2440+
is_stock_item=1,
2441+
)
2442+
2443+
# create inward stock entry
2444+
stock_entry = make_stock_entry(
2445+
item_code=item.item_code,
2446+
target=warehouse,
2447+
qty=10,
2448+
basic_rate=100,
2449+
inspection_required=True,
2450+
do_not_submit=True,
2451+
)
2452+
2453+
# create QI from Stock Entry and check the naming series generated.
2454+
qi = make_quality_inspections(
2455+
stock_entry.company,
2456+
stock_entry.doctype,
2457+
stock_entry.name,
2458+
stock_entry.as_dict().get("items"),
2459+
"Incoming",
2460+
)
2461+
self.assertEqual(qi[0], "NQC-ST-00001")
2462+
2463+
# delete naming rule
2464+
frappe.delete_doc("Document Naming Rule", qc_naming_rule.name)
2465+
24182466

24192467
def make_serialized_item(self, **args):
24202468
args = frappe._dict(args)

0 commit comments

Comments
 (0)