Esempio n. 1
0
class StockSchema(BaseSchema):
    class Meta:
        model = Stock
        exclude = ('order_items', 'created_on', 'updated_on')

    purchase_amount = ma.Float(precision=2)
    selling_amount = ma.Float(precision=2)
    units_purchased = ma.Integer()
    batch_number = ma.String(load=True)
    expiry_date = ma.Date()
    product_name = ma.String()
    product_id = ma.UUID(load=True)
    distributor_bill_id = ma.UUID(allow_none=True)
    units_sold = ma.Integer(dump_only=True, load=False)
    expired = ma.Boolean(dump_only=True)
    brand_name = ma.String(dump_only=True)
    quantity_label = ma.String(dump_only=True)
    default_stock = ma.Boolean(load=True, allow_none=True)

    distributor_bill = ma.Nested('DistributorBillSchema',
                                 many=False,
                                 dump_only=True,
                                 only=('id', 'distributor',
                                       'reference_number'))
    product = ma.Nested('ProductSchema',
                        many=False,
                        only=('id', 'name', 'retail_shop'),
                        dump_only=True)
Esempio n. 2
0
class OrderSchema(BaseSchema):
    class Meta:
        model = Order

    edit_stock = ma.Boolean()
    sub_total = ma.Float(precision=2)
    total = ma.Float(precision=2)

    customer_id = ma.Integer()
    discount_id = ma.Integer()
    items_count = ma.Integer()
    amount_due = ma.Integer()

    items = ma.Nested('ItemSchema',
                      many=True,
                      exclude=('order', 'order_id'),
                      load=True)
    retail_shop = ma.Nested('RetailShopSchema',
                            many=False,
                            only=('id', 'name'))
    customer = ma.Nested('CustomerSchema',
                         many=False,
                         load=True,
                         only=('id', 'name', 'mobile_number'))
    discounts = ma.Nested('DiscountSchema', many=True, load=True)
Esempio n. 3
0
class ProductSchema(BaseSchema):
    class Meta:
        model = Product
        exclude = ('created_on', 'updated_on')

    name = ma.String()
    description = ma.Dict()
    sub_description = ma.String()
    distributor_id = ma.Integer()
    brand_id = ma.Integer()
    retail_shop_id = ma.Integer()
    distributor = ma.Nested('DistributorSchema', many=False, dump_only=True, only=('id', 'name'))
    brand = ma.Nested('BrandSchema', many=False, dump_only=True, only=('id', 'name'))
    retail_shop = ma.Nested('RetailShopSchema', many=False, dump_only=True, only=('id', 'name'))
    mrp = ma.Integer(dump_only=True)
    available_stock = ma.Integer(dump_only=True)
    similar_products = ma.List(ma.Integer)
    tags = ma.Nested('TagSchema', many=True, only=('id', 'name'))
    salts = ma.Nested('SaltSchema', many=True, only=('id', 'name'))
    _links = ma.Hyperlinks(
        {
            'distributor': ma.URLFor('pos.distributor_view', slug='<distributor_id>'),
            'retail_shop': ma.URLFor('pos.retail_shop_view', slug='<retail_shop_id>'),
            'brand': ma.URLFor('pos.brand_view', slug='<brand_id>'),
            'stocks': ma.URLFor('pos.stock_view', __product_id__exact='<id>')
        }
    )

    stocks = ma.Nested('StockSchema', many=True, only=('purchase_amount', 'selling_amount', 'units_purchased',
                                                       'units_sold', 'expiry_date', 'purchase_date', 'id'))
    taxes = ma.Nested('TaxSchema', many=True, only=('id', 'name', 'value'))
    available_stocks = ma.Nested('StockSchema', many=True, only=('purchase_amount', 'selling_amount', 'units_purchased',
                                                                 'units_sold', 'expiry_date', 'purchase_date', 'id'))
Esempio n. 4
0
class ProductTaxSchema(BaseSchema):
    class Meta:
        model = ProductTax
        exclude = ('created_on', 'updated_on')
        fields = ('tax_id', 'product_id')

    tax_id = ma.Integer(load=True)
    product_id = ma.Integer(load=True)
