Skip to content

Commit

Permalink
feat: cleanup obsolet address and contact flags (LAN-780)
Browse files Browse the repository at this point in the history
  • Loading branch information
scdanieli committed Aug 26, 2023
1 parent 3f2e141 commit 8e57a45
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 70 deletions.
22 changes: 3 additions & 19 deletions landa/fixtures/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -4519,13 +4519,13 @@
"docstatus": 0,
"doctype": "Translation",
"language": "de",
"modified": "2021-12-03 17:22:26.449471",
"modified": "2023-09-26 15:40:26.449471",
"name": "2418380635",
"parent": null,
"parentfield": null,
"parenttype": null,
"source_text": "Primary Address (Full)",
"translated_text": "Prim\u00e4re Adresse (vollst\u00e4ndig)"
"source_text": "Full Address",
"translated_text": "Vollst\u00e4ndige Adresse"
},
{
"context": null,
Expand Down Expand Up @@ -5807,22 +5807,6 @@
"source_text": "Pincode",
"translated_text": "Postleitzahl"
},
{
"context": null,
"contributed": 0,
"contribution_docname": null,
"contribution_status": "",
"docstatus": 0,
"doctype": "Translation",
"language": "de",
"modified": "2021-09-02 17:10:49.800353",
"name": "6dc383a8a1",
"parent": null,
"parentfield": null,
"parenttype": null,
"source_text": "Primary Address (Full)",
"translated_text": "Prim\u00e4re Adresse (kommagetrennt)"
},
{
"context": null,
"contributed": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ def create_address(
address.pincode = pincode
address.city = city
address.country = "Germany"
address.is_primary_address = 1
address.is_shipping_address = 1
address.append("links", {"link_doctype": "LANDA Member", "link_name": member})
address.organization = organization

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
{
"fieldname": "full_address",
"fieldtype": "Data",
"label": "Primary Address (Full)",
"label": "Full Address",
},
{
"fieldname": "primary_email_address",
Expand Down Expand Up @@ -103,25 +103,22 @@ def get_link_filters(link_names: List[str]):
link_filters = get_link_filters(external_contact_ids)

# load addresses from db
address_fields = ["address_line1", "pincode", "city", "is_primary_address"]
address_fields = ["address_line1", "pincode", "city"]
addresses = frappe.get_list(
"Address",
filters=link_filters,
fields=[link_field] + address_fields,
)
# convert to pandas dataframe
addresses_df = to_df(addresses, address_fields)
# remove all duplicate addresses by keeping only the primary address or last existing address if there is no primary address
addresses_df = remove_duplicate_indices(addresses_df, sort_by="is_primary_address")
# remove all duplicate addresses by keeping only the last existing address
addresses_df = remove_duplicate_indices(addresses_df)

# merge all columns to one address column and add this as the first column
addresses_df["full_address"] = (
addresses_df["address_line1"] + ", " + addresses_df["pincode"] + " " + addresses_df["city"]
)

# remove column 'is_primary_address'
addresses_df.drop("is_primary_address", axis=1, inplace=True)

# load contacts from db that are linked to the member fucntions loaded before
contact_fields = ["email_id", "phone", "mobile_no"]
contacts = frappe.get_list(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get_member_filter(frappe_tuple):
link_filters = get_link_filters(members)

# load addresses from db
address_fields = ["address_line1", "pincode", "city", "is_primary_address"]
address_fields = ["address_line1", "pincode", "city"]
addresses = frappe.get_list(
"Address",
filters=link_filters,
Expand All @@ -88,17 +88,14 @@ def get_member_filter(frappe_tuple):
)
# convert to pandas dataframe
addresses_df = frappe_tuple_to_pandas_df(addresses, address_fields + ["member"])
# remove all duplicate addresses by keeping only the primary address or last existing address if there is no primary address
addresses_df = remove_duplicate_indices(addresses_df, sort_by="is_primary_address")
# remove all duplicate addresses by keeping only the last existing address
addresses_df = remove_duplicate_indices(addresses_df)

# merge all columns to one address column and add this as the first column
addresses_df["full_address"] = (
addresses_df["address_line1"] + ", " + addresses_df["pincode"] + " " + addresses_df["city"]
)

# remove column 'is_primary_address'
addresses_df.drop("is_primary_address", axis=1, inplace=True)

# load addresses from db
permit_fields = ["year", "member", "docstatus"]
permits = frappe.get_list(
Expand Down Expand Up @@ -182,7 +179,7 @@ def get_columns(self):
{
"fieldname": "full_address",
"fieldtype": "Data",
"label": "Primary Address (Full)",
"label": "Full Address",
},
{
"fieldname": "magazine_active",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
{
"fieldname": "full_address",
"fieldtype": "Data",
"label": "Primary Address (Full)",
"label": "Full Address",
"width": 0
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def get_data(self):
link_filters = get_link_filters(self.members)

# load addresses from db
address_fields = ["address_line1", "pincode", "city", "is_primary_address"]
address_fields = ["address_line1", "pincode", "city"]
addresses = frappe.get_list(
"Address",
filters=link_filters,
Expand All @@ -30,17 +30,14 @@ def get_data(self):
addresses_df = pd.DataFrame(addresses, columns=address_fields + ["member"])
addresses_df.set_index("member", inplace=True)

# remove all duplicate addresses by keeping only the primary address or last existing address if there is no primary address
addresses_df = remove_duplicate_indices(addresses_df, sort_by="is_primary_address")
# remove all duplicate addresses by keeping only the last existing address
addresses_df = remove_duplicate_indices(addresses_df)

# merge all columns to one address column and add this as the first column
addresses_df["full_address"] = (
addresses_df["address_line1"] + ", " + addresses_df["pincode"] + " " + addresses_df["city"]
)

# remove column 'is_primary_address'
addresses_df.drop("is_primary_address", axis=1, inplace=True)

# merge all dataframes from different doctypes
data = pd.concat([self.members_df, addresses_df], axis=1).reindex(self.members_df.index)

Expand Down Expand Up @@ -83,7 +80,7 @@ def get_columns(self):
{
"fieldname": "full_address",
"fieldtype": "Data",
"label": "Primary Address (Full)",
"label": "Full Address",
},
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
{
"fieldname": "full_address",
"fieldtype": "Data",
"label": "Primary Address (Full)",
"label": "Full Address",
},
{
"fieldname": "address_line1",
Expand Down Expand Up @@ -177,22 +177,20 @@ def get_contact_details(
awards_df.drop(award_fields[:-1], axis=1, inplace=True)

# load addresses from db
address_fields = ["address_line1", "pincode", "city", "is_primary_address"]
address_fields = ["address_line1", "pincode", "city"]
addresses = get_contact_details("Address", MEMBERS, address_fields)

# convert to pandas dataframe
addresses_df = frappe_tuple_to_pandas_df(addresses, address_fields + ["member"])
# remove all duplicate addresses by keeping only the primary address or last existing address if there is no primary address
addresses_df = remove_duplicate_indices(addresses_df, sort_by="is_primary_address")
# remove all duplicate addresses by keeping only the last existing address
addresses_df = remove_duplicate_indices(addresses_df)

# merge all columns to one address column and add this as the first column
addresses_df["full_address"] = (
addresses_df["address_line1"] + ", " + addresses_df["pincode"] + " " + addresses_df["city"]
)
address_cols = addresses_df.columns.tolist()
addresses_df = addresses_df[address_cols[-1:] + address_cols[:-1]]
# remove column 'is_primary_address'
addresses_df.drop("is_primary_address", axis=1, inplace=True)

# load contacts from db that are linked to the member fucntions loaded before
contact_fields = ["email_id", "phone", "mobile_no"]
Expand Down
1 change: 1 addition & 0 deletions landa/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ landa.patches.update_system_settings
landa.patches.delete_customized_workspaces # 2023-08-14
landa.patches.build_water_body_cache # 2023-08-14
landa.patches.set_hide_custom_in_user_workspaces
landa.patches.cleanup_addresses_and_contacts
16 changes: 16 additions & 0 deletions landa/patches/cleanup_addresses_and_contacts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import frappe


def execute():
cleanup_addresses()
cleanup_contacts()


def cleanup_addresses():
# the two checkboxes are no longer used and are hidden from now on.
frappe.db.sql("""update `tabAddress` set is_shipping_address=0, is_primary_address=0""")


def cleanup_contacts():
# the two checkboxes are no longer used and are hidden from now on.
frappe.db.sql("""update `tabContact` set is_billing_contact=0, is_primary_contact=0""")
14 changes: 0 additions & 14 deletions landa/patches/set_billing_and_shipping_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@

def execute():
set_billing_and_shipping_defaults()
# Cleanup of data not yet now, but in the next release. Ask Samuel why.
# TODO: Clean data
# cleanup_addresses()
# cleanup_contacts()


def customize_customer():
Expand Down Expand Up @@ -75,13 +71,3 @@ def set_billing_and_shipping_defaults():
"default_shipping_address": address_name,
},
)


def cleanup_addresses():
# the two checkboxes are no longer used and are hidden from now on.
frappe.db.sql("""update `tabAddress` set is_shipping_address=0, is_primary_address=0""")


def cleanup_contacts():
# the two checkboxes are no longer used and are hidden from now on.
frappe.db.sql("""update `tabContact` set is_billing_contact=0, is_primary_contact=0""")
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
{
"fieldname": "full_address",
"fieldtype": "Data",
"label": "Primary Address (Full)",
"label": "Full Address",
},
{
"fieldname": "address_line1",
Expand Down Expand Up @@ -127,27 +127,24 @@ def get_link_filters(frappe_tuple, index="member"):
"address_line1",
"pincode",
"city",
"is_primary_address",
link_field_label,
],
)
# convert to pandas dataframe
addresses_df = pd.DataFrame.from_records(
addresses,
index="member",
columns=["address_line1", "pincode", "city", "is_primary_address", "member"],
columns=["address_line1", "pincode", "city", "member"],
)
# remove all duplicate addresses by keeping only the primary address or last existing address if there is no primary address
addresses_df = remove_duplicate_indices(addresses_df, sort_by="is_primary_address")
# remove all duplicate addresses by keeping only the last existing address
addresses_df = remove_duplicate_indices(addresses_df)

# merge all columns to one address column and add this as the first column
addresses_df["full_address"] = (
addresses_df["address_line1"] + ", " + addresses_df["pincode"] + " " + addresses_df["city"]
)
address_cols = addresses_df.columns.tolist()
addresses_df = addresses_df[address_cols[-1:] + address_cols[:-1]]
# remove column 'is_primary_address'
addresses_df.drop("is_primary_address", axis=1, inplace=True)

# load contacts from db that are linked to the member fucntions loaded before
contacts = frappe.get_all(
Expand Down

0 comments on commit 8e57a45

Please sign in to comment.