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: Empty docname in wbmlo change log & track changes for WB Rules (LAN-781) #252

Merged
merged 3 commits into from
Nov 28, 2023
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 @@ -49,7 +49,7 @@
],
"issingle": 1,
"links": [],
"modified": "2023-09-22 14:26:40.377433",
"modified": "2023-11-27 18:59:08.307363",
"modified_by": "Administrator",
"module": "Water Body Management",
"name": "Water Body Rules",
Expand Down Expand Up @@ -80,5 +80,6 @@
}
],
"sort_field": "modified",
"sort_order": "DESC"
"sort_order": "DESC",
"track_changes": 1
}
21 changes: 14 additions & 7 deletions landa/water_body_management/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def get_version_log_query(from_datetime: str):
"Fish Species",
"File",
"Water Body Management Local Organization",
"Water Body Rules",
]
)
)
Expand Down Expand Up @@ -173,7 +174,10 @@ def build_modified_change_log(entry, changed_data, event):


def build_dependency_change_log(entry, changed_data):
"""Return a pretty dict with changes in dependencies (File and WBMLO)."""
"""
Return a pretty dict with changes in dependencies (File and WBMLO).
`entry` could be creation (Version), modification (Version) or deletion (Deleted Document) events.
"""
if (
cint(entry.deleted)
and entry.doctype == "File"
Expand All @@ -183,13 +187,16 @@ def build_dependency_change_log(entry, changed_data):
return []

if entry.doctype == "Water Body Management Local Organization":
ref_water_body = frappe.db.get_value(
"Water Body Management Local Organization",
entry.docname,
"water_body",
)
if cint(entry.deleted):
ref_water_body = changed_data.get("water_body") # Deleted WBMLO
else:
ref_water_body = frappe.db.get_value( # Created/Modified WBMLO
"Water Body Management Local Organization",
entry.docname,
"water_body",
)
else:
ref_water_body = entry.attached_to_name or changed_data.attached_to_name
ref_water_body = changed_data.attached_to_name if cint(entry.deleted) else entry.attached_to_name

key = "files" if entry.doctype == "File" else "organizations"
return {
Expand Down
Loading