2026-07-09 09:48:30 -05:00
|
|
|
# Construir Draft SAP B1
|
|
|
|
|
|
|
|
|
|
```mermaid
|
|
|
|
|
flowchart TD
|
|
|
|
|
A["factura + resultados_val"] --> B["Determinar ItemCode<br>C103002-A (mes anterior)<br>C103002 (mes actual)"]
|
2026-09-10 13:21:04 -05:00
|
|
|
B --> B2["CardCode = PL + ruc_emisor<br>sapb1_manager.obtener_condicion_pago(CardCode)<br>(BusinessPartners.PayTermsGrpCode → PaymentTermsTypes)"]
|
|
|
|
|
B2 --> B3["fecha_vencimiento = fecha_contabilizacion +<br>NumberOfAdditionalDays<br>(si es 0, usar NumberOfAdditionalMonths * 30)"]
|
|
|
|
|
B3 --> C["Calcular cuotas<br>DocumentInstallments"]
|
2026-07-09 09:48:30 -05:00
|
|
|
|
|
|
|
|
C --> D{"¿Tiene detracción?"}
|
|
|
|
|
D -->|Sí| E["Cuota 1: monto detracción<br>U_VS_TIPOCUOTA = D"]
|
|
|
|
|
E --> F["Cuota 2: neto = total - detracción<br>U_VS_TIPOCUOTA = N"]
|
|
|
|
|
D -->|No| G["Cuota única por el total<br>U_VS_TIPOCUOTA = N"]
|
|
|
|
|
|
|
|
|
|
F --> H["Por cada línea de factura"]
|
|
|
|
|
G --> H
|
|
|
|
|
|
|
|
|
|
H --> I["Obtener guias_lt[]<br>desde resultado_validacion"]
|
|
|
|
|
I --> J["zona_guia = guias_lt[0]['zona']"]
|
|
|
|
|
J --> K["Por cada item en guias_lt[]"]
|
|
|
|
|
|
|
|
|
|
K --> L["PriceAfterVAT:<br>suma pav FL* si use_sap_prices<br>line_total si no"]
|
|
|
|
|
L --> M["Qty = item['quantity']"]
|
|
|
|
|
M --> N["Crear DocumentLine:<br>ItemCode, Quantity,<br>PriceAfterVAT, WarehouseCode,<br>U_IDC_GRFLETE"]
|
|
|
|
|
|
|
|
|
|
N --> O["Acumular total_weight<br>+= item['weight1']"]
|
|
|
|
|
O --> K
|
|
|
|
|
|
|
|
|
|
K --> P["U_IDC_VALREF =<br>round((total_weight / 1000) *<br>CUADRO_VALOR_REFERENCIAL[zona], 2)"]
|
|
|
|
|
|
|
|
|
|
P --> Q["Armar payload completo"]
|
2026-09-10 13:21:04 -05:00
|
|
|
Q --> R["Cabecera:<br>DocType, CardCode, NumAtCard,<br>DocDate = fecha_contabilizacion,<br>DocDueDate = fecha_vencimiento,<br>U_IDC_NUMGR, Comments"]
|
2026-07-09 09:48:30 -05:00
|
|
|
R --> S["DocumentLines[] +<br>DocumentInstallments[]"]
|
|
|
|
|
S --> T["← Retornar dict para<br>POST /Drafts"]
|
|
|
|
|
```
|