Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,22 @@ def start_repost(account_repost_doc=str) -> None:


def get_allowed_types_from_settings(child_doc: bool = False):
repost_docs = [
x.document_type
for x in frappe.db.get_all(
"Repost Allowed Types", filters={"allowed": True}, fields=["distinct(document_type)"]
)
]
# Avoid DISTINCT(...) here: Frappe applies a default ORDER BY which breaks on Postgres
# when used with SELECT DISTINCT.
repost_docs = frappe.db.get_all(
"Repost Allowed Types",
filters={"allowed": True},
pluck="document_type",
)

# De-dupe while preserving order (first occurrence wins)
repost_docs = list(dict.fromkeys(repost_docs))
result = repost_docs

if repost_docs and child_doc:
result.extend(get_child_docs(repost_docs))
# Keep uniqueness after extending
result = list(dict.fromkeys(result))

return result

Expand Down Expand Up @@ -291,8 +297,11 @@ def get_repost_allowed_types(doctype, txt, searchfield, start, page_len, filters
if txt:
filters.update({"document_type": ("like", f"%{txt}%")})

if allowed_types := frappe.db.get_all(
"Repost Allowed Types", filters=filters, fields=["distinct(document_type)"], as_list=1
):
return allowed_types
return []
allowed_types = frappe.db.get_all(
"Repost Allowed Types",
filters=filters,
pluck="document_type",
)

allowed_types = list(dict.fromkeys(allowed_types))
return [[dt] for dt in allowed_types]
24 changes: 18 additions & 6 deletions erpnext/patches/v15_0/update_pick_list_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,24 @@ def execute():


def update_delivery_note():
DN = frappe.qb.DocType("Delivery Note")
DNI = frappe.qb.DocType("Delivery Note Item")

frappe.qb.update(DNI).join(DN).on(DN.name == DNI.parent).set(DNI.against_pick_list, DN.pick_list).where(
IfNull(DN.pick_list, "") != ""
).run()
# Postgres doesn't support UPDATE ... JOIN. Use UPDATE ... FROM instead.
frappe.db.multisql(
{
"mariadb": """
UPDATE `tabDelivery Note Item` dni
JOIN `tabDelivery Note` dn ON dn.`name` = dni.`parent`
SET dni.`against_pick_list` = dn.`pick_list`
WHERE COALESCE(dn.`pick_list`, '') <> ''
""",
"postgres": """
UPDATE "tabDelivery Note Item" dni
SET against_pick_list = dn.pick_list
FROM "tabDelivery Note" dn
WHERE dn.name = dni.parent
AND COALESCE(dn.pick_list, '') <> ''
""",
}
)


def update_pick_list_items():
Expand Down
Loading