38 lines
1.6 KiB
Python
38 lines
1.6 KiB
Python
from typing import Any, Dict
|
|||
|
|
|
||
|
|
INVOICE_BASE_TYPE = 13 # ObjType clásico de Sales Invoice (oInvoices) en SAP B1
|
||
|
|
|
||
|
|
|
||
|
|
def construir_delivery(invoice: Dict[str, Any], stock_transfer: Dict[str, Any], store_config: Dict[str, Any]) -> Dict[str, Any]:
|
||
|
|
"""
|
||
|
|
Arma el JSON para POST DeliveryNotes con la Invoice de reserva como base
|
||
|
|
(BaseType/BaseEntry/BaseLine). Solo se entregan los ítems que
|
||
|
|
efectivamente se transfirieron en este fulfillment (StockTransferLines),
|
||
|
|
emparejados con la línea correspondiente de la Invoice por ItemCode.
|
||
|
|
"""
|
||
|
|
invoice_lines_por_sku = {line["ItemCode"]: line for line in invoice["DocumentLines"]}
|
||
|
|
|
||
|
|
document_lines = []
|
||
|
|
for st_line in stock_transfer["StockTransferLines"]:
|
||
|
|
inv_line = invoice_lines_por_sku[st_line["ItemCode"]]
|
||
|
|
document_lines.append(
|
||
|
|
{
|
||
|
|
"ItemCode": st_line["ItemCode"],
|
||
|
|
"Quantity": st_line["Quantity"],
|
||
|
|
"WarehouseCode": inv_line["WarehouseCode"],
|
||
|
|
"BaseType": INVOICE_BASE_TYPE,
|
||
|
|
"BaseEntry": invoice["DocEntry"],
|
||
|
|
"BaseLine": inv_line["LineNum"],
|
||
|
|
}
|
||
|
|
)
|
||
|
|
|
||
|
|
return {
|
||
|
|
"CardCode": invoice.get("CardCode"),
|
||
|
|
"CardName": invoice.get("CardName"),
|
||
|
|
"Comments": invoice.get("NumAtCard"),
|
||
|
|
"DocDate": invoice["DocDate"][:10],
|
||
|
|
"Series": store_config["sap"]["numbering_series"]["DELIVERY"],
|
||
|
|
"U_ShopifyOrderId": invoice.get("U_ShopifyOrderId"),
|
||
|
|
"U_ShopifyStore": invoice.get("U_ShopifyStore"),
|
||
|
|
"DocumentLines": document_lines,
|
||
|
|
}
|