Exemplo n.º 1
0
def create_supplier(db: Session, supplier: schemas.Supplier):
    """Create new supplier and return its details."""
    new_id = db.query(func.max(models.Supplier.supplier_id)).scalar() + 1
    supplier.supplier_id = new_id
    db.add(models.Supplier(**supplier.dict()))
    db.commit()

    return read_supplier(db, supplier_id=new_id)
Exemplo n.º 2
0
async def post_suppliers(supplier: schemas.NewSupplier, db: Session = Depends(get_db)):
    new_supplier_id = db.query(models.Supplier).count() + 1
    new_supplier = models.Supplier(SupplierID=new_supplier_id,
                                   CompanyName=supplier.CompanyName,
                                   ContactName=supplier.ContactName,
                                   ContactTitle=supplier.ContactTitle,
                                   Address=supplier.Address,
                                   City=supplier.City,
                                   PostalCode=supplier.PostalCode,
                                   Country=supplier.Country,
                                   Phone=supplier.Phone)
    db.add(new_supplier)
    db.commit()
    return db.query(models.Supplier).filter(models.Supplier.SupplierID == new_supplier_id).first()
Exemplo n.º 3
0
def add_supplier(db: Session, supplier: schemas.Supplier):
    last_id = db.query(models.Supplier).order_by(
        models.Supplier.SupplierID.desc()).first()
    s = models.Supplier(SupplierID=last_id.SupplierID + 1,
                        CompanyName=supplier.CompanyName,
                        ContactName=supplier.ContactName,
                        ContactTitle=supplier.ContactTitle,
                        Address=supplier.Address,
                        City=supplier.City,
                        Region=supplier.Region,
                        PostalCode=supplier.PostalCode,
                        Country=supplier.Country,
                        Phone=supplier.Phone,
                        Fax=supplier.Fax,
                        HomePage=supplier.HomePage)
    print(s.SupplierID)
    return (db.add(s))
Exemplo n.º 4
0
def add_supplier(db: Session, supplier: schemas.AddSupplier):
    supplier_id = db.query(models.Supplier).count() + 1
    db_supplier = models.Supplier(SupplierID=supplier_id,
                                  CompanyName=supplier.CompanyName,
                                  ContactName=supplier.ContactName,
                                  ContactTitle=supplier.ContactTitle,
                                  Address=supplier.Address,
                                  City=supplier.City,
                                  PostalCode=supplier.PostalCode,
                                  Country=supplier.Country,
                                  Phone=supplier.Phone,
                                  Fax=supplier.Fax,
                                  HomePage=supplier.HomePage)
    db.add(db_supplier)
    db.commit()
    db.refresh(db_supplier)
    return db_supplier
Exemplo n.º 5
0
def create_supplier(db: Session, supplier_from_msg: schemas.SupplierCreate):
    max_id = db.query(func.max(models.Supplier.SupplierID)).scalar()
    id_free = max_id + 1
    db_sup_from_msg = models.Supplier(
        SupplierID=id_free,
        CompanyName=supplier_from_msg.CompanyName,
        ContactName=supplier_from_msg.ContactName,
        ContactTitle=supplier_from_msg.ContactTitle,
        Address=supplier_from_msg.Address,
        City=supplier_from_msg.City,
        PostalCode=supplier_from_msg.PostalCode,
        Country=supplier_from_msg.Country,
        Phone=supplier_from_msg.Phone)

    db.add(db_sup_from_msg)
    db.commit()
    return db_sup_from_msg
Exemplo n.º 6
0
def create_supplier(db: Session, new_supplier: schemas.NewSupplier):
    highest_id = db.query(func.max(models.Supplier.SupplierID)).scalar()
    new_supplier.SupplierID = highest_id + 1
    db.add(models.Supplier(**new_supplier.dict()))
    db.commit()
    return get_supplier(db, highest_id + 1)
Exemplo n.º 7
0
def insert_supplier(db: Session, supplier: schemas.SupplierCreate):
    supplier_id = db.query(models.Supplier).count() + 1
    db_supplier = models.Supplier(SupplierID=supplier_id, **supplier.dict())
    db.add(db_supplier)
    db.commit()
    return db_supplier
Exemplo n.º 8
0
def add_supplier(db: Session, supplier: schemas.SupplierRequest, id: int):
		new_supplier = models.Supplier(SupplierID = id, CompanyName = supplier.CompanyName, ContactName = supplier.ContactName, ContactTitle = supplier.ContactTitle, Address = supplier.Address, City = supplier.City, PostalCode = supplier.PostalCode, Country = supplier.Country, Phone = supplier.Phone)
		db.add(new_supplier)
		db.commit()
Exemplo n.º 9
0
def post_suppliers(db: Session, new_supplier: schemas.PostSupplier):
    new_supplier.SupplierID = db.query(func.max(
        models.Supplier.SupplierID)).scalar() + 1
    db.add(models.Supplier(**new_supplier.dict()))
    db.commit()
    return get_suppliers_id(db, new_supplier.SupplierID)