Bring in associated NMINC items that are never physcially shipped.

master
bleeson 2025-09-19 12:10:15 -07:00
parent c0fbb48854
commit 6f6da3dc0c
1 changed files with 72 additions and 1 deletions

View File

@ -76,6 +76,27 @@ def process_files(file):
for num, row in enumerate(csv_reader):
current_order = row[6]
if current_order != previous_order:
nminc_records = check_for_nminc_on_order(warehouse_shipment.sohnum)
if nminc_records:
pprint.pprint('nminc detected')
for record in nminc_records:
nminc_sohnum = record['SOHNUM_0']
nminc_itmref = record['ITMREF_0']
nminc_qtystu = int(record['QTYSTU_0'])
nminc_gropri = decimal.Decimal(record['GROPRI_0'])
subdetail = WarehouseShipmentSubDetail(
qtypcu=-1 * int(nminc_qtystu),
lot='',
)
warehouse_shipment.append(
WarehouseShipmentDetail(
sohnum=nminc_sohnum,
itmref=nminc_itmref,
qty=nminc_qtystu,
gropri=nminc_gropri,
),
subdetail,
)
time_stamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
if warehouse_shipment.sohnum != '':
with yamamotoyama.x3_imports.open_import_file(
@ -122,12 +143,62 @@ def process_files(file):
),
subdetail,
)
nminc_records = check_for_nminc_on_order(warehouse_shipment.sohnum)
if nminc_records:
pprint.pprint('nminc detected')
for record in nminc_records:
nminc_sohnum = record['SOHNUM_0']
nminc_itmref = record['ITMREF_0']
nminc_qtystu = int(record['QTYSTU_0'])
nminc_gropri = decimal.Decimal(record['GROPRI_0'])
subdetail = WarehouseShipmentSubDetail(
qtypcu=-1 * int(nminc_qtystu),
lot='',
)
warehouse_shipment.append(
WarehouseShipmentDetail(
sohnum=nminc_sohnum,
itmref=nminc_itmref,
qty=nminc_qtystu,
gropri=nminc_gropri,
),
subdetail,
)
time_stamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
with yamamotoyama.x3_imports.open_import_file(
SDH_IMPORT_DIRECTORY / f"ZSHIP945S_{warehouse_shipment.sohnum}_{time_stamp}.dat"
) as import_file:
warehouse_shipment.output(import_file)
def check_for_nminc_on_order(sohnum):
with yamamotoyama.get_connection() as db_connection:
return db_connection.query(
"""
select
SOQ.SOHNUM_0,
SOQ.ITMREF_0,
SOQ.QTYSTU_0,
SOP.GROPRI_0
from PROD.SORDER SOH
join PROD.SORDERQ SOQ
on SOH.SOHNUM_0 = SOQ.SOHNUM_0
join PROD.SORDERP SOP
on SOQ.SOHNUM_0 = SOP.SOHNUM_0
and SOQ.ITMREF_0 = SOP.ITMREF_0
and SOQ.SOPLIN_0 = SOP.SOPLIN_0
and SOQ.SOQSEQ_0 = SOP.SOPSEQ_0
join PROD.ITMMASTER ITM
on SOQ.ITMREF_0 = ITM.ITMREF_0
and ITM.TCLCOD_0 = 'NMINC'
where
SOH.SOHTYP_0 = 'WEB'
and SOH.BPCORD_0 = 'STSHOPIFY'
and SOH.SOHNUM_0 =:sohnum
""",
sohnum=sohnum,
).all()
@dataclasses.dataclass
class WarehouseShipmentSubDetail:
"""