mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-24 20:46:38 +00:00
refactor(postgres): port quality_procedure on_trash to the query builder
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -49,11 +49,8 @@ class QualityProcedure(NestedSet):
|
|||||||
|
|
||||||
def on_trash(self):
|
def on_trash(self):
|
||||||
# clear from child table (sub procedures)
|
# clear from child table (sub procedures)
|
||||||
frappe.db.sql(
|
qpp = frappe.qb.DocType("Quality Procedure Process")
|
||||||
"""update `tabQuality Procedure Process`
|
frappe.qb.update(qpp).set(qpp["procedure"], "").where(qpp["procedure"] == self.name).run()
|
||||||
set `procedure`='' where `procedure`=%s""",
|
|
||||||
self.name,
|
|
||||||
)
|
|
||||||
NestedSet.on_trash(self, allow_root_deletion=True)
|
NestedSet.on_trash(self, allow_root_deletion=True)
|
||||||
|
|
||||||
def check_for_incorrect_child(self):
|
def check_for_incorrect_child(self):
|
||||||
|
|||||||
@@ -65,6 +65,40 @@ class TestQualityProcedure(ERPNextTestSuite):
|
|||||||
child_qp.reload()
|
child_qp.reload()
|
||||||
self.assertEqual(child_qp.parent_quality_procedure, None)
|
self.assertEqual(child_qp.parent_quality_procedure, None)
|
||||||
|
|
||||||
|
def test_on_trash_clears_referencing_process(self):
|
||||||
|
# Build a parent group with a sub-procedure. The parent's child table gets a
|
||||||
|
# `Quality Procedure Process` row whose `procedure` field points at the child.
|
||||||
|
child_qp = create_procedure(
|
||||||
|
{
|
||||||
|
"quality_procedure_name": "Test Child On Trash",
|
||||||
|
"is_group": 0,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
create_procedure(
|
||||||
|
{
|
||||||
|
"quality_procedure_name": "Test Group On Trash",
|
||||||
|
"is_group": 1,
|
||||||
|
"processes": [dict(procedure=child_qp.name)],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Sanity: a process row in the parent references the child by name.
|
||||||
|
referencing_rows = frappe.get_all(
|
||||||
|
"Quality Procedure Process",
|
||||||
|
filters={"procedure": child_qp.name},
|
||||||
|
pluck="name",
|
||||||
|
)
|
||||||
|
self.assertTrue(referencing_rows)
|
||||||
|
|
||||||
|
# Deleting the child runs on_trash() -> the converted UPDATE clears `procedure`.
|
||||||
|
child_qp.delete()
|
||||||
|
|
||||||
|
for row_name in referencing_rows:
|
||||||
|
self.assertEqual(
|
||||||
|
frappe.db.get_value("Quality Procedure Process", row_name, "procedure"),
|
||||||
|
"",
|
||||||
|
)
|
||||||
|
|
||||||
def remove_child_from_old_parent(self):
|
def remove_child_from_old_parent(self):
|
||||||
child_qp = create_procedure(
|
child_qp = create_procedure(
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user