fix: Migrate old lead notes as per the new format

This commit is contained in:
Nabin Hait
2022-09-05 15:32:48 +05:30
parent 57257a1795
commit 3abd00f3bb
2 changed files with 22 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
import frappe
from frappe.utils import cstr, strip_html
def execute():
for doctype in ("Lead", "Prospect"):
if not frappe.db.has_column(doctype, "notes"):
continue
dt = frappe.qb.DocType(doctype)
records = (
frappe.qb.from_(dt)
.select(dt.name, dt.notes, dt.modified_by, dt.modified)
.where(dt.notes.isnotnull() & dt.notes != "")
).run()
for d in records:
if strip_html(cstr(d.notes)).strip():
doc = frappe.get_doc(doctype, d.name)
doc.append("notes", {"note": d.notes, "added_by": d.modified_by, "added_on": d.modified})
doc.save()