feature/separacion-de-tax-id-de-rfc
This commit is contained in:
@@ -136,8 +136,8 @@ class AvisoConsolidadoExportacionService:
|
||||
if client_obj:
|
||||
# Fetch Address
|
||||
c_addr = db.query(ClientProviderAddress).filter(ClientProviderAddress.client_id == target_client_id).first()
|
||||
# Identificador fiscal único en ClientProvider.rfc (RFC o TAX-ID)
|
||||
c_rfc = getattr(client_obj, "rfc", "") or ""
|
||||
# Identificador fiscal efectivo: RFC (nacional) o TAX-ID (extranjero)
|
||||
c_rfc = getattr(client_obj, "fiscal_id", "") or ""
|
||||
|
||||
c_dir_str = "DOMICILIO NO REGISTRADO"
|
||||
if c_addr:
|
||||
|
||||
@@ -31,17 +31,8 @@ class ScaiiProcessor:
|
||||
else:
|
||||
pais = pais_raw[:2]
|
||||
|
||||
tax_id = ""
|
||||
if pais == "MX":
|
||||
tax_id = cliente.rfc or ""
|
||||
else:
|
||||
# Try generic tax_id field if exists, else generic field or RFC as fallback
|
||||
# Providing a fallback to extra_information or web_key if needed, but per model inspection:
|
||||
# We don't see a specific 'tax_id' field in ClientProvider model snippet.
|
||||
# We see 'rfc'. Let's use RFC as generic holder or look for 'tax_id' if I missed it.
|
||||
# Re-reading model: rfc is the only obvious one.
|
||||
# Let's use RFC field for foreign tax id too unless instructed otherwise.
|
||||
tax_id = cliente.rfc or ""
|
||||
# Identificador fiscal del cliente: RFC (nacional) o TAX-ID (extranjero)
|
||||
tax_id = cliente.fiscal_id or ""
|
||||
|
||||
data = {
|
||||
"nombre": (cliente.name or "")[:39],
|
||||
@@ -123,10 +114,10 @@ class ScaiiProcessor:
|
||||
if factura.compliance_mx:
|
||||
if factura.compliance_mx.provider_id:
|
||||
s_obj = db.query(ClientProvider).filter(ClientProvider.id == factura.compliance_mx.provider_id).first()
|
||||
if s_obj: s_rfc = s_obj.rfc or ""
|
||||
if s_obj: s_rfc = s_obj.fiscal_id or ""
|
||||
if factura.compliance_mx.sold_to_id:
|
||||
c_obj = db.query(ClientProvider).filter(ClientProvider.id == factura.compliance_mx.sold_to_id).first()
|
||||
if c_obj: c_rfc = c_obj.rfc or ""
|
||||
if c_obj: c_rfc = c_obj.fiscal_id or ""
|
||||
|
||||
lineas.append(
|
||||
f"IV01{factura.invoice_number[:15]:<15}"
|
||||
|
||||
@@ -128,7 +128,7 @@ class ConsolidadoImportacionMexService:
|
||||
ciudad=(addr.city or "") if addr else "",
|
||||
estado=(addr.state or "") if addr else "",
|
||||
pais=(addr.country or "MEX") if addr else "MEX",
|
||||
tax_id=getattr(main, "rfc", "") or "",
|
||||
tax_id=getattr(main, "fiscal_id", "") or "",
|
||||
programa="IMMEX" if (prog and prog.program) else "",
|
||||
autorizacion=prog.program_number if prog else "",
|
||||
prosec=(
|
||||
|
||||
@@ -82,7 +82,7 @@ class ConsolidadoImportacionMexService:
|
||||
ciudad=(addr.city or "") if addr else "",
|
||||
estado=(addr.state or "") if addr else "",
|
||||
pais=(addr.country or "MEX") if addr else "MEX",
|
||||
tax_id=getattr(main, "rfc", "") or "",
|
||||
tax_id=getattr(main, "fiscal_id", "") or "",
|
||||
programa="IMMEX" if (prog and prog.program) else "",
|
||||
autorizacion=prog.program_number if prog else "",
|
||||
prosec=prog.prosec_authorization if (prog and prog.prosec and prog.prosec_authorization) else "",
|
||||
|
||||
@@ -162,7 +162,7 @@ class FacturaImportacionMexService:
|
||||
ciudad=(addr.city or "") if addr else "",
|
||||
estado=(addr.state or "") if addr else "",
|
||||
pais=(addr.country or "MEX") if addr else "MEX",
|
||||
tax_id=getattr(main, "rfc", "") or "",
|
||||
tax_id=getattr(main, "fiscal_id", "") or "",
|
||||
programa="IMMEX" if (prog and prog.program) else "",
|
||||
autorizacion=prog.program_number if prog else "",
|
||||
prosec=(
|
||||
|
||||
@@ -82,7 +82,7 @@ class FacturaImportacionMexService:
|
||||
ciudad=(addr.city or "") if addr else "",
|
||||
estado=(addr.state or "") if addr else "",
|
||||
pais=(addr.country or "MEX") if addr else "MEX",
|
||||
tax_id=getattr(main, "rfc", "") or "",
|
||||
tax_id=getattr(main, "fiscal_id", "") or "",
|
||||
programa="IMMEX" if (prog and prog.program) else "",
|
||||
autorizacion=prog.program_number if prog else "",
|
||||
prosec=prog.prosec_authorization if (prog and prog.prosec and prog.prosec_authorization) else "",
|
||||
|
||||
@@ -156,7 +156,7 @@ class FacturaImportacionUsaService:
|
||||
ciudad=(addr.city or "") if addr else "",
|
||||
estado=(addr.state or "") if addr else "",
|
||||
pais=(addr.country or "USA") if addr else "USA",
|
||||
tax_id=getattr(main, "rfc", "") or "",
|
||||
tax_id=getattr(main, "fiscal_id", "") or "",
|
||||
programa="IMMEX" if (prog and prog.program) else "",
|
||||
autorizacion=prog.program_number if prog else "",
|
||||
prosec=(
|
||||
|
||||
@@ -103,7 +103,7 @@ class PackingListService:
|
||||
ciudad=(addr.city or "") if addr else "",
|
||||
estado=(addr.state or "") if addr else "",
|
||||
pais=(addr.country or "MEX") if addr else "MEX",
|
||||
tax_id=getattr(main, "rfc", "") or "",
|
||||
tax_id=getattr(main, "fiscal_id", "") or "",
|
||||
programa="IMMEX" if (prog and prog.program) else "",
|
||||
autorizacion=prog.program_number if prog else "",
|
||||
prosec=prog.prosec_authorization if (prog and prog.prosec and prog.prosec_authorization) else "",
|
||||
|
||||
@@ -31,8 +31,9 @@ class ScaiiProcessor:
|
||||
pais = "US"
|
||||
else:
|
||||
pais = pais_raw[:2]
|
||||
|
||||
tax_id = cliente.rfc or ""
|
||||
|
||||
# Identificador fiscal del cliente: RFC (nacional) o TAX-ID (extranjero)
|
||||
tax_id = cliente.fiscal_id or ""
|
||||
|
||||
data = {
|
||||
"nombre": (cliente.name or "")[:39],
|
||||
@@ -161,10 +162,10 @@ class ScafDefProcessor(ScaiiProcessor):
|
||||
if factura.compliance_mx:
|
||||
if factura.compliance_mx.sold_to_id:
|
||||
c_obj = db.query(ClientProvider).filter(ClientProvider.id == factura.compliance_mx.sold_to_id).first()
|
||||
if c_obj: c_tax = (c_obj.rfc or "")[:12]
|
||||
if c_obj: c_tax = (c_obj.fiscal_id or "")[:12]
|
||||
if factura.compliance_mx.provider_id:
|
||||
s_obj = db.query(ClientProvider).filter(ClientProvider.id == factura.compliance_mx.provider_id).first()
|
||||
if s_obj: s_tax = (s_obj.rfc or "")[:12]
|
||||
if s_obj: s_tax = (s_obj.fiscal_id or "")[:12]
|
||||
|
||||
# IV01 uses 11 spaces then 'C' per Clarion logic
|
||||
# Adjusted validation for RFCs to avoid crashes or None
|
||||
|
||||
@@ -31,8 +31,9 @@ class ScaiiProcessor:
|
||||
pais = "US"
|
||||
else:
|
||||
pais = pais_raw[:2]
|
||||
|
||||
tax_id = cliente.rfc or ""
|
||||
|
||||
# Identificador fiscal del cliente: RFC (nacional) o TAX-ID (extranjero)
|
||||
tax_id = cliente.fiscal_id or ""
|
||||
|
||||
data = {
|
||||
"nombre": (cliente.name or "")[:39],
|
||||
@@ -178,10 +179,10 @@ class ScafTempProcessor(ScaiiProcessor):
|
||||
if factura.compliance_mx:
|
||||
if factura.compliance_mx.sold_to_id:
|
||||
c_obj = db.query(ClientProvider).filter(ClientProvider.id == factura.compliance_mx.sold_to_id).first()
|
||||
if c_obj: c_tax = c_obj.rfc[:12] if c_obj.rfc else ""
|
||||
if c_obj: c_tax = c_obj.fiscal_id[:12] if c_obj.fiscal_id else ""
|
||||
if factura.compliance_mx.provider_id:
|
||||
s_obj = db.query(ClientProvider).filter(ClientProvider.id == factura.compliance_mx.provider_id).first()
|
||||
if s_obj: s_tax = s_obj.rfc[:12] if s_obj.rfc else ""
|
||||
if s_obj: s_tax = s_obj.fiscal_id[:12] if s_obj.fiscal_id else ""
|
||||
|
||||
lineas.append(
|
||||
f"IV01{factura.invoice_number[:15]:<15}{f_fecha}{entry_port:<5}{' ':<11}C"
|
||||
|
||||
@@ -113,19 +113,19 @@ class DatabaseHelper:
|
||||
|
||||
try:
|
||||
sql = text("""
|
||||
SELECT cp.name, cp.rfc
|
||||
SELECT cp.name, cp.rfc, cp.tax_id
|
||||
FROM a76.clients_and_providers cp
|
||||
WHERE cp.id = :client_code
|
||||
AND (cp.client_or_provider = :client_type OR cp.client_or_provider = 'both')
|
||||
""")
|
||||
result = db.execute(sql, {"client_code": client_code, "client_type": client_type}).fetchone()
|
||||
|
||||
|
||||
if result:
|
||||
# Unified identifier: cp.rfc contains either RFC (national) or TAX-ID (foreign)
|
||||
# Identificadores separados: rfc (nacional) y tax_id (extranjero), cada uno en su columna
|
||||
return {
|
||||
"name": result[0],
|
||||
"rfc": result[1],
|
||||
"tax_id": result[1],
|
||||
"tax_id": result[2],
|
||||
}
|
||||
else:
|
||||
logger.debug(f"Client {client_code} not found as {client_type}")
|
||||
|
||||
Reference in New Issue
Block a user