Add ENTRY_VOID movement type and integrate balance entry creation in invoice processing
- Introduced a new movement type 'ENTRY_VOID' to handle invoice reversals, ensuring net balance remains zero. - Updated the FaLineItem DTOs to replace 'download' with 'discharge' for consistency. - Implemented balance entry creation in the invoice processing and reverting workflows, enhancing inventory management. - Adjusted progress tracking messages to reflect the new balance entry generation steps.
This commit is contained in:
@@ -25,6 +25,7 @@ from .sub_process.review_rule_octave import (
|
||||
)
|
||||
from ...common.process.review_uma import revisa_uma
|
||||
from .sub_process.assing_values import assign_values_lines, assign_values_invoice
|
||||
from ..balance.create_balance_entries import create_balance_entries
|
||||
|
||||
|
||||
|
||||
@@ -282,4 +283,7 @@ def main_process(db: Session, invoice: InvoiceHeader, tenant_id: str, company_id
|
||||
# Paso 7: Actualizar totales, IVA e incrementables y marcar como procesada
|
||||
_update_invoice_totals(invoice)
|
||||
|
||||
# Paso 8: Generar saldos en a24.balance_movement (una entrada por partida)
|
||||
create_balance_entries(db, invoice, lines)
|
||||
|
||||
db.flush()
|
||||
@@ -12,6 +12,7 @@ from .sub_process.review_exchange_rate import review_exchange_rate
|
||||
from .sub_process.review_weights import review_weights_kgs, review_weights_lbs
|
||||
from .sub_process.review_rule_octave import valida_imp_regla_octava, descuenta_cupo_r_octava
|
||||
from .sub_process.assing_values import assign_values_lines, assign_values_invoice
|
||||
from ..balance.create_balance_entries import create_balance_entries
|
||||
from .main_process import _validate_sisimp_limits, _update_invoice_totals, _validate_lines
|
||||
|
||||
|
||||
@@ -99,6 +100,11 @@ def process_invoice_task(self: Task, invoice_id: int, tenant_id: str, company_id
|
||||
sql_errors=sql_errors,
|
||||
)
|
||||
_update_invoice_totals(invoice)
|
||||
|
||||
# ── Paso 8: Generar saldos en a24.balance_movement ───────────────────
|
||||
_progress(self, 98, "Generando saldos de inventario...")
|
||||
create_balance_entries(db, invoice, lines)
|
||||
|
||||
db.flush()
|
||||
db.commit()
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ from api.v1.modules.a76.items.models import LineItem
|
||||
from core.exceptions import ErrorCollector
|
||||
|
||||
from .sub_process.review_rule_octave import borra_saldos_regla_octava
|
||||
from ..balance.void_balance_entries import void_balance_entries
|
||||
|
||||
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
@@ -231,4 +232,11 @@ def revert_process(
|
||||
# ── Paso 2c: UPDATE QEqiMaq ───────────────────────────────────────────────
|
||||
_reset_line_quantities(lines)
|
||||
|
||||
# ── Paso 2d: Anular saldos en a24.balance_movement ───────────────────────
|
||||
# Inserta ENTRY_VOID por cada ENTRY abierto de esta factura, dejando el
|
||||
# balance neto en 0 para que las descargas de exportación no puedan
|
||||
# consumir esos lotes. El guard interno confirma que no haya consumos
|
||||
# activos (ya validado arriba, pero se mantiene como doble seguro).
|
||||
void_balance_entries(db, invoice)
|
||||
|
||||
return sql_errors
|
||||
|
||||
@@ -58,7 +58,7 @@ def revert_invoice_task(self: Task, invoice_id: int, tenant_id: str, company_id:
|
||||
)
|
||||
|
||||
# ── Paso 4: Confirmar transacción ─────────────────────────────────────
|
||||
_progress(self, 95, "Confirmando cambios...")
|
||||
_progress(self, 95, "Anulando saldos de inventario y confirmando...")
|
||||
db.flush()
|
||||
db.commit()
|
||||
|
||||
|
||||
@@ -166,7 +166,7 @@ class ItemService:
|
||||
# FA data uses line.id as primary key
|
||||
if line_data.fa_data:
|
||||
fa_dict = line_data.fa_data.model_dump(
|
||||
exclude_unset=True, exclude={"line_item_id"}
|
||||
exclude_unset=True, exclude={"line_item_id", "includes_subitems"}
|
||||
)
|
||||
fa_dict.update(
|
||||
{"id": line.id, "tenant_id": tenant_id, "company_id": company_id}
|
||||
|
||||
Reference in New Issue
Block a user