# Copyright (c) 2023, Jingrow Technologies Pvt. Ltd. and Contributors
# For license information, please see license.txt

import jingrow


def execute():
	jingrow.reload_doctype("App Patch")

	# All archived benches
	Bench = jingrow.qb.DocType("Bench")
	bench_names = (
		jingrow.qb.from_(Bench).select(Bench.name).where(Bench.status == "Archived").run(pluck="name")
	)

	# All app patches which have those benches with the applied status
	jingrow.db.set_value(
		"App Patch", {"bench": ["in", bench_names], "status": "Applied"}, "status", "Archived"
	)
	jingrow.db.commit()
