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: QC mapping in sales/purchase with same items #42219

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
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/controllers/stock_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -1510,6 +1510,7 @@ def make_quality_inspections(doctype, docname, items, inspection_type):
"sample_size": flt(item.get("sample_size")),
"item_serial_no": item.get("serial_no").split("\n")[0] if item.get("serial_no") else None,
"batch_no": item.get("batch_no"),
"rowname": item.get("docname"),
}
).insert()
quality_inspection.save()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"sample_size",
"column_break1",
"item_name",
"rowname",
"description",
"bom_no",
"specification_details",
Expand Down Expand Up @@ -238,14 +239,21 @@
"fieldname": "manual_inspection",
"fieldtype": "Check",
"label": "Manual Inspection"
},
{
"fieldname": "rowname",
"fieldtype": "Data",
"hidden": 1,
"label": "Rowname",
"read_only": 1
}
],
"icon": "fa fa-search",
"idx": 1,
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2024-03-27 13:10:28.680815",
"modified": "2024-07-08 12:08:50.904016",
"modified_by": "Administrator",
"module": "Stock",
"name": "Quality Inspection",
Expand Down
51 changes: 18 additions & 33 deletions erpnext/stock/doctype/quality_inspection/quality_inspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class QualityInspection(Document):
]
remarks: DF.Text | None
report_date: DF.Date
rowname: DF.Data | None
sample_size: DF.Float
status: DF.Literal["", "Accepted", "Rejected"]
verified_by: DF.Data | None
Expand Down Expand Up @@ -124,46 +125,30 @@ def update_qc_reference(self):

if self.reference_type == "Job Card":
if self.reference_name:
frappe.db.sql(
f"""
UPDATE `tab{self.reference_type}`
SET quality_inspection = %s, modified = %s
WHERE name = %s and production_item = %s
""",
(quality_inspection, self.modified, self.reference_name, self.item_code),
frappe.db.set_value(
self.reference_type, self.reference_name, "quality_inspection", quality_inspection
)
frappe.db.set_value(self.reference_type, self.reference_name, "modified", self.modified)

else:
args = [quality_inspection, self.modified, self.reference_name, self.item_code]
doctype = self.reference_type + " Item"
conditions = {"parent": self.reference_name, "item_code": self.item_code}
if self.batch_no and self.docstatus == 1:
conditions["batch_no"] = self.batch_no

if self.docstatus == 2: # if cancel, then remove qi link wherever same name
conditions["quality_inspection"] = self.name

if hasattr(self, "rowname") and self.rowname:
conditions["name"] = self.rowname

if self.reference_type == "Stock Entry":
doctype = "Stock Entry Detail"
else:
doctype = self.reference_type + " Item"

if self.reference_type and self.reference_name:
conditions = ""
if self.batch_no and self.docstatus == 1:
conditions += " and t1.batch_no = %s"
args.append(self.batch_no)

if self.docstatus == 2: # if cancel, then remove qi link wherever same name
conditions += " and t1.quality_inspection = %s"
args.append(self.name)

frappe.db.sql(
f"""
UPDATE
`tab{doctype}` t1, `tab{self.reference_type}` t2
SET
t1.quality_inspection = %s, t2.modified = %s
WHERE
t1.parent = %s
and t1.item_code = %s
and t1.parent = t2.name
{conditions}
""",
args,
)
frappe.db.set_value(doctype, conditions, "quality_inspection", quality_inspection)

frappe.db.set_value(self.reference_type, self.reference_name, "modified", self.modified)

def inspect_and_set_status(self):
for reading in self.readings:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ def test_delete_quality_inspection_linked_with_stock_entry(self):
se.items[0].quality_inspection = qa.name
se.save()

# Unlink the quality inspection from stock entry item
se.items[0].quality_inspection = None
se.save()

qa.delete()

se.reload()
Expand Down
Loading