Esempio n. 5
0
class OrderSchema(BaseSchema):
    class Meta:
        model = Order

    edit_stock = ma.Boolean()
    sub_total = ma.Float(precision=2)
    total = ma.Float(precision=2)

    retail_shop_id = ma.UUID(load=True, required=True)
    reference_number = ma.String(load=True, required=False, partial=True)
    customer_id = ma.UUID(load=True, required=False, allow_none=True)
    address_id = ma.UUID(load=True,
                         required=False,
                         partial=True,
                         allow_none=True)
    discount_id = ma.UUID()
    current_status_id = ma.UUID(load=True)
    user_id = ma.UUID(dump_only=True)
    items_count = ma.Integer(dump_only=True)
    amount_due = ma.Integer()
    invoice_number = ma.Integer(dump_only=True, allow_none=True)

    items = ma.Nested('ItemSchema',
                      many=True,
                      exclude=('order', 'order_id'),
                      load=True)
    retail_shop = ma.Nested('RetailShopSchema',
                            many=False,
                            only=('id', 'name'))
    customer = ma.Nested('CustomerSchema',
                         many=False,
                         dump_only=True,
                         only=['id', 'name', 'mobile_number'])
    created_by = ma.Nested('UserSchema',
                           many=False,
                           dump_only=True,
                           only=['id', 'name'])
    address = ma.Nested('AddressSchema',
                        many=False,
                        dump_only=True,
                        only=['id', 'name'])
    discounts = ma.Nested('DiscountSchema', many=True, load=True)
    current_status = ma.Nested('StatusSchema', many=False, dump_only=True)

    @post_load
    def save_data(self, obj):
        obj.user_id = current_user.id
        print(
            Order.query.with_entities(func.Count(Order.id)).filter(
                Order.retail_shop_id == obj.retail_shop_id).scalar() + 1)
        obj.invoice_number = Order.query.with_entities(func.Count(
            Order.id)).filter(
                Order.retail_shop_id == obj.retail_shop_id).scalar() + 1
        if obj.current_status_id is None:
            obj.current_status_id = Status.query.with_entities(
                Status.id).filter(Status.name == 'PLACED').first()
        return obj
Esempio n. 6
0
class UserRoleSchema(BaseSchema):

    class Meta:
        model = UserRole

    id = ma.Integer(load=True)
    user_id = ma.Integer(load=True)
    role_id = ma.Integer(load=True)
    user = ma.Nested('UserSchema', many=False)
    role = ma.Nested('RoleSchema', many=False)
Esempio n. 7
0
class UserRoleSchema(BaseSchema):
    class Meta:
        model = UserRole
        exclude = ('created_on', 'updated_on')

    id = ma.Integer(dump_only=True)
    user_id = ma.Integer(load=True)
    role_id = ma.Integer(load=True)
    user = ma.Nested('UserSchema', many=False)
    role = ma.Nested('RoleSchema', many=False)
Esempio n. 8
0
class HousingSchema(BaseSchema):
	class Meta:
		model = Housing
		exclude = ('updated_on',)
		# fields = ('no_of_rooms', 'no_of_bedrooms', 'no_of_bathrooms', '')

	id = ma.Integer(dump_only=True)
	prediction1 = ma.Number(dump_only=True)
	prediction2 = ma.Number(dump_only=True)
	user_id = ma.Integer(dump_only=True)
	user = ma.Nested(UserSchema, many=False, only=('id',))
Esempio n. 9
0
class ProductTagSchema(BaseSchema):
    class Meta:
        model = ProductTag
        exclude = ('created_on', 'updated_on')

    tag_id = ma.Integer(load=True)
    product_id = ma.Integer(load=True)

    @post_load
    def index_product(self, data):
        return data
Esempio n. 10
0
class StockSchema(BaseSchema):
    class Meta:
        model = Stock
        exclude = ('created_on', 'updated_on')

    purchase_amount = ma.Float(precision=2)
    selling_amount = ma.Float(precision=2)
    units_purchased = ma.Integer()
    batch_number = ma.String()
    expiry_date = ma.Date()
    distributor_bill_id = ma.Integer()
    units_sold = ma.Integer(dump_ony=True)
Esempio n. 11
0
class ItemTaxSchema(BaseSchema):
    class Meta:
        model = ItemTax
        exclude = ('created_on', 'updated_on')

    tax_value = ma.Float(precision=2)

    item_id = ma.Integer(load=True)
    tax_id = ma.Integer(load=True)

    tax = ma.Nested('TaxSchema', many=False, only=('id', 'name'))
    item = ma.Nested('ItemSchema', many=False)
Esempio n. 12
0
class TagSchema(BaseSchema):
    class Meta:
        model = Tag
        exclude = ('created_on', 'updated_on')

    id = ma.Integer()
    name = ma.String()
    store_id = ma.Integer()
    store = ma.Nested('StoreSchema',
                      many=False,
                      dump_only=True,
                      only=('id', 'name'))
