예제 #1
0
def create_product_type():
    data = request.get_json() or {}
    if 'name' not in data:
        return bad_request('Must include product type name.')
    if ProductType.query.filter_by(name=data['name']).first():
        return bad_request('Another product type already has the same name.')
    product_type = ProductType()
    product_type.from_dict(data)
    db.session.add(product_type)
    db.session.commit()
    response = jsonify(product_type.to_dict())
    response.status_code = 201
    response.headers['Location'] = url_for('api.get_product_type', id=product_type.id)
    return response
예제 #2
0
 def test_delete(self, session):
     session.add(ProductType(Name='foo'))
     session.commit()
     pt = ProductType.query.filter().first()
     assert pt.Active
     pt.delete()
     assert not pt.Active
예제 #3
0
    def post(self):
        name = request.json['name']
        amount = request.json['amount']
        type_name = request.json['product_type']
        sku = request.json['sku']

        product_type = ProductType.query.filter_by(name=type_name).first()

        if product_type:
            pt_res = type_name
        else:
            product_type = ProductType(name=type_name)
            db.session.add(product_type)
            db.session.commit()
            pt_res = f'Product type was created {type_name}'

        product = Product(name=name,
                          amount=amount,
                          sku=sku,
                          type_id=product_type.id)
        db.session.add(product)
        db.session.commit()
        return {
            "name": product.name,
            "amount": product.amount,
            "product_type": pt_res
        }
예제 #4
0
 def test_to_dict(self, session):
     session.add(ProductType(Name='foo'))
     session.commit()
     pt = ProductType.query.filter().first()
     pt_dict = pt.to_dict()
     assert pt_dict['Name'] == 'foo'
     assert pt_dict['ID'] == 1
     assert pt_dict['Active']
예제 #5
0
def admin_product_type():
    form = ProductTypeForm()
    types = ProductType.query.all()
    if request.method=='POST':
        type = ProductType(
            type_name = form.type_name.data
        )
        db.session.add(type)
        db.session.commit()
        return redirect(url_for('admin_product_type'))
    return loginCheck(render_template('admin/product_type.html',form=form,types=types))
예제 #6
0
def deploy():
    """Run deployment tasks."""
    from flask_migrate import upgrade

    # migrate database to latest revision
    upgrade()
    # create all tables
    db.create_all()

    # insert default values
    ShopDetails.insert_shop_details()
    Admin.insert_default_admin()
    StatusCatalog.insert_order_status()
    PaymentMethod.insert_payment_method()
    PaymentStatus.insert_payment_status()

    Unit.insert_units()
    DeliveryCharge.insert_default_charge()
    WeightDeliveryCharge.insert_default_charge()
    ProductType.insert_categories()
예제 #7
0
def add_product_type(db):
    pt1 = ProductType()
    pt1.name = u'汉堡系列'
    pt1.description = u'被面包包裹的健康'

    pt2 = ProductType()
    pt2.name = u'面条系列'
    pt2.description = u'爽滑入味的健康'

    pt3 = ProductType()
    pt3.name = u'沙拉系列'
    pt3.description = u'冷拌的美味健康'

    db.session.add(pt1)
    db.session.add(pt2)
    db.session.add(pt3)
    db.session.commit()
예제 #8
0
    def test_insert_product(self):
        pt = ProductType(type_name="Pulses")

        unit = Unit(unit_name="Kilogram", unit_short="kg")

        db.session.add(pt)
        db.session.add(unit)
        db.session.commit()

        unit = Unit.query.filter_by(unit_name="Kilogram").first()
        producttype = ProductType.query.filter_by(type_name="Pulses").first()
        p = Product(
            product_name="rice",
            product_description="basmatic rice",
            price_per_unit=123,
            product_items=producttype,
            unit_items=unit,
        )
        db.session.add(p)
        db.session.commit()
        self.assertTrue(
            Product.query.filter_by(product_name="rice").first() == p)
예제 #9
0
def get_product_types():
    page = request.args.get('page', 1, type=int)
    per_page = min(request.args.get('per_page', 10, type=int), 100)
    data = ProductType.to_collection_dict(ProductType.query, page, per_page, 'api.get_product_types')
    return jsonify(data)
예제 #10
0
def add_product_type(db):
    pt1 = ProductType()
    pt1.name = u'汉堡系列'
    pt1.description = u'被面包包裹的健康'

    pt2 = ProductType()
    pt2.name = u'面条系列'
    pt2.description = u'爽滑入味的健康'

    pt3 = ProductType()
    pt3.name = u'沙拉系列'
    pt3.description = u'冷拌的美味健康'

    db.session.add(pt1)
    db.session.add(pt2)
    db.session.add(pt3)
    db.session.commit()
예제 #11
0
def image_session(session):
    """Creates a session with a camera and prod type already in the db"""
    session.add(Camera(Name='foo'))
    session.add(ProductType(Name='bar'))
    session.commit()
    return session
예제 #12
0
 def test_name_is_unique(self, session):
     session.add(ProductType(Name='foo'))
     session.commit()
     with pytest.raises(IntegrityError):
         session.add(ProductType(Name='foo'))
         session.commit()
예제 #13
0
 def test_update_from_dict(self):
     pt = ProductType(Name='foo')
     pt.update_from_dict({'Name': 'bar', 'spam': 'baz'})
     assert pt.Name == 'bar'
예제 #14
0
 def test_from_dict(self):
     pt = ProductType.from_dict({'Name': 'foo', 'spam': 'baz'})
     assert pt.Name == 'foo'
예제 #15
0
 def test_insert_product_type(self):
     pt = ProductType(type_name="Pulses")
     db.session.add(pt)
     db.session.commit()
     self.assertTrue(
         ProductType.query.filter_by(type_name="Pulses").first() == pt)