Skip to content

Commit

Permalink
patch: auto commit on many writes
Browse files Browse the repository at this point in the history
  • Loading branch information
barredterra committed Mar 15, 2024
1 parent f1d24c6 commit 100e2c9
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions landa/patches/link_external_contact_to_regional_organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,36 @@
from frappe.model.naming import make_autoname
from frappe.model.rename_doc import rename_doc

from landa.utils import autocommit


def execute():
"""Adjust the existing External Contacts to link to the regional organization
instead of the organization.
Also change the name of the External Contacts to reflect the new organization.
"""
for external_contact, organization in frappe.get_all(
"External Contact",
filters={"organization": ("is", "set")},
fields=["name", "organization"],
as_list=True,
):
regional_organization = frappe.get_doc("Organization", organization[:3])
ext_contact = frappe.get_doc("External Contact", external_contact)
ext_contact.db_set(
{
"organization": regional_organization.name,
"organization_name": regional_organization.organization_name,
},
update_modified=False,
)

rename_doc(
with autocommit():
for external_contact, organization in frappe.get_all(
"External Contact",
external_contact,
make_autoname(f"EXT-{regional_organization.name}-.####", "External Contact"),
force=True,
show_alert=False,
)
filters={"organization": ("is", "set")},
fields=["name", "organization"],
as_list=True,
):
regional_organization = frappe.get_doc("Organization", organization[:3])
ext_contact = frappe.get_doc("External Contact", external_contact)
ext_contact.db_set(
{
"organization": regional_organization.name,
"organization_name": regional_organization.organization_name,
},
update_modified=False,
)

rename_doc(
"External Contact",
external_contact,
make_autoname(f"EXT-{regional_organization.name}-.####", "External Contact"),
force=True,
show_alert=False,
)

0 comments on commit 100e2c9

Please sign in to comment.