|
|
@ -21,7 +21,7 @@ from ..models import ( |
|
|
|
get_session_factory, |
|
|
|
get_session_factory, |
|
|
|
get_tm_session, |
|
|
|
get_tm_session, |
|
|
|
) |
|
|
|
) |
|
|
|
from ..models import Category, Consumable, User, Role |
|
|
|
from ..models import Category, Consumable, Order, OrderStatus, User, Role |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def usage(argv): |
|
|
|
def usage(argv): |
|
|
@ -38,9 +38,9 @@ def read_exported_file(*paths): |
|
|
|
return items |
|
|
|
return items |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def parse_dt(value, default=None): |
|
|
|
def parse_dt(value, default=False): |
|
|
|
if value.startswith('0000'): |
|
|
|
if not value or value.startswith('0000'): |
|
|
|
return default or datetime.utcnow() |
|
|
|
return datetime.utcnow() if default is False else default |
|
|
|
return datetime.strptime(value + ' -0000', '%Y-%m-%d %H:%M:%S %z') |
|
|
|
return datetime.strptime(value + ' -0000', '%Y-%m-%d %H:%M:%S %z') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -102,3 +102,36 @@ def main(argv=sys.argv): |
|
|
|
) |
|
|
|
) |
|
|
|
dbsession.add(consumable) |
|
|
|
dbsession.add(consumable) |
|
|
|
dbsession.flush() |
|
|
|
dbsession.flush() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
order_list = read_exported_file(base_dir, 'export_orders.yml') |
|
|
|
|
|
|
|
for data in tqdm(order_list, desc='Orders'): |
|
|
|
|
|
|
|
work_status = data.get('work_status', 'approval') |
|
|
|
|
|
|
|
status = OrderStatus[work_status.upper()] |
|
|
|
|
|
|
|
category = Category[data['category'].upper()] |
|
|
|
|
|
|
|
date_created = parse_dt(data['date_created']) |
|
|
|
|
|
|
|
order = Order( |
|
|
|
|
|
|
|
id=data['id'], |
|
|
|
|
|
|
|
vendor=data['vendor'], |
|
|
|
|
|
|
|
catalog_nr=data['catalog_number'], |
|
|
|
|
|
|
|
cas_description=data['CAS_description'], |
|
|
|
|
|
|
|
package_size=data['package_size'], |
|
|
|
|
|
|
|
unit_price=data['price_unit'], |
|
|
|
|
|
|
|
amount=data['quantity'], |
|
|
|
|
|
|
|
total_price=data['price_total'], |
|
|
|
|
|
|
|
account=data['account'], |
|
|
|
|
|
|
|
currency=data['currency'], |
|
|
|
|
|
|
|
comment=data['comment'], |
|
|
|
|
|
|
|
created_date=date_created, |
|
|
|
|
|
|
|
created_by=data['username'], |
|
|
|
|
|
|
|
approval_date=parse_dt(data['date_modified'], None), |
|
|
|
|
|
|
|
approval_by='', |
|
|
|
|
|
|
|
ordered_date=parse_dt(data['date_ordered'], None), |
|
|
|
|
|
|
|
ordered_by='', |
|
|
|
|
|
|
|
completed_date=parse_dt(data['date_completed'], None), |
|
|
|
|
|
|
|
completed_by='', |
|
|
|
|
|
|
|
category=category, |
|
|
|
|
|
|
|
status=status |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
dbsession.add(order) |
|
|
|
|
|
|
|
dbsession.flush() |
|
|
|