mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-16 13:32:13 +00:00
* fix: incorrect quality inspection linked in purchase receipt (#44985)
(cherry picked from commit b84c8ff960)
# Conflicts:
# erpnext/stock/doctype/quality_inspection/quality_inspection.json
* chore: fix conflicts
---------
Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
@@ -2309,6 +2309,12 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
|
|||||||
fieldname: "batch_no",
|
fieldname: "batch_no",
|
||||||
label: __("Batch No"),
|
label: __("Batch No"),
|
||||||
hidden: true
|
hidden: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldtype: "Data",
|
||||||
|
fieldname: "child_row_reference",
|
||||||
|
label: __("Child Row Reference"),
|
||||||
|
hidden: true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -2352,14 +2358,14 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
|
|||||||
if (this.has_inspection_required(item)) {
|
if (this.has_inspection_required(item)) {
|
||||||
let dialog_items = dialog.fields_dict.items;
|
let dialog_items = dialog.fields_dict.items;
|
||||||
dialog_items.df.data.push({
|
dialog_items.df.data.push({
|
||||||
"docname": item.name,
|
|
||||||
"item_code": item.item_code,
|
"item_code": item.item_code,
|
||||||
"item_name": item.item_name,
|
"item_name": item.item_name,
|
||||||
"qty": item.qty,
|
"qty": item.qty,
|
||||||
"description": item.description,
|
"description": item.description,
|
||||||
"serial_no": item.serial_no,
|
"serial_no": item.serial_no,
|
||||||
"batch_no": item.batch_no,
|
"batch_no": item.batch_no,
|
||||||
"sample_size": item.sample_quantity
|
"sample_size": item.sample_quantity,
|
||||||
|
"child_row_reference": item.name,
|
||||||
});
|
});
|
||||||
dialog_items.grid.refresh();
|
dialog_items.grid.refresh();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
"inspection_type",
|
"inspection_type",
|
||||||
"reference_type",
|
"reference_type",
|
||||||
"reference_name",
|
"reference_name",
|
||||||
|
"child_row_reference",
|
||||||
"section_break_7",
|
"section_break_7",
|
||||||
"item_code",
|
"item_code",
|
||||||
"item_serial_no",
|
"item_serial_no",
|
||||||
@@ -238,6 +239,15 @@
|
|||||||
"fieldname": "manual_inspection",
|
"fieldname": "manual_inspection",
|
||||||
"fieldtype": "Check",
|
"fieldtype": "Check",
|
||||||
"label": "Manual Inspection"
|
"label": "Manual Inspection"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "child_row_reference",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"hidden": 1,
|
||||||
|
"label": "Child Row Reference",
|
||||||
|
"no_copy": 1,
|
||||||
|
"print_hide": 1,
|
||||||
|
"read_only": 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"icon": "fa fa-search",
|
"icon": "fa fa-search",
|
||||||
@@ -245,7 +255,7 @@
|
|||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2023-08-23 11:56:50.282878",
|
"modified": "2024-12-30 19:08:16.611192",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Stock",
|
"module": "Stock",
|
||||||
"name": "Quality Inspection",
|
"name": "Quality Inspection",
|
||||||
@@ -272,4 +282,4 @@
|
|||||||
"sort_field": "modified",
|
"sort_field": "modified",
|
||||||
"sort_order": "ASC",
|
"sort_order": "ASC",
|
||||||
"states": []
|
"states": []
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ class QualityInspection(Document):
|
|||||||
amended_from: DF.Link | None
|
amended_from: DF.Link | None
|
||||||
batch_no: DF.Link | None
|
batch_no: DF.Link | None
|
||||||
bom_no: DF.Link | None
|
bom_no: DF.Link | None
|
||||||
|
child_row_reference: DF.Data | None
|
||||||
description: DF.SmallText | None
|
description: DF.SmallText | None
|
||||||
inspected_by: DF.Link
|
inspected_by: DF.Link
|
||||||
inspection_type: DF.Literal["", "Incoming", "Outgoing", "In Process"]
|
inspection_type: DF.Literal["", "Incoming", "Outgoing", "In Process"]
|
||||||
@@ -74,6 +75,64 @@ class QualityInspection(Document):
|
|||||||
self.inspect_and_set_status()
|
self.inspect_and_set_status()
|
||||||
|
|
||||||
self.validate_inspection_required()
|
self.validate_inspection_required()
|
||||||
|
self.set_child_row_reference()
|
||||||
|
|
||||||
|
def set_child_row_reference(self):
|
||||||
|
if self.child_row_reference:
|
||||||
|
return
|
||||||
|
|
||||||
|
if not (self.reference_type and self.reference_name):
|
||||||
|
return
|
||||||
|
|
||||||
|
doctype = self.reference_type + " Item"
|
||||||
|
if self.reference_type == "Stock Entry":
|
||||||
|
doctype = "Stock Entry Detail"
|
||||||
|
|
||||||
|
child_row_references = frappe.get_all(
|
||||||
|
doctype,
|
||||||
|
filters={"parent": self.reference_name, "item_code": self.item_code},
|
||||||
|
pluck="name",
|
||||||
|
)
|
||||||
|
|
||||||
|
if not child_row_references:
|
||||||
|
return
|
||||||
|
|
||||||
|
if len(child_row_references) == 1:
|
||||||
|
self.child_row_reference = child_row_references[0]
|
||||||
|
else:
|
||||||
|
self.distribute_child_row_reference(child_row_references)
|
||||||
|
|
||||||
|
def distribute_child_row_reference(self, child_row_references):
|
||||||
|
quality_inspections = frappe.get_all(
|
||||||
|
"Quality Inspection",
|
||||||
|
filters={
|
||||||
|
"reference_name": self.reference_name,
|
||||||
|
"item_code": self.item_code,
|
||||||
|
"docstatus": ("<", 2),
|
||||||
|
},
|
||||||
|
fields=["name", "child_row_reference", "docstatus"],
|
||||||
|
order_by="child_row_reference desc",
|
||||||
|
)
|
||||||
|
|
||||||
|
for row in quality_inspections:
|
||||||
|
if not child_row_references:
|
||||||
|
break
|
||||||
|
|
||||||
|
if row.child_row_reference and row.child_row_reference in child_row_references:
|
||||||
|
child_row_references.remove(row.child_row_reference)
|
||||||
|
continue
|
||||||
|
|
||||||
|
if row.docstatus == 1:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if row.name == self.name:
|
||||||
|
self.child_row_reference = child_row_references[0]
|
||||||
|
else:
|
||||||
|
frappe.db.set_value(
|
||||||
|
"Quality Inspection", row.name, "child_row_reference", child_row_references[0]
|
||||||
|
)
|
||||||
|
|
||||||
|
child_row_references.remove(child_row_references[0])
|
||||||
|
|
||||||
def validate_inspection_required(self):
|
def validate_inspection_required(self):
|
||||||
if self.reference_type in ["Purchase Receipt", "Purchase Invoice"] and not frappe.get_cached_value(
|
if self.reference_type in ["Purchase Receipt", "Purchase Invoice"] and not frappe.get_cached_value(
|
||||||
@@ -157,35 +216,38 @@ class QualityInspection(Document):
|
|||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
args = [quality_inspection, self.modified, self.reference_name, self.item_code]
|
|
||||||
doctype = self.reference_type + " Item"
|
doctype = self.reference_type + " Item"
|
||||||
|
|
||||||
if self.reference_type == "Stock Entry":
|
if self.reference_type == "Stock Entry":
|
||||||
doctype = "Stock Entry Detail"
|
doctype = "Stock Entry Detail"
|
||||||
|
|
||||||
if self.reference_type and self.reference_name:
|
if doctype and self.reference_name:
|
||||||
conditions = ""
|
child_doc = frappe.qb.DocType(doctype)
|
||||||
|
|
||||||
|
query = (
|
||||||
|
frappe.qb.update(child_doc)
|
||||||
|
.set(child_doc.quality_inspection, quality_inspection)
|
||||||
|
.where(
|
||||||
|
(child_doc.parent == self.reference_name) & (child_doc.item_code == self.item_code)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
if self.batch_no and self.docstatus == 1:
|
if self.batch_no and self.docstatus == 1:
|
||||||
conditions += " and t1.batch_no = %s"
|
query = query.where(child_doc.batch_no == self.batch_no)
|
||||||
args.append(self.batch_no)
|
|
||||||
|
|
||||||
if self.docstatus == 2: # if cancel, then remove qi link wherever same name
|
if self.docstatus == 2: # if cancel, then remove qi link wherever same name
|
||||||
conditions += " and t1.quality_inspection = %s"
|
query = query.where(child_doc.quality_inspection == self.name)
|
||||||
args.append(self.name)
|
|
||||||
|
|
||||||
frappe.db.sql(
|
if self.child_row_reference:
|
||||||
f"""
|
query = query.where(child_doc.name == self.child_row_reference)
|
||||||
UPDATE
|
|
||||||
`tab{doctype}` t1, `tab{self.reference_type}` t2
|
query.run()
|
||||||
SET
|
|
||||||
t1.quality_inspection = %s, t2.modified = %s
|
frappe.db.set_value(
|
||||||
WHERE
|
self.reference_type,
|
||||||
t1.parent = %s
|
self.reference_name,
|
||||||
and t1.item_code = %s
|
"modified",
|
||||||
and t1.parent = t2.name
|
self.modified,
|
||||||
{conditions}
|
|
||||||
""",
|
|
||||||
args,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def inspect_and_set_status(self):
|
def inspect_and_set_status(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user