Exemple #1
0
 def post(self):
     """Creates a new Product """
     data = request.json
     new_product = ProductModel(**data)
     new_product.save()
     response_object = {
         'status': 'success',
         'message': 'Product successfully created.',
         'product_id': new_product.id
     }
     return response_object, 201
Exemple #2
0
 def test_amount_default_to_zero(self, database):
     stock = Stock(name='Stock').create()
     product = Product(name='Product').create()
     lot_number = 'Lot'
     stock_product = StockProduct(stock_id=stock.id,
                                  product_id=product.id,
                                  lot_number=lot_number)
     db.session.add(stock_product)
     db.session.commit()
     assert stock_product.amount is 0
Exemple #3
0
 def test_lot_number_not_null(self, database):
     stock = Stock(name='Stock').create()
     product = Product(name='Product').create()
     lot_number = None
     stock_product = StockProduct(stock_id=stock.id,
                                  product_id=product.id,
                                  lot_number=lot_number)
     db.session.add(stock_product)
     with pytest.raises(sqlexc.IntegrityError,
                        match=r'.*not-null.*'):
         db.session.commit()
Exemple #4
0
 def test_non_unique_order_item_constraint(self, database):
     order = Order()
     product = Product(name='Product')
     specification = Specification(product=product)
     order_item_1 = OrderItem(
         item=specification, order=order, lot_number='lot_1')
     order_item_2 = OrderItem(
         item=specification, order=order, lot_number='lot_1')
     db.session.add(order_item_1)
     db.session.add(order_item_2)
     db.session.commit()
     assert order_item_1.lot_number == 'lot_1'
     assert order_item_2.lot_number == 'lot_1'
Exemple #5
0
 def test_delete_order_cascades_to_order_items(self, database):
     order = Order()
     product = Product(name='Product')
     specification = Specification(product=product)
     order_item_1 = OrderItem(item=specification,
                              order=order,
                              lot_number='lot_1')
     order_item_2 = OrderItem(item=specification,
                              order=order,
                              lot_number='lot_2')
     order.create()
     assert len(order.order_items) is 2
     assert order_item_1.order_id is order.id
     assert order_item_2.order_id is order.id
     order.delete()
     assert not OrderItem.query.all()
Exemple #6
0
 def test_stock_delete_cascades_to_stock_products(self, database):
     stock = Stock(name='Stock')
     product = Product(name='Product')
     stock_product_1 = StockProduct(stock=stock,
                                    product=product,
                                    lot_number='Lot 1')
     stock_product_2 = StockProduct(stock=stock,
                                    product=product,
                                    lot_number='Lot 2')
     stock.create()
     assert len(stock.stock_products) is 2
     assert stock_product_1.stock_id is stock.id
     assert stock_product_2.stock_id is stock.id
     stock.delete()
     assert not StockProduct.query.all()
     assert not Stock.query.all()
Exemple #7
0
 def test_unique_stock_product_constraint(self, database):
     stock = Stock(name='Stock').create()
     product = Product(name='Product').create()
     lot_number = 'Lot'
     stock_product_1 = StockProduct(stock_id=stock.id,
                                    product_id=product.id,
                                    lot_number=lot_number)
     stock_product_2 = StockProduct(stock_id=stock.id,
                                    product_id=product.id,
                                    lot_number=lot_number)
     db.session.add(stock_product_1)
     db.session.add(stock_product_2)
     with pytest.raises(sqlexc.IntegrityError,
                        match=r'.*unique_stock_product.*'):
         db.session.commit()
     db.session.rollback()
     db.session.add(stock_product_1)
     stock_product_2.lot_number = 'Lot_2'
     db.session.add(stock_product_2)
     db.session.commit()
Exemple #8
0
    def save_info(self):

        irobotboxs = IrobotboxOrder.query.filter_by(Oper1=None).all()

        ####获取所有渠道
        for ib in irobotboxs:
            check_source = Source.query.filter_by(
                SourceId=ib.OrderSourceID).first()
            if check_source:
                pass
            else:
                source = Source(SourceId=ib.OrderSourceID,
                                SourceName=ib.OrderSourceName)
                db.session.add(source)
                db.session.commit()

            check_customer = Customer.query.filter_by(
                ClientUserAccount=ib.ClientUserAccount).first()
            if check_customer:
                pass
            else:
                customer = Customer(ClientUserAccount=ib.ClientUserAccount,
                                    Email=ib.Email,
                                    Telephone=ib.Telephone)
                db.session.add(customer)
                db.session.commit()

            order = Order(OrderCode = ib.OrderCode, Currency = ib.Currency,TrackNumber=ib.TrackNumbers,\
             TotalPrice = ib.TotalPrice)
            track = Track(TrackNumber=ib.TrackNumbers, order_id=ib.OrderCode)
            order.source_id = ib.OrderSourceID
            order.client_id = ib.ClientUserAccount
            db.session.add(order)
            db.session.add(track)
            ib.Oper1 = 1

            gettotalSettlement(ib.OrderCode, ib.TotalPrice, ib.Currency,
                               'total', TotalSettlement)

            chanel = ib.OrderSourceName

            gettotalSettlement(ib.OrderCode, ib.TotalPrice, ib.Currency,
                               chanel, TypeSettlement)

            sourcename = chanel[:3]

            if sourcename == 'Ama':

                gettotalSettlement(ib.OrderCode, ib.TotalPrice, ib.Currency,
                                   'AMA', AMASettlement)

            elif sourcename == 'SMT':

                gettotalSettlement(ib.OrderCode, ib.TotalPrice, ib.Currency,
                                   'SMT', SMTSettlement)

            elif sourcename == 'eba':

                gettotalSettlement(ib.OrderCode, ib.TotalPrice, ib.Currency,
                                   'EBA', EBASettlement)

            elif sourcename == 'WIS':

                gettotalSettlement(ib.OrderCode, ib.TotalPrice, ib.Currency,
                                   'WIS', WISSettlement)

            else:
                gettotalSettlement(ib.OrderCode, ib.TotalPrice, ib.Currency,
                                   'other', OtherSettlement)

        irobotboxsproduct = IrobotboxOrderProducts.query.all()

        for ibp in irobotboxsproduct:
            product = Product(SKU=ibp.SKU,
                              ProductNum=ibp.ProductNum,
                              order_id=ibp.order_id)
            db.session.add(product)
            db.session.commit()

            getskuSettlement(ibp.order_id, ibp.SKU, SKUSettlement)

            getnumSettlement(ibp.order_id, ibp.SKU, ibp.ProductNum,
                             NumberSettlement)

            getsaleSettlement(ibp.order_id, ibp.ClientSKU, ibp.ProductNum,
                              SalesSettlement)