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)
class UserSchema(BaseSchema): class Meta: model = User exclude = ('updated_on', 'password') id = ma.UUID(dump_only=True) email = ma.Email(unique=True, primary_key=True, required=True) username = ma.String(required=True) name = ma.String(load=True) brand_ids = ma.List(ma.UUID, dump_only=True) retail_shop_ids = ma.List(ma.UUID, dump_only=True) retail_shops = ma.Nested('RetailShopSchema', many=True, dump_only=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, only=('id', 'name')) permissions = ma.Nested('PermissionSchema', many=True, dump_only=True, only=('id', 'name'))
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 RetailShopSchema(BaseSchema): class Meta: model = RetailShop exclude = ('created_on', 'updated_on', 'products', 'orders', 'users', 'brands', 'distributors', 'tags', 'taxes') _links = ma.Hyperlinks({ 'products': ma.URLFor('pos.product_view', __retail_shop_id__exact='<id>'), 'brands': ma.URLFor('pos.brand_view', __retail_shop_id__exact='<id>'), 'distributors': ma.URLFor('pos.distributor_view', __retail_shop_id__exact='<id>'), 'tags': ma.URLFor('pos.tag_view', __retail_shop_id__exact='<id>'), 'taxes': ma.URLFor('pos.tax_view', __retail_shop_id__exact='<id>') }) retail_brand_id = ma.UUID() retail_brand = ma.Nested('RetailBrandSchema', many=False) total_sales = ma.Dict() address = ma.Nested('AddressSchema', many=False) localities = ma.Nested('LocalitySchema', many=True) registration_details = ma.Nested('RegistrationDetailSchema', many=True) printer_config = ma.Nested('PrinterConfigSchema', load=True, many=False)
class UserDeviceSchema(BaseSchema): class Meta: model = UserDevice #exclude = ('created_on', 'updated_on') id = ma.UUID(Load=True) user_id = ma.UUID(Load=True) device_id = ma.UUID(Load=True) user = ma.Nested('UserSchema', many=False) device = ma.Nested('DeviceSchema', many=False)
class DeviceGroupSchema(BaseSchema): class Meta: model = DeviceGroup #exclude=('updated_on','created_on') id = ma.UUID(Load=True) group_id = ma.UUID(Load=True) device_id = ma.UUID(Load=True) group = ma.Nested('GroupSchema', many=False) device = ma.Nested('DeviceSchema', many=False)
class RiderDeviceScehma(BaseSchema): class Meta: model = RiderDevice #exclude = () id = ma.UUID(Load=True) rider_id = ma.UUID(Load=True) device_id = ma.UUID(Load=True) rider = ma.Nested('RiderSchema', many=False) device = ma.Nested('DeviceSchema', many=False)
class UserPermissionSchema(BaseSchema): class Meta: model = UserPermission exclude = ('created_on', 'updated_on') id = ma.UUID(load=True) user_id = ma.UUID(load=True) permission_id = ma.UUID(load=True) user = ma.Nested('UserSchema', many=False) permission = ma.Nested('PermissionSchema', many=False)
class UserRoleSchema(BaseSchema): class Meta: model = UserRole exclude = ('created_on', 'updated_on') id = ma.UUID(load=True) user_id = ma.UUID(load=True) role_id = ma.UUID(load=True) user = ma.Nested('UserSchema', many=False) role = ma.Nested('RoleSchema', many=False)
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)
class DistributorBillSchema(BaseSchema): class Meta: model = DistributorBill exclude = ('created_on', 'updated_on') purchase_date = ma.Date() distributor_id = ma.Integer() distributor = ma.Nested('DistributorSchema', many=False) purchased_items = ma.Nested('StockSchema', many=True, exclude=('distributor_bill', 'product_variation', 'order_items', 'distributor_bill_id'))
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'))
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) user_profile = ma.Nested('UserProfileSchema', load=True, many=False, exclude=('user',)) roles = ma.Nested('RoleSchema', many=True, dump_only=True)
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)
class StoreSchema(BaseSchema): class Meta: model = Store exclude = ('created_on', 'updated_on', 'products', 'orders', 'users', 'brands', 'distributors', 'tags', 'taxes') organisation_id = ma.UUID() retail_brand = ma.Nested('OrganisationSchema', many=False) total_sales = ma.Dict() address = ma.Nested('AddressSchema', many=False) localities = ma.Nested('LocalitySchema', many=True) registration_details = ma.Nested('RegistrationDetailSchema', many=True) printer_config = ma.Nested('PrinterConfigSchema', load=True, many=False)
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 ChatSchema(ma.ModelSchema): class Meta: model = Chat exclude = ('created_on', 'updated_on') id = ma.Integer(dump_only=True) sender = ma.Nested('UserSchema', only=('username', ), many=False, dump_only=True) receiver = ma.Nested('UserSchema', only=('username', ), many=False, dump_only=True)
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 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'))
class LocalitySchema(BaseSchema): class Meta: model = Locality exclude = ('created_on', 'updated_on') city_id = ma.UUID(load=True) city = ma.Nested('CitySchema', many=False, load=True)
class ScheduleStopSchema(ma.Schema): class Meta: fields = ('address', 'latitude', 'longitude', 'timestamp', 'rides') latitude = ma.Decimal(as_string=True) longitude = ma.Decimal(as_string=True) rides = ma.Nested(ScheduleStopRideSchema, many=True)
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',))
class RoleSchema(BaseSchema): class Meta: model = Role exclude = ('updated_on', 'created_on', 'users') id = ma.UUID() name = ma.String() level = ma.UUID(Load=True) permissions = ma.Nested('PermissionSchema', many=True, dump_only=True, only=('id', 'name')) users = ma.Nested('UserSchema', many=True, dump_only=True, only=('id', 'name'))
class OrderSchema(BaseSchema): class Meta: model = Order sub_total = ma.Float(precision=2) total = ma.Float(precision=2) store_id = ma.Integer(load=True, allow_none=True) customer_id = ma.Integer(load=True, required=False, allow_none=True) address_id = ma.Integer(load=True, required=False, partial=True, allow_none=True) discount_id = ma.Integer() items_count = ma.Integer(dump_only=True) amount_due = ma.Integer(dump_only=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, load=True, only=['id', 'name', 'number']) address = ma.Nested('AddressSchema', many=False, dump_only=True, only=['id', 'name']) discounts = ma.Nested('DiscountSchema', many=True, load=True) @pre_load() def save(self, data): if 'customer' in data and (data['customer']['name'] or data['customer']['number']): customer_id = Customer.query.with_entities(Customer.id)\ .filter(Customer.organisation_id == current_user.organisation_id, Customer.name == data['customer']['name'], Customer.number == data['customer']['number']).limit(1).scalar() if customer_id: data['customer_id'] = customer_id data.pop('customer')
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 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 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'))
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'))
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 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)