visitoraddressid fix. switched to parentid of address
This commit is contained in:
@ -341,13 +341,19 @@ columns_pricebookentry = ['IsActive', 'Product2.Product_Code__c', 'UnitPrice', '
|
||||
df_pricelistitem.columns = columns_pricebookentry
|
||||
|
||||
##--------------------------------------------------------------------------##
|
||||
## Location (Van)
|
||||
## Location (Van) + Address and Parent Location
|
||||
##--------------------------------------------------------------------------##
|
||||
|
||||
# Create van locations from resource assignments
|
||||
van_columns = ['Id', 'City__c', 'Country__c', 'Street__c', 'PostalCode__c', 'GeoY__c', 'GeoX__c', 'Resource__r.Employee__r.Name']
|
||||
van_columns = ['Id', 'City__c', 'Country__c', 'Street__c', 'HouseNo__c', 'PostalCode__c', 'GeoY__c', 'GeoX__c', 'Resource__r.Employee__r.Name']
|
||||
van_address_columns = ['City__c', 'Country__c', 'Street__c', 'HouseNo__c', 'PostalCode__c', 'GeoY__c', 'GeoX__c', 'ExternalReference']
|
||||
van_df = df_resourceassignment[van_columns].copy()
|
||||
|
||||
van_df['Street__c'] = (
|
||||
van_df['Street__c'].astype(str) + ' ' +
|
||||
van_df['HouseNo__c'].astype(str)
|
||||
)
|
||||
|
||||
# Create PKey__c for vans
|
||||
van_df['ExternalReference'] = (
|
||||
van_df['Street__c'].astype(str) + ', ' +
|
||||
@ -356,9 +362,6 @@ van_df['ExternalReference'] = (
|
||||
van_df['Country__c'].astype(str)
|
||||
)
|
||||
|
||||
# Filter vans where ExternalReference does not exist in parent_df
|
||||
van_df = van_df[~van_df['ExternalReference'].isin(parent_df['Name'])]
|
||||
|
||||
# Add van records to child_df
|
||||
if not van_df.empty:
|
||||
van_records = pd.DataFrame({
|
||||
@ -372,6 +375,41 @@ if not van_df.empty:
|
||||
})
|
||||
child_df = pd.concat([child_df, van_records], ignore_index=True)
|
||||
|
||||
# Address and Parent Location for vans
|
||||
van_address_df = van_df[van_address_columns].copy()
|
||||
van_parenlocation_df = van_df[['City__c', 'Country__c', 'Street__c', 'PostalCode__c']].copy()
|
||||
|
||||
# For van addresses
|
||||
van_address_df['Country'] = van_address_df['Country__c'].map(country_mapping)
|
||||
van_address_df['Parent.Name'] = van_address_df['ExternalReference']
|
||||
van_address_df = van_address_df.drop('HouseNo__c', axis=1)
|
||||
print(van_address_df)
|
||||
van_address_df.columns = ['City', 'CountryCode', 'Street', 'PostalCode', 'Latitude', 'Longitude', 'PKey__c', 'Country', 'Parent.Name']
|
||||
print(van_address_df)
|
||||
|
||||
|
||||
# Only add addresses that don't already exist
|
||||
new_addresses = van_address_df[~van_address_df['PKey__c'].isin(address_df['PKey__c'])]
|
||||
address_df = pd.concat([address_df, new_addresses], ignore_index=True)
|
||||
|
||||
# For van parent locations
|
||||
van_parenlocation_df['Name'] = (
|
||||
van_parenlocation_df['Street__c'].astype(str) + ', ' +
|
||||
van_parenlocation_df['PostalCode__c'].astype(str) + ' ' +
|
||||
van_parenlocation_df['City__c'].astype(str) + ', ' +
|
||||
van_parenlocation_df['Country__c'].astype(str)
|
||||
)
|
||||
|
||||
van_parenlocation_df = van_parenlocation_df[['Name']].copy()
|
||||
van_parenlocation_df['DuplicateCheck__c'] = 'false'
|
||||
van_parenlocation_df['IsInventoryLocation'] = 'false'
|
||||
van_parenlocation_df['IsMobile'] = 'false'
|
||||
van_parenlocation_df['LocationType'] = 'Site'
|
||||
|
||||
# Only add parent locations that don't already exist
|
||||
new_parent_locations = van_parenlocation_df[~van_parenlocation_df['Name'].isin(parent_df['Name'])]
|
||||
parent_df = pd.concat([parent_df, new_parent_locations], ignore_index=True)
|
||||
|
||||
# Write each DataFrame to a separate CSV file
|
||||
address_df.to_csv('../4_upsert_address_and_parent_location/Address.csv', index=False)
|
||||
parent_df.to_csv('../4_upsert_address_and_parent_location/Location.csv', index=False)
|
||||
|
@ -2,11 +2,12 @@
|
||||
"allOrNone": true,
|
||||
"objects": [
|
||||
{
|
||||
"query": "SELECT Id, Pkey__c FROM Address WHERE CountryCode = 'NL' AND PKey__c != null",
|
||||
"query": "SELECT Id, ParentId, PKey__c FROM Address WHERE CountryCode = 'NL' AND PKey__c != null",
|
||||
"operation": "Readonly",
|
||||
"externalId": "ParentId",
|
||||
"master": false
|
||||
},{
|
||||
"query": "SELECT Id, Name, VisitorAddressId FROM Location WHERE VisitorAddressId = null",
|
||||
"query": "SELECT Id, Name, VisitorAddressId FROM Location WHERE VisitorAddressId = null AND Name LIKE '%NL' AND ParentLocationId = null",
|
||||
"operation": "Update",
|
||||
"master": true,
|
||||
"beforeUpdateAddons": [
|
||||
@ -19,7 +20,7 @@
|
||||
"alias": "sourceAddressIdFromPkey",
|
||||
"sourceObject": "Address",
|
||||
"sourceField": "Id",
|
||||
"lookupExpression": "source.PKey__c == target.Name",
|
||||
"lookupExpression": "source.ParentId == target.Id",
|
||||
"lookupSource": "source"
|
||||
}
|
||||
],
|
||||
@ -36,4 +37,4 @@
|
||||
"externalId": "Name"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user