You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
4.2 KiB
85 lines
4.2 KiB
from datetime import datetime
|
|
from minibase.app import db
|
|
|
|
|
|
class Companies(db.Model):
|
|
__tablename__ = 'companies'
|
|
id = db.Column(db.Integer, nullable=False, primary_key=True)
|
|
name = db.Column(db.String(100), nullable=False)
|
|
main_company = db.Column(db.Integer, nullable=False, default='1')
|
|
subsidiary_of = db.Column(db.Integer, nullable=True, default='')
|
|
website = db.Column(db.String(100), nullable=True, default='')
|
|
street = db.Column(db.String(100), nullable=False)
|
|
street_no = db.Column(db.Integer, nullable=False)
|
|
city = db.Column(db.String(100), nullable=False)
|
|
post_code = db.Column(db.Integer, nullable=False)
|
|
state = db.Column(db.String(100), nullable=False)
|
|
classification = db.Column(db.Integer, nullable=False, default=0)
|
|
comment = db.Column(db.String(300), nullable=True)
|
|
image_file = db.Column(db.String(20), nullable=False, default='default_company.jpg')
|
|
upload_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
|
|
last_update_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow, onupdate=datetime.utcnow)
|
|
|
|
# One To Many relationships where indexes can point o mutiple companies.
|
|
# Example : One Legal_entity could cocern multiple companies. (There are surely more than just one GmBH)
|
|
country_id = db.Column(db.Integer, db.ForeignKey('country.id'), nullable=True)
|
|
legal_entity_id = db.Column(db.Integer, db.ForeignKey('company_legal_entity.id'), nullable=True)
|
|
type_id = db.Column(db.Integer, db.ForeignKey('company_types.id'), nullable=True)
|
|
industry_id = db.Column(db.Integer, db.ForeignKey('industry.id'), nullable=True)
|
|
status_id = db.Column(db.Integer, db.ForeignKey('company_status.id'), nullable=True)
|
|
|
|
# One To Many relationships for a company having mutliple elements of the following indexes
|
|
# Example : One company would/could have many eployees
|
|
employees = db.relationship('Person', backref='employer', lazy=True)
|
|
projects = db.relationship('Project', backref='belongs_to', lazy=True)
|
|
elements = db.relationship('Project_element', backref='company_ship_to', viewonly=True, lazy=True)
|
|
notes = db.relationship('Company_note', backref='company', lazy=True)
|
|
products = db.relationship('Product', backref='manufacturer', lazy=True)
|
|
|
|
# returns a more information-rich, or official, string representation of an object
|
|
# >>> company.query.all()
|
|
# [1, ComanyName, CompanyCounntry] (Do not change this presentation
|
|
# it will corrupt: the getCompanyId function in minibase.dabase.utils
|
|
def __repr__(self):
|
|
return f"{self.name}, {self.country_bill}, {self.id}"
|
|
|
|
|
|
class Company_types(db.Model):
|
|
__tablename__ = 'company_types'
|
|
id = db.Column(db.Integer, nullable=False, primary_key=True)
|
|
name = db.Column(db.String(50), nullable=False)
|
|
description = db.Column(db.String(300), nullable=False)
|
|
companies = db.relationship('Companies', backref='type', lazy=True)
|
|
|
|
# returns a more information-rich, or official, string representation of an object
|
|
def __repr__(self):
|
|
return f"{self.name}"
|
|
|
|
|
|
class Company_legal_entity(db.Model):
|
|
id = db.Column(db.Integer, nullable=False, primary_key=True)
|
|
name = db.Column(db.String(50), nullable=False)
|
|
description = db.Column(db.String(300), nullable=False)
|
|
companies = db.relationship('Company', backref='legal_entiy', lazy=True)
|
|
|
|
# returns a more information-rich, or official, string representation of an object
|
|
def __repr__(self):
|
|
return f"{self.name}"
|
|
|
|
|
|
class Company_note(db.Model):
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
priority = db.Column(db.Integer, nullable=False, default='0')
|
|
title = db.Column(db.String(100), nullable=False)
|
|
content = db.Column(db.Text, nullable=False)
|
|
date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
|
|
date_due = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
|
|
|
|
company_id = db.Column(db.Integer, db.ForeignKey('company.id'), nullable=False)
|
|
status_id = db.Column(db.Integer, db.ForeignKey('note_status.id'), nullable=False)
|
|
|
|
# returns a more information-rich, or official, string representation of an object
|
|
def __repr__(self):
|
|
return f"{self.title}, {self.content}"
|
|
|