process_order
Module to prepare SAP order data.
integration(sap_afko, sap_afpo, sap_aufk, sap_mara, sap_cdpos=None)
¶
Integration of SAP tables.
● DataFrames to Integrate: ○ Order Header Data (sap_afko) ○ Order Item Data (sap_afpo) ○ Order Master Data (sap_aufk) ○ General Material Data (sap_mara) ○ Header and Item (sap_cdpos, optional)
Transformation
○ Join operations: ▪ sap_afko left join sap_afpo on AUFNR. ▪ Result left join sap_aufk on AUFNR. ▪ Result left join sap_mara on MATNR. ▪ If sap_cdpos is provided, result left join sap_cdpos on OBJNR. ○ Handle Missing Values: ▪ Use ZZGLTRP_ORIG if available; otherwise, use GLTRP.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sap_afko
|
DataFrame
|
SAP AFKO Dataframe |
required |
sap_afpo
|
DataFrame
|
SAP AFPO Dataframe |
required |
sap_aufk
|
DataFrame
|
SAP AUFK Dataframe |
required |
sap_mara
|
DataFrame
|
SAP MARA Dataframe |
required |
sap_cdpos
|
DataFrame
|
SAP CDPOS Dataframe. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
DataFrame |
DataFrame
|
Integrated DataFrame |
Source code in code\modules\process_order.py
post_prep_process_order(df)
¶
Post-process the Process Order Data.
Input Data: Integrated DataFrame from the joined SAP tables.
Transformation
○ Derive the following keys (intra represents the primary key of one system and inter the primary key the harmonized view. ▪ Intra Primary Key (primary_key_intra): Concatenate AUFNR, POSNR, and DWERK. ▪ Inter Primary Key (primary_key_inter): Concatenate SOURCE_SYSTEM_ERP, AUFNR, POSNR, and DWERK. ○ Calculate On-Time Flag: ▪ Set on_time_flag to: ● 1 if ZZGLTRP_ORIG >= LTRMI. ● 0 if ZZGLTRP_ORIG < LTRMI. ● null if dates are missing. ○ Calculate On-Time Deviation and Late Delivery Bucket: ▪ Compute actual_on_time_deviation as ZZGLTRP_ORIG - LTRMI. ▪ Categorize late_delivery_bucket based on deviation days. ○ Ensure ZZGLTRP_ORIG is Present: ▪ Add ZZGLTRP_ORIG with null values if it's not in the DataFrame. ○ Derive MTO vs. MTS Flag: ▪ Set mto_vs_mts_flag to: ● "MTO" if KDAUF (Sales Order Number) is not null. ● "MTS" otherwise. ○ Convert Dates to Timestamps: ▪ Create order_finish_timestamp from LTRMI. ▪ Create order_start_timestamp from GSTRI.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
Resulting DataFrame from the integration step. |
required |
Returns:
Name | Type | Description |
---|---|---|
DataFrame |
DataFrame
|
Post-processed DataFrame with additional calculated fields. |
Source code in code\modules\process_order.py
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
|
prep_sap_general_material_data(df, col_global_material)
¶
Prepare the SAP general material data.
Input Data: SAP MARA table (General Material Data)
Transformation
○ Filter materials: ▪ Old Material Number (BISMT) is not in ["ARCHIVE", "DUPLICATE", "RENUMBERED"] or is null. ▪ Deletion flag (LVORM) is null or empty. ○ Select the required columns. ○ Rename the global material number column to a consistent name, if necessary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
Input DataFrame |
required |
col_global_material
|
str
|
Column name for Global Material |
required |
Returns:
Name | Type | Description |
---|---|---|
DataFrame |
DataFrame
|
Processed DataFrame |
Raises:
Type | Description |
---|---|
TypeError
|
If input DataFrame is invalid |
TypeError
|
If column name is invalid |
Source code in code\modules\process_order.py
prep_sap_order_header_data(df)
¶
Prepare the SAP order header data.
Input Data: SAP AFKO table (Order Header Data)
Transformation
○ Select the required columns. ○ Createstart_date and finish_date: ▪ Format GSTRP as 'yyyy-MM'. ▪ If GSTRP is null, use the current date. ▪ Concatenate'-01' to form full dates. ▪ Convert to date format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
Input DataFrame |
required |
Returns:
Name | Type | Description |
---|---|---|
DataFrame |
DataFrame
|
Processed DataFrame |
Raises:
Type | Description |
---|---|
TypeError
|
If input DataFrame is invalid |
Source code in code\modules\process_order.py
prep_sap_order_item(df)
¶
Prepare the SAP order item data.
Input Data: SAP AFPO table (Order Item Data) Transformation: ○ Select the required columns.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
Input DataFrame |
required |
Returns:
Name | Type | Description |
---|---|---|
DataFrame |
DataFrame
|
Processed DataFrame |
Raises:
Type | Description |
---|---|
TypeError
|
If input DataFrame is invalid |
Source code in code\modules\process_order.py
prep_sap_order_master_data(df)
¶
Prepare the SAP order master data.
Input Data: SAP AUFK table (Order Master Data)
Transformation
○ Select the required columns.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
Input DataFrame |
required |
Returns:
Name | Type | Description |
---|---|---|
DataFrame |
DataFrame
|
Processed DataFrame |
Raises:
Type | Description |
---|---|
TypeError
|
If input DataFrame is invalid |