Esempio n. 13
0
class DistributorSchema(BaseSchema):
    class Meta:
        model = Distributor
        exclude = ('created_on', 'updated_on')

    name = ma.String()
    phone_numbers = ma.List(ma.Integer())
    emails = ma.List(ma.Email())
    retail_shop_id = ma.Integer()

    retail_shop = ma.Nested('RetailShopSchema', many=False, dump_only=True, only=('id', 'name'))
    bills = ma.Nested('DistributorBillSchema', many=True, exclude=('distributor', 'distributor_id'))
Esempio n. 14
0
class ProductSaltSchema(BaseSchema):
    class Meta:
        model = ProductSalt
        exclude = ('created_on', 'updated_on', 'salt', 'store', 'product')

    salt_id = ma.Integer(load=True, required=True, allow_none=False)
    product_id = ma.Integer(load=True, required=True, allow_none=False)
    store_id = ma.Integer(dump_only=True)

    @post_load
    def save_data(self, obj):
        # index_product_salts(*[obj.id])
        return obj
Esempio n. 15
0
class RiderSchema(BaseSchema):
    class Meta:
        model = Rider
        #exclude = ('updated_on')

    id = ma.Integer(dump_only=True)
    email = ma.Email(required=False)
    first_name = ma.String(Load=True)
    last_name = ma.String(Load=True)
    mobile_number = ma.Integer(Load=True)
    device_limit = ma.Integer(Load=True)
    devices = ma.Nested('DeviceSchema',
                        many=False,
                        dump_only=True,
                        only=('id', 'name'))
Esempio n. 16
0
class UserSchema(BaseSchema):
    class Meta:
        model = User
        exclude = ('updated_on', 'my_payments', 'my_dues')

    id = ma.Integer(dump_only=True)
    email = ma.Email(required=False)
    # username = ma.String(required=True)
    first_name = ma.String(load=True)
    roles = ma.Nested('RoleSchema',
                      many=True,
                      dump_only=True,
                      only=('id', 'name'))
    fixed_dues = ma.Integer(dump_only=True)
    subscriptions = ma.Integer(dump_only=True)
Esempio n. 17
0
class CommentSchema(ma.SQLAlchemyAutoSchema):
    class Meta:
        model = Comments

    username = ma.String()
    post_id = ma.Integer()
    content = ma.String(required=True, validate=[Length(min=2, max=600)])
Esempio n. 18
0
class UserSchema(BaseSchema):
    class Meta:
        model = User

    id = ma.Integer(dump_only=True)
    # is_admin = ma.Boolean(dump_only=True)
    email = ma.Email(required=False)
Esempio n. 19
0
class SaltSchema(BaseSchema):
    class Meta:
        model = Salt
        exclude = ('created_on', 'updated_on')

    retail_shop_id = ma.Integer()
    retail_shop = ma.Nested('RetailShopSchema', many=False, dump_only=True, only=('id', 'name'))
Esempio n. 20
0
class SaltElasticSchema(BaseSchema):
    class Meta:
        model = Salt
        exclude = ('created_on', 'updated_on', 'store', 'products',
                   'prescription_required', 'store_id')

    id = ma.Integer()
Esempio n. 21
0
class AddressSchema(BaseSchema):
    class Meta:
        model = Address
        exclude = ('created_on', 'updated_on', '')

    locality_id = ma.Integer(load_only=True)
    locality = ma.Nested('LocalitySchema', many=False, load=True, exclude=('city_id',))
Esempio n. 22
0
class LocalitySchema(BaseSchema):
    class Meta:
        model = Locality
        exclude = ('created_on', 'updated_on')

    city_id = ma.Integer(load=True)
    city = ma.Nested('CitySchema', many=False, load=True)
Esempio n. 23
0
class IPinfoSchema(ma.ModelSchema):
    class Meta:
        model = ipinfo

    id = ma.Integer(dump_only=True)
    country_code = ma.String(required=True)
    country_name = ma.String(required=True)
    proxy_type = ma.String(required=True)
