예제 #1
0
class ProductTagSchema(BaseSchema):
    class Meta:
        model = ProductTag
        exclude = ('created_on', 'updated_on')

    tag_id = ma.UUID(load=True)
    product_id = ma.UUID(load=True)
예제 #2
0
class CustomerAddressSchema(BaseSchema):
    class Meta:
        model = CustomerAddress
        exclude = ('created_on', 'updated_on')

    address_id = ma.UUID(load=True, partial=False)
    customer_id = ma.UUID(load=True, partial=False)
예제 #3
0
class BrandDistributorSchema(BaseSchema):
    class Meta:
        model = BrandDistributor
        exclude = ('created_on', 'updated_on')

    brand_id = ma.UUID(load=True)
    distributor_id = ma.UUID(load=True)
예제 #4
0
class ProductSaltSchema(BaseSchema):
    class Meta:
        model = ProductSalt
        exclude = ('created_on', 'updated_on')

    salt_id = ma.UUID(load=True)
    product_id = ma.UUID(load=True)
예제 #5
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)
예제 #6
0
class UserStoreSchema(BaseSchema):
    class Meta:
        model = UserStore
        exclude = ('created_on', 'updated_on')

    user_id = ma.UUID(load=True, allow_none=False)
    store_id = ma.UUID(load=True, allow_none=False)
예제 #7
0
class UserRetailShopSchema(BaseSchema):
    class Meta:
        model = UserRetailShop
        exclude = ('created_on', 'updated_on')

    user_id = ma.UUID(load=True, allow_none=False)
    retail_shop_id = ma.UUID(load=True, allow_none=False)
예제 #8
0
class ProductTaxSchema(BaseSchema):
    class Meta:
        model = ProductTax
        exclude = ('created_on', 'updated_on')
        fields = ('tax_id', 'product_id')

    tax_id = ma.UUID(load=True)
    product_id = ma.UUID(load=True)
예제 #9
0
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)
예제 #10
0
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)
예제 #11
0
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)
예제 #12
0
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)
예제 #13
0
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)
예제 #14
0
class ItemTaxSchema(BaseSchema):
    class Meta:
        model = ItemTax
        exclude = ('created_on', 'updated_on')

    tax_value = ma.Float(precision=2)

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

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

    id = ma.UUID()
    name = ma.String()
    retail_shop_id = ma.UUID()
    retail_shop = ma.Nested('RetailShopSchema',
                            many=False,
                            dump_only=True,
                            only=('id', 'name'))
예제 #16
0
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'))
예제 #17
0
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'))
예제 #18
0
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)
예제 #19
0
class PrinterConfigSchema(BaseSchema):
    class Meta:
        model = PrinterConfig
        exclude = ('created_on', 'updated_on')

    retail_shop_id = ma.UUID(load=True, allow_none=False)
    have_bill_printer = ma.Boolean(load=True)
예제 #20
0
class CustomerTransactionSchema(BaseSchema):
    class Meta:
        model = CustomerTransaction
        exclude = ('updated_on', )

    amount = ma.Float(precision=2, load=True)
    customer_id = ma.UUID(load=True, partial=False, allow_none=False)
예제 #21
0
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)
예제 #22
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'))
예제 #23
0
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', ))
예제 #24
0
class TaxSchema(BaseSchema):
    class Meta:
        model = Tax
        exclude = ('created_on', 'updated_on')

    name = ma.String(load=True)
    value = ma.Float(precision=2, load=True)
    retail_shop_id = ma.UUID(load=True)
    retail_shop = ma.Nested('RetailShopSchema',
                            many=False,
                            dump_only=True,
                            only=('id', 'name'))
예제 #25
0
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)
예제 #26
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
예제 #27
0
class DistributorSchema(BaseSchema):
    class Meta:
        model = Distributor
        exclude = ('created_on', 'updated_on')

    id = ma.UUID()
    name = ma.String()
    phone_numbers = ma.List(ma.Integer())
    emails = ma.List(ma.Email())
    retail_shop_id = ma.UUID()
    products = ma.Nested('ProductSchema',
                         many=True,
                         dump_only=True,
                         only=('id', 'name', 'last_selling_amount', 'barcode',
                               'last_purchase_amount', 'stock_required',
                               'quantity_label'))

    retail_shop = ma.Nested('RetailShopSchema',
                            many=False,
                            dump_only=True,
                            only=('id', 'name'))
    bills = ma.Nested('DistributorBillSchema',
                      many=True,
                      exclude=('distributor', 'distributor_id'))
예제 #28
0
class ItemSchema(BaseSchema):
    class Meta:
        model = Item
        exclude = ('created_on', 'updated_on')

    product_id = ma.UUID(load=True, required=True)
    unit_price = ma.Float(precision=2)
    quantity = ma.Float(precision=2)
    order_id = ma.UUID()
    stock_id = ma.UUID()
    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)
    children = ma.Nested('self',
                         many=True,
                         default=None,
                         load=True,
                         exclude=('parent', ))
    product = ma.Nested('ProductSchema', many=False, only=('id', 'name'))
    combo = ma.Nested('ComboSchema', many=False, only=('id', 'name'))
    taxes = ma.Nested('ItemTaxSchema', many=True, exclude=('item', ))
    add_ons = ma.Nested('AddOnSchema', many=True, exclude=('item', ))
예제 #29
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)
예제 #30
0
class BrandSchema(BaseSchema):
    class Meta:
        model = Brand
        exclude = ('created_on', 'updated_on')

    name = ma.String()
    retail_shop_id = ma.UUID()
    retail_shop = ma.Nested('RetailShopSchema',
                            many=False,
                            dump_only=True,
                            only=('id', 'name'))
    distributors = ma.Nested('DistributorSchema',
                             many=True,
                             dump_only=True,
                             only=('id', 'name'))
    products = ma.Nested('ProductSchema',
                         many=True,
                         dump_only=True,
                         only=('id', 'name'))