Files
erpnext/erpnext/patches/v12_0/update_is_cancelled_field.py
Saurabh 034773a670 fix: broken patches (#29067)
* chore: patch fixes

* fix: remove desktop icons while deleting sales reports

* refactor: dont ignore dangerous exceptions in patches

* fix: make patch kinda idempotent

with previous query rerunning would've caused all values to become 0.

* fix: check type before patching

Co-authored-by: Ankush Menat <ankush@frappe.io>
2022-01-25 11:12:25 +05:30

31 lines
727 B
Python

import frappe
def execute():
#handle type casting for is_cancelled field
module_doctypes = (
('stock', 'Stock Ledger Entry'),
('stock', 'Serial No'),
('accounts', 'GL Entry')
)
for module, doctype in module_doctypes:
if (not frappe.db.has_column(doctype, "is_cancelled")
or frappe.db.get_column_type(doctype, "is_cancelled").lower() == "int(1)"
):
continue
frappe.db.sql("""
UPDATE `tab{doctype}`
SET is_cancelled = 0
where is_cancelled in ('', NULL, 'No')"""
.format(doctype=doctype))
frappe.db.sql("""
UPDATE `tab{doctype}`
SET is_cancelled = 1
where is_cancelled = 'Yes'"""
.format(doctype=doctype))
frappe.reload_doc(module, "doctype", frappe.scrub(doctype))