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.
132 lines
3.9 KiB
132 lines
3.9 KiB
''' Consumables, Categories, Orders and Order Status Database Models ''' |
|
|
|
import bcrypt |
|
import enum |
|
import uuid |
|
|
|
from collections import namedtuple |
|
from datetime import datetime |
|
from sqlalchemy import ( |
|
Column, |
|
DateTime, |
|
Enum, |
|
Float, |
|
Integer, |
|
Text, |
|
) |
|
|
|
from .meta import Base |
|
|
|
|
|
class Category(enum.Enum): |
|
''' Categories of consumables and orders ''' |
|
CHEMICAL = 'chemical' |
|
DISPOSABLE = 'disposable' |
|
SOLVENT = 'solvent' |
|
BIOLAB = 'biolab' |
|
|
|
|
|
class OrderStatus(enum.Enum): |
|
''' status of the order ''' |
|
OPEN = 'open' |
|
APPROVAL = 'approval' |
|
ORDERED = 'ordered' |
|
COMPLETED = 'completed' |
|
|
|
|
|
class Consumable(Base): |
|
''' A consumable ''' |
|
|
|
__tablename__ = 'consumables' |
|
|
|
id = Column(Integer, primary_key=True) |
|
|
|
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') |
|
comment = Column(Text, nullable=False, default='') |
|
date_created = Column(DateTime, nullable=False, default=datetime.utcnow) |
|
date_modified = Column( |
|
DateTime, |
|
nullable=False, |
|
default=datetime.utcnow, |
|
onupdate=datetime.utcnow |
|
) |
|
|
|
def __str__(self): |
|
''' 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(DateTime, nullable=False, default=datetime.utcnow) |
|
created_by = Column(Text, nullable=False) |
|
approval_date = Column(DateTime, nullable=True) |
|
approval_by = Column(Text, nullable=False, default='') |
|
ordered_date = Column(DateTime, nullable=True) |
|
ordered_by = Column(Text, nullable=False, default='') |
|
completed_date = Column(DateTime, nullable=True) |
|
completed_by = Column(Text, nullable=False, default='') |
|
|
|
|
|
def __str__(self): |
|
''' string representation ''' |
|
return '{!s} ({!s})'.format(self.cas_description, self.vendor) |
|
|
|
|
|
def _date_info(self, some_date, some_one): |
|
''' string representaton of date and user ''' |
|
if not some_date: |
|
# no date, no string |
|
return '' |
|
if some_one: |
|
# in the new system a status change also stores the purchaser |
|
return '{!s} by {!s}'.format(some_date, some_one) |
|
# historical data does not have a purchaser associated with a date |
|
return '{!s}'.format(some_date) |
|
|
|
@property |
|
def placed(self): |
|
''' string representation for placed on / by ''' |
|
return self._date_info(self.created_date, self.created_by) |
|
|
|
@property |
|
def approved(self): |
|
''' string representation for approval on / by ''' |
|
return self._date_info(self.approval_date, self.approval_by) |
|
|
|
@property |
|
def ordered(self): |
|
''' string representation for ordered on / by ''' |
|
return self._date_info(self.ordered_date, self.ordered_by) |
|
|
|
@property |
|
def completed(self): |
|
''' string representation for completed on / by ''' |
|
return self._date_info(self.completed_date, self.completed_by)
|
|
|