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)
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)])
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'))
class UserSchema(ma.SQLAlchemyAutoSchema): class Meta: model = User load_only = ["password"] email = ma.String(required=True, validate=Length(min=4)) password = ma.String(required=True, validate=Length(min=6))
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)
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'))
class LoggedInUserSchema(ma.SQLAlchemyAutoSchema): class Meta: model = User load_only = ["password"] email = ma.String(required=True, validate=[Length(min=4), Email()]) username = ma.String(required=True, validate=[Length(min=1)]) f_name = ma.String(required=True, validate=[Length(min=2)]) l_name = ma.String(required=True, validate=[Length(min=2)]) password = ma.String(required=True, validate=Length(min=6))
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'))
class UserSchema(BaseSchema): class Meta: model = User exclude = ('updated_on', 'confirmed_at') #fields = ('id', 'email', 'username') id = ma.Integer(dump_only=True) email = ma.Email(required=False) mobile_number = ma.String(required=True) username = ma.String(required=True) roles = ma.Nested('RoleSchema', many=True, dump_only=True, only=('id', 'name'))
class ProfileSchema(ma.SQLAlchemyAutoSchema): class Meta: model = Profile username = ma.String(required=True, validate=Length(min=1)) fname = ma.String(required=True, validate=Length(min=1)) lname = ma.String(required=True, validate=Length(min=1)) account_active = ma.Boolean(required=True) employer = ma.Boolean(required=True) contractor = ma.Boolean(required=True) user = ma.Nested(UserSchema)
class UserSchema(ma.SQLAlchemyAutoSchema): class Meta: model = User load_only = [ "f_name", "l_name", "email", "state", "post_code", "address", "country", "password" ] email = ma.String(required=True, validate=[Length(min=4), Email()]) username = ma.String(required=True, validate=[Length(min=1)]) f_name = ma.String(required=True, validate=[Length(min=2)]) l_name = ma.String(required=True, validate=[Length(min=2)]) password = ma.String(required=True, validate=Length(min=6))
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'))
class OrderDiscountSchema(BaseSchema): class Meta: model = OrderDiscount exclude = ('created_on', 'updated_on') name = ma.String() amount = ma.Float(precision=2)
class UserSchema(ma.SQLAlchemyAutoSchema): class Meta: model = User load_only = [ "first_name", "last_name", "email", "password" ] load_instance = True email = ma.String(required=True, validate=[Length(min=4), Email()]) username = ma.String(required=True, validate=[Length(min=1)]) first_name = ma.String(required=True, validate=[Length(min=2)]) last_name = ma.String(required=True, validate=[Length(min=2)]) password = ma.String(required=True, validate=Length(min=6))
class StatusSchema(BaseSchema): class Meta: model = Status exclude = ('created_on', 'updated_on') name = ma.String() amount = ma.Float(precision=2)
class MessageSchema(ma.SQLAlchemyAutoSchema): class Meta: model = Message message = ma.String(required=True, validate=Length(min=1)) message_sent = ma.Int(required=True, validate=Length(min=1)) contract = ma.Nested(ContractSchema)
class ItemAddOnSchema(BaseSchema): class Meta: model = ItemAddOn exclude = ('created_on', 'updated_on') name = ma.String() amount = ma.Float(precision=2)
class RoleSchema(BaseSchema): class Meta: model = Role fields = ('name',) name = ma.String()
class RoleSchema(BaseSchema): class Meta: model = Role exclude = ('updated_on', 'created_on', 'users') id = ma.UUID() name = ma.String() permissions = ma.Nested('PermissionSchema', many=True, dump_only=True, only=('id', 'name'))
class TaxSchema(BaseSchema): class Meta: model = Tax exclude = ('created_on', 'updated_on') name = ma.String() value = ma.Float(precision=2) retail_shop = ma.Nested('RetailShopSchema', many=False, dump_only=True, only=('id', 'name'))
class BrandSchema(BaseSchema): class Meta: model = Brand exclude = ('created_on', 'updated_on') name = ma.String() retail_shop_id = ma.Integer() retail_shop = ma.Nested('RetailShopSchema', many=False, dump_only=True, only=('id', 'name'))
class UserSchema(BaseSchema): class Meta: model = User exclude = ('created_on', 'updated_on', 'password', 'current_login_at', 'current_login_ip', 'last_login_at', 'last_login_ip', 'login_count', 'confirmed_at') id = ma.Integer(dump_only=True) email = ma.Email(unique=True, primary_key=True, required=True) username = ma.String(required=True) name = ma.String(dump_only=True) brand_ids = ma.List(ma.Integer) retail_shop_ids = ma.List(ma.Integer) retail_shops = ma.Nested('RetailShopSchema', many=True) _links = ma.Hyperlinks({'shops': ma.URLFor('pos.retail_shop_view', __id__in='<retail_shop_ids>')}) roles = ma.Nested('RoleSchema', many=True, dump_only=True)
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
class UserProfileSchema(BaseSchema): class Meta: model = UserProfile exclude = ('created_on', 'updated_on') id = ma.Integer(load=True) first_name = ma.String(load=True) user = ma.Nested('UserSchema', load=False)
class EngagementSchema(ma.SQLAlchemyAutoSchema): class Meta: model = Engagement title = ma.String(required=True, validate=Length(min=1)) capacity_in_days = ma.Int(required=True, validate=Length(min=1)) hours_of_work = ma.Int(required=True, validate=Length(min=1)) start_date = ma.DateTime(required=True) end_date = ma.DateTime(required=True) contract = ma.Nested(ContractSchema)
class AddressSchema(BaseSchema): class Meta: model = Address exclude = ('created_on', 'updated_on', 'locality') name = ma.String(load=True, required=True) locality_id = ma.UUID(load_only=True) locality = ma.Nested('LocalitySchema', many=False, load=False, exclude=('city_id', ))
class UserSchema(ma.ModelSchema): class Meta: model = User exclude = ('created_on', 'updated_on', 'password', 'current_login_at', 'current_login_ip', 'last_login_at', 'last_login_ip', 'login_count') id = ma.Integer(dump_only=True) email = ma.Email() user_profile = ma.Nested('UserProfileSchema', many=False) authentication_token = ma.String()
class GroupSchema(BaseSchema): class Meta: model = Group exclude = ('updated_on', 'created_on') id = ma.Integer(dump_only=True) name = ma.String(Load=True) devices = ma.Nested('DeviceSchema', unique=True, dump_only=True, only=('id', 'name'))
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'))