Merge pull request 'refactor: streamline item imports and queries in processors' (#155) from feature/trasnferencia_mainx30 into development
Reviewed-on: ADUANASOFT/anexo76#155
This commit is contained in:
@@ -5,8 +5,7 @@ from .schemas import Mainx30GenerationRequest, ErrorValidacion
|
||||
|
||||
# --- MODELOS A76 ---
|
||||
from api.v1.modules.a76.invoices.models import InvoiceHeader, InvoiceComplianceMx
|
||||
from api.v1.modules.a76.items.models import Item
|
||||
from api.v1.modules.a76.items.line_items.models import LineItem
|
||||
from api.v1.modules.a76.items.models import LineItem
|
||||
from api.v1.modules.a76.clients_and_providers.models import ClientProvider
|
||||
|
||||
class ScaiiProcessor:
|
||||
@@ -201,8 +200,8 @@ class ScaiiProcessor:
|
||||
self.cuenta_partidas += 3
|
||||
|
||||
# --- PARTIDAS (DETALLE IV20-IV27) ---
|
||||
items_query = db.query(LineItem).join(Item).filter(
|
||||
Item.invoice_id == factura.id
|
||||
items_query = db.query(LineItem).filter(
|
||||
LineItem.invoice_id == factura.id
|
||||
).options(
|
||||
joinedload(LineItem.part_info),
|
||||
joinedload(LineItem.description),
|
||||
|
||||
@@ -6,8 +6,7 @@ from .schemas import Mainx30GenerationRequest, ErrorValidacion
|
||||
|
||||
# --- MODELOS A76 ---
|
||||
from api.v1.modules.a76.invoices.models import InvoiceHeader, InvoiceComplianceMx
|
||||
from api.v1.modules.a76.items.models import Item
|
||||
from api.v1.modules.a76.items.line_items.models import LineItem
|
||||
from api.v1.modules.a76.items.models import LineItem
|
||||
from api.v1.modules.a76.clients_and_providers.models import ClientProvider
|
||||
|
||||
class ScaiiProcessor:
|
||||
@@ -280,12 +279,12 @@ class ScafDefProcessor(ScaiiProcessor):
|
||||
self.cuenta_partidas += 3
|
||||
|
||||
# Items IV20-27
|
||||
items_headers = db.query(Item).filter(Item.invoice_id == factura.id).all()
|
||||
items_headers = db.query(LineItem).filter(LineItem.invoice_id == factura.id).all()
|
||||
item_ids = [ih.id for ih in items_headers]
|
||||
|
||||
if item_ids:
|
||||
items_query = db.query(LineItem).filter(
|
||||
LineItem.item_id.in_(item_ids)
|
||||
LineItem.id.in_(item_ids)
|
||||
).options(
|
||||
joinedload(LineItem.part_info),
|
||||
joinedload(LineItem.description),
|
||||
@@ -298,7 +297,7 @@ class ScafDefProcessor(ScaiiProcessor):
|
||||
for line in items_query:
|
||||
f_consec_partidas += 1
|
||||
part_num = (line.part_info.part_number if line.part_info else "S/N")[:25]
|
||||
po = (line.financial.purchase_order or "")[:20] if line.financial else ""
|
||||
po = (line.order or "")[:20] if line.financial else ""
|
||||
|
||||
# IV20
|
||||
lineas.append(f"IV20{f_consec_partidas:03d} {part_num:<25}C {po:<20}")
|
||||
@@ -314,7 +313,7 @@ class ScafDefProcessor(ScaiiProcessor):
|
||||
qty = float(line.quantity.quantity or 0) if line.quantity else 0.0
|
||||
pb = float(line.quantity.gross_weight or 0) if line.quantity else 0.0
|
||||
pn = float(line.quantity.net_weight or 0) if line.quantity else 0.0
|
||||
costo_u = float(line.financial.unit_price_usd or 0) if line.financial else 0.0
|
||||
costo_u = float(line.financial.unit_cost_capture or 0) if line.financial else 0.0
|
||||
|
||||
um = (line.unit_of_measure_info.american_code or "PCS")[:3] if line.unit_of_measure_info else "PCS"
|
||||
pais = ((line.customs.origin_country or "MX")[:2]).upper() if line.customs else "MX"
|
||||
|
||||
@@ -6,8 +6,7 @@ from .schemas import Mainx30GenerationRequest, ErrorValidacion
|
||||
|
||||
# --- MODELOS A76 ---
|
||||
from api.v1.modules.a76.invoices.models import InvoiceHeader, InvoiceComplianceMx
|
||||
from api.v1.modules.a76.items.models import Item
|
||||
from api.v1.modules.a76.items.line_items.models import LineItem
|
||||
from api.v1.modules.a76.items.models import LineItem
|
||||
from api.v1.modules.a76.clients_and_providers.models import ClientProvider
|
||||
|
||||
class ScaiiProcessor:
|
||||
@@ -251,12 +250,12 @@ class ScafTempProcessor(ScaiiProcessor):
|
||||
|
||||
# Partidas IV20, IV21, IV22, IV24, IV26, IV27
|
||||
# Let's get Item IDs first to ensure we find them
|
||||
items_headers = db.query(Item).filter(Item.invoice_id == factura.id).all()
|
||||
items_headers = db.query(LineItem).filter(LineItem.invoice_id == factura.id).all()
|
||||
item_ids = [ih.id for ih in items_headers]
|
||||
|
||||
if item_ids:
|
||||
items_query = db.query(LineItem).filter(
|
||||
LineItem.item_id.in_(item_ids)
|
||||
LineItem.id.in_(item_ids)
|
||||
).options(
|
||||
joinedload(LineItem.part_info),
|
||||
joinedload(LineItem.description),
|
||||
@@ -283,7 +282,7 @@ class ScafTempProcessor(ScaiiProcessor):
|
||||
qty = float(line.quantity.quantity or 0) if line.quantity else 0.0
|
||||
pb = float(line.quantity.gross_weight or 0) if line.quantity else 0.0
|
||||
pn = float(line.quantity.net_weight or 0) if line.quantity else 0.0
|
||||
costo_u = float(line.financial.unit_price_usd or 0) if line.financial else 0.0
|
||||
costo_u = float(line.financial.unit_cost_capture or 0) if line.financial else 0.0
|
||||
|
||||
um = line.unit_of_measure_info.american_code if line.unit_of_measure_info else "PCS"
|
||||
pais = (line.customs.origin_country or "MX")[:2] if line.customs else "MX"
|
||||
@@ -392,11 +391,11 @@ class ScaiiTempProcessor(ScafTempProcessor):
|
||||
self.cuenta_partidas += 1
|
||||
|
||||
# Partidas IV20, IV21, IV22
|
||||
items_headers = db.query(Item).filter(Item.invoice_id == factura.id).all()
|
||||
items_headers = db.query(LineItem).filter(LineItem.invoice_id == factura.id).all()
|
||||
item_ids = [ih.id for ih in items_headers]
|
||||
|
||||
if item_ids:
|
||||
items_query = db.query(LineItem).filter(LineItem.item_id.in_(item_ids)).all()
|
||||
items_query = db.query(LineItem).filter(LineItem.id.in_(item_ids)).all()
|
||||
|
||||
for line in items_query:
|
||||
f_consec_partidas += 1
|
||||
|
||||
Reference in New Issue
Block a user