class ModelBase(object): created_on = db.Column(db.DateTime, default=db.func.now()) updated_on = db.Column(db.DateTime, default=db.func.now(), onupdate=db.func.now()) @declared_attr def __tablename__(self): return self.__name__.lower() def get_dict(self): return { item.key:self.__dict__[item.key] for item in self.__table__.columns.values() } def on_model_change(self, form, model, is_created=False): journal = Journal( table = self.__name__.lower(), field_name = '', new_value = '', ) # def my_before_commit(session): # import ipdb;ipdb.set_trace() # print "before commit!" # Session = sessionmaker() # event.listen(Session, "before_commit", my_before_commit)
class InvoiceType(ModelBase, db.Model): id = db.Column(db.Integer, primary_key=True) type = db.Column(db.String, nullable=False) description = db.Column(db.String, nullable=True) invoices = db.relationship( 'Invoice', backref='invoice_type' )
class ClientIdentifierType(ModelBase, db.Model): id = db.Column(db.Integer, primary_key=True) label = db.Column(db.String, nullable=False) description = db.Column(db.String, nullable=True) clients = db.relationship( "Client", backref='identifier_type', )
class ClientType(ModelBase, db.Model): id = db.Column(db.Integer, primary_key=True) label = db.Column(db.String, nullable=False) code = db.Column(db.String(5), index=True, nullable=False) description = db.Column(db.String, nullable=True) clients = db.relationship( 'Client', backref='type' )
class InvoiceStatus(ModelBase, db.Model): id = db.Column(db.Integer, primary_key=True) status = db.Column(db.String(100), nullable=False) status_code = db.Column(db.String(10), nullable=False) description = db.Column(db.String, nullable=True) invoices = db.relationship( 'Invoice', backref='invoice_status' )
class User(ModelBase, db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(32), index=True) password_hash = db.Column(db.String(128)) phone_number = db.Column(db.String, nullable=True) address = db.Column(db.String, nullable=True) name = db.Column(db.String, nullable=True) address = db.Column(db.String, nullable=True) birthday = db.Column(db.Date, nullable=True) def hash_password(self, password): self.password_hash = pwd_context.encrypt(password) def verify_password(self, password): return pwd_context.verify(password, self.password_hash) def generate_auth_token(self, expiration=600): s = Serializer(app.config['SECRET_KEY'], expires_in=expiration) return s.dumps({'id': self.id}) @staticmethod def verify_auth_token(token): s = Serializer(app.config['SECRET_KEY']) try: data = s.loads(token) except SignatureExpired: return None # valid token, but expired except BadSignature: return None # invalid token user = User.query.get(data['id']) return user
class InvoiceItem(ModelBase, db.Model): __tablename__ = 'invoice_item' id = db.Column(db.Integer, primary_key=True) amount = db.Column(db.Float, nullable=False) code = db.Column(db.String, index=True) description = db.Column(db.String, nullable=False) price = db.Column(db.Float, nullable=False) iva = db.Column(db.Float, nullable=False) total = db.Column(db.Float, nullable=False)
class Journal(db.Model): __tablename__ = 'journal' id = db.Column(db.Integer, primary_key=True) created_on = db.Column(db.DateTime, default=db.func.now()) updated_on = db.Column(db.DateTime, default=db.func.now(), onupdate=db.func.now()) table_name = db.Column(db.String, index=True, nullable=False) field_name = db.Column(db.String, index=True, nullable=False) new_value = db.Column(db.String, nullable=False)
class Client(ModelBase, db.Model): id = db.Column(db.Integer, primary_key=True) type_id = db.Column( db.Integer, db.ForeignKey('client_type.id'), index=True, nullable=False, ) name = db.Column(db.String, index=True, nullable=False) identifier = db.Column(db.String, index=True, nullable=False, unique=True) identifier_type_id = db.Column( db.Integer, db.ForeignKey('client_identifier_type.id'), index=True, nullable=False, ) contact = db.Column(db.String, nullable=True) address = db.Column(db.String, nullable=False) phone = db.Column(db.String, index=True, nullable=True)
class Invoice(ModelBase, db.Model): __tablename__ = 'billing' id = db.Column(db.Integer, primary_key=True) client_id = db.Column(db.Integer, db.ForeignKey('client.id'), nullable=False) client_name = db.Column(db.String, nullable=False) client_address = db.Column(db.String, nullable=False) client_identifier = db.Column(db.String, nullable=False) client_identifier_type = db.Column(db.String, db.ForeignKey('client_identifier_type.id'), nullable=False) ref_num = db.Column(db.String, index=True, nullable=False, unique=True) description = db.Column(db.String, nullable=False) discount = db.Column(db.Float, nullable=True, default=0) taxable_base = db.Column(db.Float, nullable=False, default=0) iva = db.Column(db.Float, nullable=False) iva_total = db.Column(db.Float, nullable=False) net = db.Column(db.Float, nullable=False) gross = db.Column(db.Float, nullable=False) total = db.Column(db.Float, nullable=False) paid = db.Column(db.Boolean, default=0) paid_date = db.Column(db.DateTime, default=None) status = db.Column(db.Integer, db.ForeignKey('invoice_status.id'), default=0) invoice_type_id = db.Column(db.Integer, db.ForeignKey('invoice_type.id')) def create_new_invoice(self, client_id): import ipdb;ipdb.set_trace()