Se ajusto la tabla de quantity y de packeges, y se creo la relacion
This commit is contained in:
@@ -19,7 +19,7 @@ class Package(Base, TenantScopedMixin, TimestampMixin):
|
||||
__table_args__ = (
|
||||
PrimaryKeyConstraint("id", name="packages_pkey"),
|
||||
UniqueConstraint("tenant_id", "company_id", "key", name="packages_key_ukey"),
|
||||
{"schema": "a76"},
|
||||
{"schema": "a76", "extend_existing": True},
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||||
|
||||
@@ -4,6 +4,8 @@ from sqlalchemy import String, Integer, Numeric, SmallInteger, ForeignKey
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
from core.database import Base
|
||||
|
||||
from api.v1.modules.a76.general_catalogs.packages.models import Package
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..line_items.models import LineItem
|
||||
|
||||
@@ -38,13 +40,14 @@ class LineQuantity(Base):
|
||||
net_weight: Mapped[Optional[Decimal]] = mapped_column(Numeric(19, 8)) # PESONETO
|
||||
gross_weight: Mapped[Optional[Decimal]] = mapped_column(Numeric(19, 8)) # PESOBRUTO
|
||||
|
||||
|
||||
# Packaging
|
||||
package_key: Mapped[Optional[str]] = mapped_column(String(5)) # CLAVEBULTOS
|
||||
package_id: Mapped[Optional[int]] = mapped_column(ForeignKey("a76.packages.id"))
|
||||
package_quantity: Mapped[Optional[int]] = mapped_column(Integer) # CANTBULTOS
|
||||
package_description: Mapped[Optional[str]] = mapped_column(String(40)) # DESCBULTOS
|
||||
container_quantity: Mapped[Optional[int]] = mapped_column(SmallInteger) # CANTBULCONT
|
||||
container_description: Mapped[Optional[str]] = mapped_column(String(40)) # DESCCONTENEDOR
|
||||
box_count: Mapped[Optional[str]] = mapped_column(String(30)) # NOCAJAS
|
||||
|
||||
# Relationship (one-to-one)
|
||||
line: Mapped["LineItem"] = relationship(back_populates="quantity")
|
||||
line: Mapped["LineItem"] = relationship(back_populates="quantity")
|
||||
package_info: Mapped[Optional["Package"]] = relationship(Package)
|
||||
@@ -313,7 +313,7 @@ class PackingListService:
|
||||
cantidad_importacion=qty.quantity if qty else 0,
|
||||
unidad_medida=uom_comercial, # Commercial UOM (PCS, EA)
|
||||
cantidad_bultos=int(qty.package_quantity) if qty and qty.package_quantity else 0,
|
||||
clave_bultos=(qty.package_key or "") if qty else "",
|
||||
clave_bultos=(qty.package_info.key if qty and qty.package_info else "") if qty else "",
|
||||
peso_neto=self.formatear_numero(peso_neto_kg),
|
||||
peso_bruto=self.formatear_numero(peso_bruto_kg),
|
||||
peso_neto_lbs=self.formatear_numero(peso_neto_lb),
|
||||
|
||||
2
drop_column.sql
Normal file
2
drop_column.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE a76.item_line_quantities
|
||||
DROP COLUMN IF EXISTS package_key;
|
||||
2
drop_desc_column.sql
Normal file
2
drop_desc_column.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE a76.item_line_quantities
|
||||
DROP COLUMN IF EXISTS package_description;
|
||||
10
fix_data.sql
Normal file
10
fix_data.sql
Normal file
@@ -0,0 +1,10 @@
|
||||
-- Actualizar el nuevo campo package_id usando el valor numérico guardado erróneamente en package_key
|
||||
UPDATE a76.item_line_quantities
|
||||
SET
|
||||
package_id = CAST(package_key AS INTEGER)
|
||||
WHERE
|
||||
package_key ~ '^\d+$'
|
||||
AND package_id IS NULL;
|
||||
|
||||
-- Opcional: Limpiar el campo package_key si ya se migró (para evitar confusión futura, pero mejor dejarlo por seguridad)
|
||||
-- UPDATE a76.item_line_quantities SET package_key = NULL WHERE package_id IS NOT NULL;
|
||||
18
fix_db_column.py
Normal file
18
fix_db_column.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from sqlalchemy import text
|
||||
from core.database import SessionLocal
|
||||
|
||||
def add_column():
|
||||
db = SessionLocal()
|
||||
try:
|
||||
sql = text("ALTER TABLE a76.item_line_quantities ADD COLUMN IF NOT EXISTS package_id INTEGER REFERENCES a76.packages(id);")
|
||||
db.execute(sql)
|
||||
db.commit()
|
||||
print("Successfully added package_id column.")
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
db.rollback()
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
add_column()
|
||||
2
fix_schema.sql
Normal file
2
fix_schema.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE a76.item_line_quantities
|
||||
ADD COLUMN IF NOT EXISTS package_id INTEGER REFERENCES a76.packages (id);
|
||||
Reference in New Issue
Block a user