Browse Source

added order model

php2python
Holger Frey 7 years ago
parent
commit
f6f609957c
  1. 2
      ordr2/models/__init__.py
  2. 47
      ordr2/models/orders.py

2
ordr2/models/__init__.py

@ -6,7 +6,7 @@ import zope.sqlalchemy @@ -6,7 +6,7 @@ import zope.sqlalchemy
# import or define all models here to ensure they are attached to the
# Base.metadata prior to any initialization routines
from .user import User, Role # flake8: noqa
from .orders import Category, Consumable
from .orders import Category, Consumable, Order, OrderStatus
# run configure_mappers after defining all of the models to ensure
# all relationships can be setup

47
ordr2/models/orders.py

@ -24,6 +24,14 @@ class Category(enum.Enum): @@ -24,6 +24,14 @@ class Category(enum.Enum):
BIOLAB = 'biolab'
class OrderStatus(enum.Enum):
''' status of the order '''
OPEN = 'open'
APPROVAL = 'approval'
ORDERED = 'ordered'
COMPLETED = 'completed'
class Consumable(Base):
''' A consumable '''
@ -31,7 +39,7 @@ class Consumable(Base): @@ -31,7 +39,7 @@ class Consumable(Base):
id = Column(Integer, primary_key=True)
cas_description = Column(Text, nullable=False, unique=True)
cas_description = Column(Text, nullable=False)
category = Column(Enum(Category), nullable=False)
catalog_nr = Column(Text, nullable=False)
vendor = Column(Text, nullable=False)
@ -51,3 +59,40 @@ class Consumable(Base): @@ -51,3 +59,40 @@ class Consumable(Base):
''' string representation '''
return '{!s} ({!s})'.format(self.cas_description, self.vendor)
class Order(Base):
''' An order '''
__tablename__ = 'orders'
id = Column(Integer, primary_key=True)
status = Column(Enum(OrderStatus), nullable=False)
cas_description = Column(Text, nullable=False)
category = Column(Enum(Category), nullable=False)
catalog_nr = Column(Text, nullable=False)
vendor = Column(Text, nullable=False)
package_size = Column(Text, nullable=False)
unit_price = Column(Float, nullable=False)
currency = Column(Text, nullable=False, default='EUR')
amount = Column(Integer, nullable=False)
total_price = Column(Float, nullable=False)
account = Column(Text, nullable=False, default='')
comment = Column(Text, nullable=False, default='')
created_date = Column(Date, nullable=False, default=datetime.utcnow)
created_by = Column(Text, nullable=False)
approval_date = Column(Date, nullable=True)
approval_by = Column(Text, nullable=False, default='')
ordered_date = Column(Date, nullable=True)
ordered_by = Column(Text, nullable=False, default='')
completed_date = Column(Date, nullable=True)
completed_by = Column(Text, nullable=False, default='')
def __str__(self):
''' string representation '''
return '{!s} ({!s})'.format(self.cas_description, self.vendor)