class User(db.Model): __tablename__ = 'users' url = db.Column(db.String(), nullable=False, primary_key=True) first_name = db.Column(db.String()) last_name = db.Column(db.String()) email = db.Column(db.String()) role = db.Column(db.String()) permission_level = db.Column(db.Integer()) opening_mileage = db.Column( db.Numeric(precision=10, scale=2) ) # returns a decimal.Decimal object to prevent rounding errors. Pass asdecimal=False to this constructor if you want to just get floats out. created_at = db.Column(db.DateTime()) updated_at = db.Column(db.DateTime()) def __init__(self, created_at=datetime.now(), updated_at=datetime.now(), **kwargs): """Mostly rely on default declarative SQLAlchemy constructor. Additionally set the timestamps on object creation.""" super( User, self).__init__(**kwargs) # use the default declarative constructor self.created_at = created_at self.updated_at = updated_at def __repr__(self): return '<url {}>'.format(self.url)
class BankTransaction(db.Model): __tablename__ = 'bank_transactions' url = db.Column(db.String(), nullable=False, primary_key=True) bank_account = db.Column(db.String(), nullable=False) amount = db.Column(db.Numeric(precision=10, scale=2)) dated_on = db.Column(db.Date()) description = db.Column(db.String()) full_description = db.Column(db.String()) is_manual = db.Column(db.Boolean()) unexplained_amount = db.Column(db.Numeric(precision=10, scale=2)) uploaded_at = db.Column(db.Date()) created_at = db.Column(db.DateTime()) updated_at = db.Column(db.DateTime()) def __init__(self, created_at=datetime.now(), updated_at=datetime.now(), **kwargs): """Mostly rely on default declarative SQLAlchemy constructor. Additionally set the timestamps on object creation.""" super( BankTransaction, self).__init__(**kwargs) # use the default declarative constructor self.created_at = created_at self.updated_at = updated_at def __repr__(self): return '<url {}>'.format(self.url)
class BankAccount(db.Model): __tablename__ = 'bank_accounts' url = db.Column('url', db.String(length=255), autoincrement=False, nullable=False, primary_key=True) account_number = db.Column('account_number', db.String(length=255), autoincrement=False, nullable=True) bank_code = db.Column('bank_code', db.String(length=25), autoincrement=False, nullable=True) bank_name = db.Column('bank_name', db.String(length=255), autoincrement=False, nullable=True) bic = db.Column('bic', db.String(length=255), autoincrement=False, nullable=True) latest_activity_date = db.Column('latest_activity_date', db.DATE(), autoincrement=False, nullable=True) currency = db.Column('currency', db.String(length=255), autoincrement=False, nullable=True) current_balance = db.Column('current_balance', db.NUMERIC(precision=10, scale=2), autoincrement=False, nullable=True) iban = db.Column('iban', db.String(length=255), autoincrement=False, nullable=True) is_personal = db.Column('is_personal', db.BOOLEAN(), autoincrement=False, nullable=True) is_primary = db.Column('is_primary', db.BOOLEAN(), autoincrement=False, nullable=True) name = db.Column('name', db.String(length=255), autoincrement=False, nullable=True) opening_balance = db.Column('opening_balance', db.NUMERIC(precision=10, scale=2), autoincrement=False, nullable=True) sort_code = db.Column('sort_code', db.String(length=255), autoincrement=False, nullable=True) type = db.Column('type', db.String(length=255), autoincrement=False, nullable=True) created_at = db.Column('created_at', db.DateTime(), nullable=True) updated_at = db.Column('updated_at', db.DateTime(), nullable=True) def __init__(self, created_at=datetime.now(), updated_at=datetime.now(), **kwargs): """Mostly rely on default declarative SQLAlchemy constructor. Additionally set the timestamps on object creation.""" super(BankAccount, self).__init__(**kwargs) # use the default declarative constructor self.created_at = created_at self.updated_at = updated_at def __repr__(self): return '<url {}>'.format(self.url)
class User(db.Model): """ User Model for storing user related details """ __tablename__ = "users" id = db.Column(db.Integer, primary_key=True, autoincrement=True) username = db.Column(db.String(255), unique=True, nullable=False) password = db.Column(db.String(255), nullable=False) registered_on = db.Column(db.DateTime, nullable=False) admin = db.Column(db.Boolean, nullable=False, default=False) def __init__(self, username, password, admin=False): self.username = username self.password = bcrypt.generate_password_hash( password, current_app.config.get('BCRYPT_LOG_ROUNDS')).decode() self.registered_on = datetime.datetime.now() self.admin = admin def encode_auth_token(self, user_id): """ Generates the Auth Token :return: string """ try: payload = { 'exp': datetime.datetime.utcnow() + datetime.timedelta(days=1, seconds=0), 'iat': datetime.datetime.utcnow(), 'sub': user_id } return jwt.encode(payload, current_app.config.get('SECRET_KEY'), algorithm='HS256') except Exception as e: return e @staticmethod def decode_auth_token(auth_token): """ Validates the auth token :param auth_token: :return: integer|string """ try: payload = jwt.decode(auth_token, current_app.config.get('SECRET_KEY')) is_blacklisted_token = BlacklistToken.check_blacklist(auth_token) if is_blacklisted_token: return 'Token blacklisted. Please log in again.' else: return payload['sub'] except jwt.ExpiredSignatureError: return 'Signature expired. Please log in again.' except jwt.InvalidTokenError: return 'Invalid token. Please log in again.'
class Site(db.Model): __tablename__ = 'site' id = db.APIColumn(db.Integer, primary_key=True, methods=['GET']) chapter_id = db.APIColumn(db.Integer) title = db.APIColumn(db.String(32)) latitude = db.APIColumn(db.String(32)) longitude = db.APIColumn(db.String(32)) events = db.relationship('Event', back_populates='site')
class BankTransactionExplanation(db.Model): __tablename__ = 'bank_transaction_explanations' url = db.Column(db.String(), nullable=False, primary_key=True) bank_transaction = db.Column(db.String(), nullable=False) bank_account = db.Column(db.String(), nullable=False) category = db.Column(db.String()) dated_on = db.Column(db.Date()) description = db.Column(db.String()) gross_value = db.Column(db.Numeric(precision=10, scale=2)) paid_bill = db.Column(db.String()) paid_invoice = db.Column(db.String()) paid_user = db.Column(db.String()) receipt_reference = db.Column(db.String()) sales_tax_rate = db.Column(db.Numeric(precision=10, scale=2)) created_at = db.Column(db.DateTime()) updated_at = db.Column(db.DateTime()) def __init__(self, created_at=datetime.now(), updated_at=datetime.now(), **kwargs): """Mostly rely on default declarative SQLAlchemy constructor. Additionally set the timestamps on object creation.""" super(BankTransactionExplanation, self).__init__(**kwargs) # use the default declarative constructor self.created_at = created_at self.updated_at = updated_at def __repr__(self): return '<url {}>'.format(self.url)
class ServerCost(db.Model): __tablename__ = 'server_costs' project_url = db.Column(db.String(), sa.ForeignKey('projects.url'), nullable=False, primary_key=True) value = db.Column( db.Numeric(precision=10, scale=2), nullable=True ) # returns a decimal.Decimal object to prevent rounding errors. Pass asdecimal=False to this constructor if you want to just get floats out. created_at = db.Column(db.DateTime()) updated_at = db.Column(db.DateTime()) def __init__(self, created_at=datetime.now(), updated_at=datetime.now(), **kwargs): """Mostly rely on default declarative SQLAlchemy constructor. Additionally set the timestamps on object creation.""" super( ServerCost, self).__init__(**kwargs) # use the default declarative constructor self.created_at = created_at self.updated_at = updated_at def __repr__(self): return '<project url {0} value {1}>'.format(self.url, self.value)
class BlacklistToken(db.Model): """ Token Model for storing JWT tokens """ __tablename__ = 'blacklist_tokens' id = db.Column(db.Integer, primary_key=True, autoincrement=True) token = db.Column(db.String(500), unique=True, nullable=False) blacklisted_on = db.Column(db.DateTime, nullable=False) def __init__(self, token): self.token = token self.blacklisted_on = datetime.datetime.now() def __repr__(self): return '<id: token: {}'.format(self.token) @staticmethod def check_blacklist(auth_token): # check whether auth token has been blacklisted res = BlacklistToken.query.filter_by(token=str(auth_token)).first() if res: return True else: return False
class Project(db.Model): __tablename__ = 'projects' url = db.Column(db.String(), nullable=False, primary_key=True) name = db.Column(db.String()) contact = db.Column(db.String()) budget = db.Column(db.Integer()) is_ir35 = db.Column(db.Boolean()) status = db.Column(db.String()) budget_units = db.Column(db.String()) normal_billing_rate = db.Column(db.Numeric(precision=10, scale=2)) hours_per_day = db.Column(db.Numeric(precision=10, scale=2)) uses_project_invoice_sequence = db.Column(db.Boolean()) currency = db.Column(db.String()) billing_period = db.Column(db.String()) created_at = db.Column(db.DateTime()) updated_at = db.Column(db.DateTime()) def __init__(self, created_at=datetime.now(), updated_at=datetime.now(), **kwargs): """Mostly rely on default declarative SQLAlchemy constructor. Additionally set the timestamps on object creation.""" super(Project, self).__init__(**kwargs) # use the default declarative constructor self.created_at = created_at self.updated_at = updated_at def __repr__(self): return '<url {}>'.format(self.url)
class Bill(db.Model): __tablename__ = 'bills' url = db.Column(db.String(), nullable=False, primary_key=True) category = db.Column(db.String(), nullable=False) project = db.Column(db.String()) comments = db.Column(db.String()) contact = db.Column(db.String()) dated_on = db.Column(db.Date()) due_on = db.Column(db.Date()) due_value = db.Column(db.Numeric(precision=10, scale=2)) paid_value = db.Column(db.Numeric(precision=10, scale=2)) reference = db.Column(db.String()) sales_tax_rate = db.Column(db.Numeric(precision=10, scale=2)) sales_tax_value = db.Column(db.Numeric(precision=10, scale=2)) status = db.Column(db.String()) total_value = db.Column(db.Numeric(precision=10, scale=2)) created_at = db.Column(db.DateTime()) updated_at = db.Column(db.DateTime()) def __init__(self, created_at=datetime.now(), updated_at=datetime.now(), **kwargs): """Mostly rely on default declarative SQLAlchemy constructor. Additionally set the timestamps on object creation.""" super( Bill, self).__init__(**kwargs) # use the default declarative constructor self.created_at = created_at self.updated_at = updated_at def __repr__(self): return '<url {}>'.format(self.url)
class Expense(db.Model): __tablename__ = 'expenses' url = db.Column(db.String(), nullable=False, primary_key=True) category = db.Column(db.String()) currency = db.Column(db.String()) dated_on = db.Column(db.Date()) description = db.Column(db.String()) gross_value = db.Column(db.Numeric(precision=10, scale=2)) manual_sales_tax_amount = db.Column(db.Numeric(precision=10, scale=2)) native_gross_value = db.Column(db.Numeric(precision=10, scale=2)) native_sales_tax_value = db.Column(db.Numeric(precision=10, scale=2)) project = db.Column(db.String()) receipt_reference = db.Column(db.String()) sales_tax_rate = db.Column(db.Numeric(precision=10, scale=2)) sales_tax_value = db.Column(db.Numeric(precision=10, scale=2)) user = db.Column(db.String()) rebill_factor = db.Column(db.Numeric(precision=10, scale=2)) created_at = db.Column(db.DateTime()) updated_at = db.Column(db.DateTime()) def __init__(self, created_at=datetime.now(), updated_at=datetime.now(), **kwargs): """Mostly rely on default declarative SQLAlchemy constructor. Additionally set the timestamps on object creation.""" super(Expense, self).__init__(**kwargs) # use the default declarative constructor self.created_at = created_at self.updated_at = updated_at def __repr__(self): return '<url {}>'.format(self.url)
class Event(db.Model): __tablename__ = 'event' id = db.APIColumn(db.Integer, primary_key=True, methods=['GET']) site_id = db.APIColumn(db.Integer, db.ForeignKey('site.id')) chapter_id = db.APIColumn(db.Integer) title = db.APIColumn(db.String(32)) start_time = db.APIColumn(db.DateTime(timezone=True)) end_time = db.APIColumn(db.DateTime(timezone=True)) site = db.relationship('Site', back_populates='events')
class Category(db.Model): __tablename__ = 'categories' url = db.Column(db.String(255), nullable=False, primary_key=True) allowable_for_tax = db.Column(db.Boolean()) auto_sales_tax_rate = db.Column(db.String(255)) description = db.Column(db.String(255)) group_description = db.Column(db.String(255)) nominal_code = db.Column(db.String(255)) tax_reporting_name = db.Column(db.String(255)) created_at = db.Column(db.DateTime()) updated_at = db.Column(db.DateTime()) def __init__(self, created_at=datetime.now(), updated_at=datetime.now(), **kwargs): """Mostly rely on default declarative SQLAlchemy constructor. Additionally set the timestamps on object creation.""" super( Category, self).__init__(**kwargs) # use the default declarative constructor self.created_at = created_at self.updated_at = updated_at def __repr__(self): return '<url {}>'.format(self.url)
class Contact(db.Model): __tablename__ = 'contacts' url = db.Column(db.String(), nullable=False, primary_key=True) account_balance = db.Column(db.Numeric(precision=10, scale=2)) address1 = db.Column(db.String()) address2 = db.Column(db.String()) address3 = db.Column(db.String()) billing_email = db.Column(db.String()) charge_sales_tax = db.Column(db.String()) contact_name_on_invoices = db.Column(db.Boolean()) country = db.Column(db.String()) email = db.Column(db.String()) first_name = db.Column(db.String()) is_deletable = db.Column(db.Boolean()) last_name = db.Column(db.String()) locale = db.Column(db.String()) mobile = db.Column(db.String()) phone_number = db.Column(db.String()) organisation_name = db.Column(db.String()) postcode = db.Column(db.String()) region = db.Column(db.String()) status = db.Column(db.String()) sales_tax_registration_number = db.Column(db.String()) town = db.Column(db.String()) uses_contact_invoice_sequence = db.Column(db.Boolean()) active_projects_count = db.Column(db.Integer()) created_at = db.Column(db.DateTime()) updated_at = db.Column(db.DateTime()) def __init__(self, created_at=datetime.now(), updated_at=datetime.now(), **kwargs): """Mostly rely on default declarative SQLAlchemy constructor. Additionally set the timestamps on object creation.""" super(Contact, self).__init__(**kwargs) # use the default declarative constructor self.created_at = created_at self.updated_at = updated_at def __repr__(self): return '<url {}>'.format(self.url)
class Invoice(db.Model): __tablename__ = 'invoices' url = db.Column(db.String(), nullable=False, primary_key=True) always_show_bic_and_iban = db.Column(db.Boolean()) comments = db.Column(db.String()) contact = db.Column(db.String()) currency = db.Column(db.String()) dated_on = db.Column(db.Date()) discount_percent = db.Column(db.Numeric(precision=10, scale=2)) due_on = db.Column(db.Date()) due_value = db.Column(db.Numeric(precision=10, scale=2)) exchange_rate = db.Column(db.Numeric(precision=10, scale=2)) involves_sales_tax = db.Column(db.Boolean()) is_interim_uk_vat = db.Column(db.Boolean()) net_value = db.Column(db.Numeric(precision=10, scale=2)) omit_header = db.Column(db.Boolean()) paid_on = db.Column(db.Date()) paid_value = db.Column(db.Numeric(precision=10, scale=2)) payment_terms_in_days = db.Column(db.Integer()) po_reference = db.Column(db.String()) project = db.Column(db.String()) reference = db.Column(db.String()) sales_tax_value = db.Column(db.Numeric(precision=10, scale=2)) show_project_name = db.Column(db.Boolean()) status = db.Column(db.String()) total_value = db.Column(db.Numeric(precision=10, scale=2)) written_off_date = db.Column(db.Date()) send_reminder_emails = db.Column(db.Boolean()) send_thank_you_emails = db.Column(db.Boolean()) send_new_invoice_emails = db.Column(db.Boolean()) include_timeslips = db.Column(db.String()) recurring_invoice = db.Column(db.String()) billed_grouped_by_single_timeslip = db.Column(db.Boolean()) bank_account = db.Column(db.String()) client_contact_name = db.Column(db.String()) created_at = db.Column(db.DateTime()) updated_at = db.Column(db.DateTime()) def __init__(self, created_at=datetime.now(), updated_at=datetime.now(), **kwargs): """Mostly rely on default declarative SQLAlchemy constructor. Additionally set the timestamps on object creation.""" super( Invoice, self).__init__(**kwargs) # use the default declarative constructor self.created_at = created_at self.updated_at = updated_at def __repr__(self): return '<url {}>'.format(self.url)