X3 customer codes are now looked up in table instead of local dict.
parent
6092eaa532
commit
7af3cb1f81
|
@ -149,7 +149,7 @@ INSERT_SHIPMENT_DETAIL = """\
|
||||||
# "EC" : "EA"
|
# "EC" : "EA"
|
||||||
#}
|
#}
|
||||||
#NAME_ADDRESS_CITY_TERRITORY_POSTAL : X3 Customer Code
|
#NAME_ADDRESS_CITY_TERRITORY_POSTAL : X3 Customer Code
|
||||||
X3_CUSTOMER_MAPPING = {
|
X3_CUSTOMER_MAPPING_OLD = {
|
||||||
'AVRI1000_AVRIQC' : 'AVRI0001',
|
'AVRI1000_AVRIQC' : 'AVRI0001',
|
||||||
'BULK1000_BULKAU' : 'BULK0001',
|
'BULK1000_BULKAU' : 'BULK0001',
|
||||||
'COOP2000_190148' : 'FEDE0006',
|
'COOP2000_190148' : 'FEDE0006',
|
||||||
|
@ -207,19 +207,37 @@ X3_CUSTOMER_MAPPING = {
|
||||||
'ISLA1000_0000' : 'ISLA0005',
|
'ISLA1000_0000' : 'ISLA0005',
|
||||||
'PURI1000_0000' : 'PURI0002',
|
'PURI1000_0000' : 'PURI0002',
|
||||||
'AVRI1000_AVRIGR' : 'AVRI0001',
|
'AVRI1000_AVRIGR' : 'AVRI0001',
|
||||||
|
'VANH1000_VANH1000' : 'VANH0001',
|
||||||
}
|
}
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""
|
"""
|
||||||
Do it!
|
Do it!
|
||||||
"""
|
"""
|
||||||
|
x3_customer_mapping = get_customer_map()
|
||||||
for edi_filename in X12_DIRECTORY.iterdir():
|
for edi_filename in X12_DIRECTORY.iterdir():
|
||||||
if SOURCE_867_FILENAME_RE.match(edi_filename.name):
|
if SOURCE_867_FILENAME_RE.match(edi_filename.name):
|
||||||
process_file(edi_filename)
|
process_file(edi_filename, x3_customer_mapping)
|
||||||
shutil.copy(edi_filename, EDI_997_DIRECTORY / edi_filename.name)
|
shutil.copy(edi_filename, EDI_997_DIRECTORY / edi_filename.name)
|
||||||
shutil.move(edi_filename, THIS_DIRECTORY / "processed_867s" / edi_filename.name) #They go in here so we can use them in the dashboard script, 2024-08 dashboard no longer needed
|
shutil.move(edi_filename, THIS_DIRECTORY / "processed_867s" / edi_filename.name) #They go in here so we can use them in the dashboard script, 2024-08 dashboard no longer needed
|
||||||
|
|
||||||
|
|
||||||
|
def get_customer_map():
|
||||||
|
customer_map = {}
|
||||||
|
with yamamotoyama.get_connection() as database:
|
||||||
|
result = database.query(
|
||||||
|
"""
|
||||||
|
SELECT
|
||||||
|
[shandex_key]
|
||||||
|
,[x3_customer]
|
||||||
|
FROM [staging].[dbo].[shandex_customer_map]
|
||||||
|
""",
|
||||||
|
).all()
|
||||||
|
for record in result:
|
||||||
|
customer_map[record['shandex_key']] = record['x3_customer']
|
||||||
|
return customer_map
|
||||||
|
|
||||||
|
|
||||||
def missing_customer_alert(customer_key):
|
def missing_customer_alert(customer_key):
|
||||||
msg = MIMEMultipart()
|
msg = MIMEMultipart()
|
||||||
msg['Subject'] = 'Shandex 867 - Missing X3 Customer'
|
msg['Subject'] = 'Shandex 867 - Missing X3 Customer'
|
||||||
|
@ -314,7 +332,7 @@ def get_product_from_gtin(gtin):
|
||||||
).first()
|
).first()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def process_file(edi_filename: pathlib.Path):
|
def process_file(edi_filename: pathlib.Path, x3_customer_mapping):
|
||||||
"""
|
"""
|
||||||
Convert a specific EDI file into an import file.
|
Convert a specific EDI file into an import file.
|
||||||
"""
|
"""
|
||||||
|
@ -367,11 +385,11 @@ def process_file(edi_filename: pathlib.Path):
|
||||||
customer_key = warehouse_shipment.create_customer_key(shandex_code_part2, shandex_code_part1)
|
customer_key = warehouse_shipment.create_customer_key(shandex_code_part2, shandex_code_part1)
|
||||||
if customer_key == 'SAMP1000_0000': #flag sample orders better
|
if customer_key == 'SAMP1000_0000': #flag sample orders better
|
||||||
warehouse_shipment.header.bpdnam = 'SMP: ' + warehouse_shipment.header.bpdnam
|
warehouse_shipment.header.bpdnam = 'SMP: ' + warehouse_shipment.header.bpdnam
|
||||||
if customer_key not in X3_CUSTOMER_MAPPING.keys():
|
if customer_key not in x3_customer_mapping.keys():
|
||||||
pprint.pprint(customer_key + ' not found.')
|
pprint.pprint(customer_key + ' not found.')
|
||||||
warehouse_shipment.header.bpcord = ''
|
warehouse_shipment.header.bpcord = ''
|
||||||
else:
|
else:
|
||||||
warehouse_shipment.header.bpcord = X3_CUSTOMER_MAPPING[customer_key]
|
warehouse_shipment.header.bpcord = x3_customer_mapping[customer_key]
|
||||||
if fields[0] == "QTY":
|
if fields[0] == "QTY":
|
||||||
#QTY*39*10*CA
|
#QTY*39*10*CA
|
||||||
_, _, qty_str, uom = fields[:4]
|
_, _, qty_str, uom = fields[:4]
|
||||||
|
|
Loading…
Reference in New Issue