Esempio n. 24
0
class ProductElasticSchema(BaseSchema):
    class Meta:
        model = Product
        exclude = ('created_on', 'updated_on', 'store', 'last_selling_amount',
                   'last_purchase_amount', 'stock_required', 'is_short',
                   'distributors', '_links', 'stocks', 'min_stock', 'combos',
                   'add_ons')

    name = ma.String()
    short_code = ma.String()
    description = ma.List(ma.Dict(), allow_none=True)
    sub_description = ma.String(allow_none=True)
    brand_id = ma.Integer()
    brand = ma.Nested('BrandSchema', many=False, only=('name', ))
    salts = ma.Nested('SaltElasticSchema', many=True, only=('id', 'name'))
    taxes = ma.Nested('TaxSchema',
                      many=True,
                      dump_only=True,
                      only=('id', 'name', 'value'))
    is_disabled = ma.Boolean()
    store_id = ma.Integer()
    quantity_label = ma.String(dump_only=True, allow_none=True)
    default_quantity = ma.Float(precision=2, partila=True)
    packaging_form = ma.String(dump_only=True, allow_none=True)
    packaging_size = ma.String(dump_only=True, allow_none=True)
    is_loose = ma.Boolean(dump_only=True, allow_none=True)
    mrp = ma.Integer(dump_only=True)
    min_stock = ma.Float(dump_only=True)
    auto_discount = ma.Float(dump_only=True)
    available_stock = ma.Integer(dump_only=True)
    similar_products = ma.List(ma.Integer)
    product_salts = ma.Nested('ProductSaltSchema',
                              many=True,
                              only=('salt_id', 'unit', 'value'))
    barcode = ma.String(max_length=13,
                        min_length=8,
                        dump_onl=True,
                        allow_none=False)
    available_stocks = ma.Nested('StockSchema',
                                 many=True,
                                 dump_only=True,
                                 only=('purchase_amount', 'selling_amount',
                                       'units_purchased', 'batch_number',
                                       'units_sold', 'expiry_date',
                                       'purchase_date', 'id', 'default_stock'))
Esempio n. 25
0
class CustomerSchema(BaseSchema):
    class Meta:
        model = Customer
        exclude = ('updated_on', )

    mobile_number = ma.Integer()
    total_orders = ma.Integer(dump_only=True)
    total_billing = ma.Float(precison=2, dump_only=True)
    amount_due = ma.Float(precison=2, dump_only=True)
    addresses = ma.Nested('AddressSchema', many=True, load=False, partial=True)
    retail_brand_id = ma.UUID(load=True)
    retail_shop_id = ma.List(ma.UUID(), load=True)
    retail_brand = ma.Nested('RetailBrandSchema',
                             many=False,
                             only=('id', 'name'))
    transactions = ma.Nested('CustomerTransactionSchema',
                             many=True,
                             only=('id', 'amount', 'created_on'))
Esempio n. 26
0
class NotificationSchema(BaseSchema):
    class Meta:
        model = Notification
        fields = ('id', 'issuer', 'title', 'body')

    id = ma.Integer(dump_only=True)
    title = ma.String(required=True)
    body = ma.String(required=True)
    issuer = ma.Nested(UserSchema, many=False, only=('id', 'email'))
Esempio n. 27
0
class DistributorBillSchema(BaseSchema):
    class Meta:
        model = DistributorBill
        exclude = ('created_on', 'updated_on')

    purchase_date = ma.Date(load=True)
    distributor_id = ma.UUID(load=True)
    total_items = ma.Integer(dump_only=True)
    bill_amount = ma.Integer(dump_only=True)

    distributor = ma.Nested('DistributorSchema',
                            many=False,
                            only=('id', 'name', 'retail_shop'))
    purchased_items = ma.Nested('StockSchema',
                                many=True,
                                exclude=('distributor_bill', 'order_items',
                                         'product'),
                                load=True)
Esempio n. 28
0
class ItemSchema(BaseSchema):
    class Meta:
        model = Item
        exclude = ('created_on', 'updated_on')

    id = ma.Integer(dump_only=True)
    product_id = ma.Integer(load=False, dump_only=True)
    unit_price = ma.Float(precision=2)
    quantity = ma.Float(precision=2)
    order_id = ma.Integer()
    stock_id = ma.Integer()
    discount = ma.Float()
    discounted_total_price = ma.Float(dump_only=True)
    discounted_unit_price = ma.Float(dump_only=True)
    total_price = ma.Float(dump_only=True)
    discount_amount = ma.Float(dump_only=True)

    taxes = ma.Nested('ItemTaxSchema', many=True, exclude=('item', ))
Esempio n. 29
0
class SchoolSchema(ma.ModelSchema):
    class Meta:
        model = School
        exclude = ('created_on', 'updated_on', 'users')

    id = ma.Integer(dump_only=True)
    school_counsellors = ma.Nested('UserSchema',
                                   exclude=('school', ),
                                   many=True)
Esempio n. 30
0
class NotificationSchema(BaseSchema):
	class Meta:
		model = Notification
		fields = ('id', 'issuer', 'title', 'body', 'updated_on')

	id = ma.Integer(dump_only=True)
	title = ma.String(required=True)
	body = ma.String(required=True)
	updated_on = ma.DateTime(format='%Y-%m-%d %I:%M %p') # Using IST
	issuer = ma.Nested(UserSchema, many=False, only=('id', 'username'))