class Payments(BaseMixin, db.Model): __tablename__ = 'paymentss' payment_type_id = db.Column(db.Integer, db.ForeignKey('payment_types.id'), nullable=False) amount = db.Column(db.Numeric, nullable=False) currency = db.Column(db.String(3), nullable=False) transaction_number = db.Column(db.String(30), nullable=True) # job = relationship("Jobs", uselist=False, back_populates="payment") def __repr__(self): return '<Payment %r>' % self.id #TODO delete def add(self, db_connection, payment): result = None try: db_connection.session.begin(subtransactions=True) db_connection.session.add(payment) db_connection.session.commit() logger.info('Add new payment. Payment id: %s', payment.id) params = {"payment": payment} result = True, params except: db_connection.session.rollback() result = db_error_message(logger) return result
class Question(db.Model, BaseMixin): __tablename__ = 'question' id = db.Column(db.Integer, primary_key=True) question = db.Column(db.String(500), nullable=False) factor = db.Column(db.Integer, nullable=True) def __init__(self, question): self.question = question def __repr__(self): return '<Question %r>' % self.id
class QuestionSet(BaseMixin, db.Model): __tablename__ = 'question_sets' id = db.Column(db.Integer, primary_key=True) label = db.Column(db.String(64)) questions = association_proxy('question_to_question_set', 'question') # questionservice_grade_type = db.relationship("ServiceGradeType") def __repr__(self): return '<QuestionSet %r>' % self.id def __init__(self, label): self.label = label
class PaymentType(BaseMixin, db.Model): __tablename__ = 'payment_types' name = db.Column(db.String(200), nullable=False) payments = db.relationship( "Payment", backref="payments_list", lazy='dynamic', primaryjoin=lambda: PaymentType.id == Payment.payment_type_id) def __repr__(self): return '<PaymentType %r>' % self.id @staticmethod def find_payment_type_by_id(type_id): try: result = True, PaymentType.query.filter( PaymentType.id == type_id).first() except: result = db_error_message(logger) return result
class Status(BaseMixin, db.Model): __tablename__ = 'statuses' name = db.Column(db.String(200), nullable=False) jobs = db.relationship("Job", backref="job_backref", lazy='dynamic', primaryjoin="Status.id == Job.status_id") def __repr__(self): return '<Status %r>' % self.id @staticmethod def find_status(status_name): result = True, try: status = Status.query.filter(Status.name == status_name).first() result = True, status except: result = False, db_error_message(global_logger) return result @staticmethod def load_not_payable_statues_ids(): try: names = [ Keys.STATUS_PENDING, Keys.STATUS_CANCELLED_BY_BUSINESS_OWNER, Keys.STATUS_DENIED_BY_BUSINESS_OWNER, Keys.STATUS_CANCELLED_BY_CAR_OWNER, Keys.STATUS_TIMEOUT ] tuple_ids = Status.query.filter( Status.name.in_(names)).with_entities(Status.id).all() ids = [r for (r, ) in tuple_ids] return True, ids except: return False, db_error_message(logger) @staticmethod def load_status(status_name): return Status.find_status(status_name)