Ejemplo n.º 1
0
class Name(db.Model):
    __tablename__ = 'names'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(1024), index=True)
    state = db.Column(db.String(15), default='NE')  # NE=Not Examined; R=Rejected; A=Accepted; C=Cond. Accepted
    choice = db.Column(db.Integer)
    designation = db.Column(db.String(50), default=None)
    consumptionDate = db.Column('consumption_date', db.DateTime(timezone=True))
    corpNum = db.Column('corp_num', db.String(10), default=None)
    remoteNameId = db.Column('remote_name_id', db.BigInteger)

    # Decision info
    conflict1 = db.Column(db.String(250), default='')  # optional conflict name
    conflict2 = db.Column(db.String(250), default='')  # optional conflict name
    conflict3 = db.Column(db.String(250), default='')  # optional conflict name
    conflict1_num = db.Column(db.String(250), default='')  # optional conflict name - corp or NR number
    conflict2_num = db.Column(db.String(250), default='')  # optional conflict name - corp or NR number
    conflict3_num = db.Column(db.String(250), default='')  # optional conflict name - corp or NR number
    decision_text = db.Column(db.String(1000), default='')

    nrId = db.Column('nr_id', db.Integer, db.ForeignKey('requests.id'), index=True)
    commentId = db.Column('comment_id', db.Integer, db.ForeignKey('comments.id'))
    # nameRequest = db.relationship('Request')

    # if a comment is added during decision, link it to the name record to be sent back to NRO
    comment = db.relationship("Comment", backref=backref("related_name", uselist=False), foreign_keys=[commentId])

    # Required for name request name analysis
    _name_type_cd = db.Column('name_type_cd', db.String(10))

    NOT_EXAMINED = 'NE'
    APPROVED = 'APPROVED'
    REJECTED = 'REJECTED'
    CONDITION = 'CONDITION'
    # Needed for name request reservation before completing the nr
    RESERVED = 'RESERVED'
    COND_RESERVE = 'COND-RESERVE'

    # Properties added for Name Request
    @property
    def name_type_cd(self):
        """Property containing the name type which is used by name Request."""
        return self._name_type_cd

    @name_type_cd.setter
    def name_type_cd(self, value: str):
        self._name_type_cd = value

    def as_dict(self):
        return {
            'id': self.id,
            'name': self.name,
            'name_type_cd': self.name_type_cd,
            'designation': self.designation,
            'choice': self.choice,
            'state': self.state,
            'conflict1': self.conflict1,
            'conflict2': self.conflict2,
            'conflict3': self.conflict3,
            'conflict1_num': self.conflict1_num,
            'conflict2_num': self.conflict2_num,
            'conflict3_num': self.conflict3_num,
            'decision_text': self.decision_text,
            'consumptionDate': self.consumptionDate.isoformat() if self.consumptionDate else None,
            'corpNum': self.corpNum,
            'comment': None if self.comment is None else self.comment.as_dict()
        }

    @classmethod
    def find_by_name(cls, name):
        return cls.query.filter_by(name=name).first()

    def save_to_db(self):
        # force uppercase names
        self.name = self.name.upper()

        db.session.add(self)
        db.session.commit()
    
    def add_to_db(self):
        db.session.add(self)

    def delete_from_db(self):
        db.session.delete(self)
        db.session.commit()
Ejemplo n.º 2
0
class Payment(db.Model):
    __tablename__ = 'payments'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)

    _payment_token = db.Column('payment_id', db.String(4096))
    _payment_completion_date = db.Column('payment_completion_date',
                                         db.DateTime(timezone=True))
    _payment_status_code = db.Column('payment_status_code', db.String(50))
    payment_note = db.Column('payment_note', db.String(100))
    payment_action = db.Column('payment_action', db.String(50))
    furnished = db.Column('furnished', db.Boolean, default=False)

    nrId = db.Column('nr_id',
                     db.Integer,
                     db.ForeignKey('requests.id'),
                     index=True)

    # properties
    @property
    def payment_token(self):
        """Property containing the payment token."""
        return self._payment_token

    @payment_token.setter
    def payment_token(self, token: str):
        self._payment_token = token

    @property
    def payment_completion_date(self):
        """Property containing the date the payment cleared."""
        return self._payment_completion_date

    @payment_completion_date.setter
    def payment_completion_date(self, date):
        """Property containing the date the payment cleared."""
        self._payment_completion_date = date

    @property
    def payment_status_code(self):
        """Property containing the payment token."""
        return self._payment_status_code

    @payment_status_code.setter
    def payment_status_code(self, str):
        self._payment_status_code = str

    def as_dict(self):
        return {
            'id': self.id,
            'nr_id': self.nrId,
            'payment_token': self.payment_token,
            'payment_note': self.payment_note,
            'payment_completion_date': self.payment_completion_date,
            'payment_status_code': self.payment_status_code,
            'payment_action': self.payment_action,
            'receipt_sent': self.furnished
        }

    def save_to_db(self):
        db.session.add(self)
        db.session.commit()

    def delete_from_db(self):
        pass
Ejemplo n.º 3
0
class Payment(db.Model):

    class PaymentActions(Enum):
        """Valid actions for a payment."""
        CREATE='CREATE'
        UPGRADE='UPGRADE'
        REAPPLY='REAPPLY'

    __tablename__ = 'payments'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)

    _payment_token = db.Column('payment_id', db.String(4096))
    _payment_completion_date = db.Column('payment_completion_date', db.DateTime(timezone=True))
    _payment_status_code = db.Column('payment_status_code', db.String(50))
    payment_note = db.Column('payment_note', db.String(100))
    payment_action = db.Column('payment_action', db.String(50))
    furnished = db.Column('furnished',db.Boolean, default=False)


    nrId = db.Column('nr_id', db.Integer, db.ForeignKey('requests.id'), index=True)

    # properties
    @property
    def payment_token(self):
        """Property containing the payment token."""
        return self._payment_token

    @payment_token.setter
    def payment_token(self, token: str):
        self._payment_token = token

    @property
    def payment_completion_date(self):
        """Property containing the date the payment cleared."""
        return self._payment_completion_date

    @payment_completion_date.setter
    def payment_completion_date(self, date):
        """Property containing the date the payment cleared."""
        self._payment_completion_date = date

    @property
    def payment_status_code(self):
        """Property containing the payment token."""
        return self._payment_status_code

    @payment_status_code.setter
    def payment_status_code(self, str):
        self._payment_status_code = str

    @classmethod
    def find_by_payment_token(cls, token: str):
        return cls.query.filter_by(_payment_token=str(token)).one_or_none()


    def as_dict(self):
        return {
            'id': self.id,
            'nr_id': self.nrId,
            'payment_token': self.payment_token,
            'payment_note': self.payment_note,
            'payment_completion_date': self.payment_completion_date,
            'payment_status_code': self.payment_status_code,
            'payment_action': self.payment_action,
            'receipt_sent': self.furnished
        }

    def save_to_db(self):
        db.session.add(self)
        db.session.commit()

    def delete_from_db(self):
        pass