Hey ppl,
I am trying to change the value of the ‘name’ field for the Account DocType (see why Programmatically Warehouse Creation Missing Ref)
check the following patch…
def execute():
frappe.reload_doctype('Account')
accounts = frappe.get_all('Account')
for account in accounts:
name_split = account.name.split()
for addr in ['DE', 'RO']:
count = Counter(name_split) # from collections import Counter
if count[addr] >= 2:
# Here I have the desired doc ex INCOMING - DE - DE ---> INCOMING - DE
# with doc.save:
doc = frappe.get_doc('Account', account['name'])
doc.name = account[:-5]
doc.save(ingnore_permissions=True)
# BREAKS :( , record_name dont exist
# with Sql statement 2:
frappe.db.sql("""
update `tabAccount`
set `name` = {0}
where `name` = {1}
""".format(account['name'][:-5], account['name']))
# Breaks : (
# with db.set_value
frappe.db.set_value('Account', account['name'], 'name', str(account[:-5]), modified=True)
# TypeError: unhashable type
I am out of any ideas …