|
|
|
@ -21,7 +21,7 @@ from ..models import (
@@ -21,7 +21,7 @@ from ..models import (
|
|
|
|
|
get_session_factory, |
|
|
|
|
get_tm_session, |
|
|
|
|
) |
|
|
|
|
from ..models import Category, Consumable, User, Role |
|
|
|
|
from ..models import Category, Consumable, Order, OrderStatus, User, Role |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def usage(argv): |
|
|
|
@ -38,9 +38,9 @@ def read_exported_file(*paths):
@@ -38,9 +38,9 @@ def read_exported_file(*paths):
|
|
|
|
|
return items |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def parse_dt(value, default=None): |
|
|
|
|
if value.startswith('0000'): |
|
|
|
|
return default or datetime.utcnow() |
|
|
|
|
def parse_dt(value, default=False): |
|
|
|
|
if not value or value.startswith('0000'): |
|
|
|
|
return datetime.utcnow() if default is False else default |
|
|
|
|
return datetime.strptime(value + ' -0000', '%Y-%m-%d %H:%M:%S %z') |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -101,4 +101,37 @@ def main(argv=sys.argv):
@@ -101,4 +101,37 @@ def main(argv=sys.argv):
|
|
|
|
|
category=category |
|
|
|
|
) |
|
|
|
|
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() |
|
|
|
|