fix: child rows for cancelled docs in getdiff

This commit is contained in:
Gursheen Anand 2023-08-18 11:03:34 +05:30
parent 0d80ffc988
commit ef7af5e849

View file

@ -59,7 +59,7 @@ class Version(Document):
return json.loads(self.data)
def get_diff(old, new, for_child=False):
def get_diff(old, new, for_child=False, compare_cancelled=False):
"""Get diff between 2 document objects
If there is a change, then returns a dict like:
@ -111,7 +111,19 @@ def get_diff(old, new, for_child=False):
# check rows for additions, changes
for i, d in enumerate(new_value):
old_row_name = getattr(d, old_row_name_field, None)
old_row_name = None
if compare_cancelled:
amended_from = frappe.db.get_value(d.parenttype, d.parent, "amended_from")
if amended_from:
parent_doc = frappe.get_doc(d.parenttype, amended_from)
old_table = parent_doc.get(d.parentfield)
if old_table and len(old_table) > i:
old_row_name = old_table[i].name
if not old_row_name:
old_row_name = getattr(d, old_row_name_field, None)
if old_row_name and old_row_name in old_rows_by_name:
found_rows.add(old_row_name)