Read in and report more information 947s. Only email 947 information, no X3 imports.
parent
b1e5c392b9
commit
39199aaaaf
99
edi_947.py
99
edi_947.py
|
@ -65,10 +65,29 @@ DAMAGE_CODE_DESCRIPTIONS_MAPPING = {
|
||||||
"AA" : "Physical Count",
|
"AA" : "Physical Count",
|
||||||
"05" : "Product Put on Hold"
|
"05" : "Product Put on Hold"
|
||||||
}
|
}
|
||||||
|
#translate WMS status codes from shandex to suggested X3 status codes
|
||||||
|
SHANDEX_WMS_CODES = {
|
||||||
|
"G":"A",
|
||||||
|
"A":"A",
|
||||||
|
"U":"A",
|
||||||
|
"C":"Q",
|
||||||
|
"H":"Q",
|
||||||
|
"Q":"QH",
|
||||||
|
"R":"QH",
|
||||||
|
"Z":"RD",
|
||||||
|
"B":"RD",
|
||||||
|
"D":"RD",
|
||||||
|
"E":"RD",
|
||||||
|
"F":"RD",
|
||||||
|
"O":"RD",
|
||||||
|
"X":"RD",
|
||||||
|
"P":"RD",
|
||||||
|
"L":"RD",
|
||||||
|
"W":"RD",
|
||||||
|
}
|
||||||
|
|
||||||
#This transaction can also be used for inventory counts, which we will report on but not process
|
#This transaction can also be used for inventory counts, which we will report on but not process
|
||||||
EMAIL_ONLY_CODES = ['AA']
|
EMAIL_ONLY_CODES = ['AA','AV','07','05','55']
|
||||||
|
|
||||||
#When we receive an EDI to change status, it will either be A or Q, the reverse of the earlier code
|
#When we receive an EDI to change status, it will either be A or Q, the reverse of the earlier code
|
||||||
DAMAGE_CODE_SOURCE_MAPPING = {
|
DAMAGE_CODE_SOURCE_MAPPING = {
|
||||||
|
@ -190,14 +209,14 @@ def gtin_lookup(gtin):
|
||||||
).first()["ITMREF_0"]
|
).first()["ITMREF_0"]
|
||||||
|
|
||||||
|
|
||||||
def stock_movement_alert(itmref, qty, lot, status):
|
def stock_movement_alert(itmref, qty, lot, status, license_plate, control_number, reason, bucket):
|
||||||
msg = MIMEMultipart()
|
msg = MIMEMultipart()
|
||||||
msg['Subject'] = 'New Stock Change from Shandex'
|
msg['Subject'] = 'New Stock Change from Shandex'
|
||||||
msg['Precedence'] = 'bulk'
|
msg['Precedence'] = 'bulk'
|
||||||
msg['From'] = 'x3report@stashtea.com'
|
msg['From'] = 'x3report@stashtea.com'
|
||||||
msg['To'] = 'woninventory@stashtea.com'
|
msg['To'] = 'woninventory@stashtea.com'
|
||||||
msg['CC'] = 'bleeson@stashtea.com,icarrera@yamamotoyama.com'
|
msg['CC'] = 'bleeson@stashtea.com,icarrera@yamamotoyama.com'
|
||||||
emailtext = f'Item: {itmref}\nQty: {qty}\nLot: {lot}\nStatus: {DAMAGE_CODE_MAPPING[status]}\nReason: {DAMAGE_CODE_DESCRIPTIONS_MAPPING[status]}'
|
emailtext = f'Item: {itmref}\nQty: {qty}\nLot: {lot}\nStatus: {DAMAGE_CODE_MAPPING[status]}\nReason: {DAMAGE_CODE_DESCRIPTIONS_MAPPING[status]}\nLP: {license_plate}\nControl: {control_number}\nReason{reason}\nStock Bucket: {bucket}'
|
||||||
msg.attach(MIMEText(emailtext, 'plain'))
|
msg.attach(MIMEText(emailtext, 'plain'))
|
||||||
service = gmail_authenticate()
|
service = gmail_authenticate()
|
||||||
encoded_message = base64.urlsafe_b64encode(msg.as_bytes()).decode()
|
encoded_message = base64.urlsafe_b64encode(msg.as_bytes()).decode()
|
||||||
|
@ -214,6 +233,15 @@ def process_file(edi_filename: pathlib.Path):
|
||||||
warehouse_stockchange = StockChange()
|
warehouse_stockchange = StockChange()
|
||||||
vcrlin = 0
|
vcrlin = 0
|
||||||
for fields in tokens_from_edi_file(edi_filename):
|
for fields in tokens_from_edi_file(edi_filename):
|
||||||
|
status = ''
|
||||||
|
qty = ''
|
||||||
|
uom = ''
|
||||||
|
gtin = ''
|
||||||
|
lot = ''
|
||||||
|
license_plate = ''
|
||||||
|
control_number = ''
|
||||||
|
reason = ''
|
||||||
|
bucket = ''
|
||||||
if fields[0] == "G62":
|
if fields[0] == "G62":
|
||||||
iptdat = fields[2]
|
iptdat = fields[2]
|
||||||
warehouse_stockchange.header.iptdat = datetime.datetime.strptime(
|
warehouse_stockchange.header.iptdat = datetime.datetime.strptime(
|
||||||
|
@ -226,33 +254,44 @@ def process_file(edi_filename: pathlib.Path):
|
||||||
# W19*AV*35*CA**UK*10077652082651***03022026C
|
# W19*AV*35*CA**UK*10077652082651***03022026C
|
||||||
_, status, qty, uom, _, _, gtin, _, _, lot = fields[:10]
|
_, status, qty, uom, _, _, gtin, _, _, lot = fields[:10]
|
||||||
product = gtin_lookup(gtin)
|
product = gtin_lookup(gtin)
|
||||||
stock_movement_alert(product, qty, lot, status)
|
if fields[0] == 'N9':
|
||||||
if status in EMAIL_ONLY_CODES:
|
if fields[1] == 'LV':
|
||||||
continue
|
license_plate = fields[2]
|
||||||
warehouse_stockchange.header.vcrdes = DAMAGE_CODE_DESCRIPTIONS_MAPPING[status]
|
elif fields[1] == 'X9':
|
||||||
subdetail = StockChangeSubDetail(
|
control_number = fields[2]
|
||||||
qtypcu=int(qty),
|
elif fields[1] == 'TD':
|
||||||
qtystu=int(qty),
|
reason = fields[2]
|
||||||
sta=DAMAGE_CODE_MAPPING[status],
|
elif fields[1] == 'ZZ':
|
||||||
pcu=uom
|
bucket = fields[2]
|
||||||
)
|
stock_movement_alert(product, qty, lot, status, license_plate, control_number, reason, bucket)
|
||||||
detail_line = StockChangeDetail(
|
#Per John Pena 9/2025, don't perform imports, only notify
|
||||||
vcrlin=vcrlin,
|
# if status in EMAIL_ONLY_CODES:
|
||||||
itmref=product,
|
# continue
|
||||||
pcu=uom,
|
# warehouse_stockchange.header.vcrdes = DAMAGE_CODE_DESCRIPTIONS_MAPPING[status]
|
||||||
sta=DAMAGE_CODE_SOURCE_MAPPING[status],
|
# subdetail = StockChangeSubDetail(
|
||||||
lot=lot
|
# qtypcu=int(qty),
|
||||||
)
|
# qtystu=int(qty),
|
||||||
warehouse_stockchange.append(
|
# sta=DAMAGE_CODE_MAPPING[status],
|
||||||
detail_line,
|
# pcu=uom
|
||||||
subdetail,
|
# )
|
||||||
)
|
# detail_line = StockChangeDetail(
|
||||||
time_stamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
# vcrlin=vcrlin,
|
||||||
|
# itmref=product,
|
||||||
|
# pcu=uom,
|
||||||
|
# sta=DAMAGE_CODE_SOURCE_MAPPING[status],
|
||||||
|
# lot=lot
|
||||||
|
# )
|
||||||
|
# warehouse_stockchange.append(
|
||||||
|
# detail_line,
|
||||||
|
# subdetail,
|
||||||
|
# )
|
||||||
|
# time_stamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||||
|
|
||||||
with yamamotoyama.x3_imports.open_import_file(
|
# if warehouse_stockchange.details._details:
|
||||||
IMPORTS_DIRECTORY / f"ZSCS_{transaction_number}_{time_stamp}.dat"
|
# with yamamotoyama.x3_imports.open_import_file(
|
||||||
) as import_file:
|
# IMPORTS_DIRECTORY / f"ZSCS_{transaction_number}_{time_stamp}.dat"
|
||||||
warehouse_stockchange.output(import_file)
|
# ) as import_file:
|
||||||
|
# warehouse_stockchange.output(import_file)
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass
|
@dataclasses.dataclass
|
||||||
|
|
Loading…
Reference in New Issue