-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_custom_fields.py
More file actions
46 lines (37 loc) · 1.58 KB
/
Copy pathupdate_custom_fields.py
File metadata and controls
46 lines (37 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3
import frappe
def update_custom_fields():
"""Update existing custom fields to allow editing after submit"""
# Connect to the site
frappe.init(site='dlitsdev1')
frappe.connect()
# Fields to update with allow_on_submit = 1
fields_to_update = [
{"dt": "Sales Invoice", "fieldname": "dlits_sales_partner"},
{"dt": "Sales Invoice", "fieldname": "dlits_commission_type"},
{"dt": "Sales Invoice", "fieldname": "dlits_commission_amount"}
]
for field_info in fields_to_update:
try:
# Get the custom field
custom_field_name = frappe.db.get_value(
"Custom Field",
{"dt": field_info["dt"], "fieldname": field_info["fieldname"]},
"name"
)
if custom_field_name:
# Update the custom field
custom_field = frappe.get_doc("Custom Field", custom_field_name)
custom_field.allow_on_submit = 1
custom_field.read_only = 0 # Remove read_only restriction
custom_field.save()
print(f"Updated {field_info['fieldname']} for {field_info['dt']}")
else:
print(f"Custom field not found: {field_info['fieldname']} for {field_info['dt']}")
except Exception as e:
print(f"Error updating {field_info['fieldname']}: {str(e)}")
# Commit changes
frappe.db.commit()
print("All custom fields updated successfully")
if __name__ == "__main__":
update_custom_fields()