|
|
|
@ -29,6 +29,56 @@ def get_multiple_orders(context, request):
@@ -29,6 +29,56 @@ def get_multiple_orders(context, request):
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_form_data_from_order(order): |
|
|
|
|
status = {"status": order.status.name} |
|
|
|
|
item = { |
|
|
|
|
"cas_description": order.cas_description, |
|
|
|
|
"category": order.category.name, |
|
|
|
|
"vendor": order.vendor, |
|
|
|
|
"catalog_nr": order.catalog_nr, |
|
|
|
|
"package_size": order.package_size, |
|
|
|
|
} |
|
|
|
|
pricing = { |
|
|
|
|
"unit_price": { |
|
|
|
|
"amount": "%.2f" % order.unit_price, |
|
|
|
|
"currency": order.currency, |
|
|
|
|
}, |
|
|
|
|
"quantity": order.amount, |
|
|
|
|
"total_price": { |
|
|
|
|
"amount": "%.2f" % order.total_price, |
|
|
|
|
"currency": order.currency, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
optional = {"account": order.account, "comment": order.comment} |
|
|
|
|
|
|
|
|
|
form_data = { |
|
|
|
|
"status": status, |
|
|
|
|
"item": item, |
|
|
|
|
"pricing": pricing, |
|
|
|
|
"optional": optional, |
|
|
|
|
} |
|
|
|
|
return form_data |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def update_order_with_form_data(order, form_data): |
|
|
|
|
form_item = form_data["item"] |
|
|
|
|
form_pricing = form_data["pricing"] |
|
|
|
|
form_optional = form_data["optional"] |
|
|
|
|
|
|
|
|
|
order.cas_description = form_item["cas_description"] |
|
|
|
|
order.category = models.OrderCategory[form_item["category"]] |
|
|
|
|
order.vendor = form_item["vendor"] |
|
|
|
|
order.catalog_nr = form_item["catalog_nr"] |
|
|
|
|
order.package_size = form_item["package_size"] |
|
|
|
|
|
|
|
|
|
order.unit_price = form_pricing["unit_price"]["amount"] |
|
|
|
|
order.currency = form_pricing["unit_price"]["currency"] |
|
|
|
|
order.amount = form_pricing["quantity"] |
|
|
|
|
|
|
|
|
|
order.account = form_optional["account"] |
|
|
|
|
order.comment = form_optional["comment"] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@view_config( |
|
|
|
|
context="ordr3:resources.OrderList", |
|
|
|
|
permission="view", |
|
|
|
@ -272,36 +322,14 @@ def view_order(context, request):
@@ -272,36 +322,14 @@ def view_order(context, request):
|
|
|
|
|
renderer="ordr3:templates/orders/edit.jinja2", |
|
|
|
|
) |
|
|
|
|
def edit_order(context, request): |
|
|
|
|
form = orders.EditOrderSchema.as_form(request) |
|
|
|
|
order = context.model |
|
|
|
|
status = {"status": order.status.name} |
|
|
|
|
item = { |
|
|
|
|
"cas_description": order.cas_description, |
|
|
|
|
"category": order.category.name, |
|
|
|
|
"vendor": order.vendor, |
|
|
|
|
"catalog_nr": order.catalog_nr, |
|
|
|
|
"package_size": order.package_size, |
|
|
|
|
} |
|
|
|
|
pricing = { |
|
|
|
|
"unit_price": { |
|
|
|
|
"amount": "%.2f" % order.unit_price, |
|
|
|
|
"currency": order.currency, |
|
|
|
|
}, |
|
|
|
|
"quantity": order.amount, |
|
|
|
|
"total_price": { |
|
|
|
|
"amount": "%.2f" % order.total_price, |
|
|
|
|
"currency": order.currency, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
optional = {"account": order.account, "comment": order.comment} |
|
|
|
|
autocorrect_url = request.resource_url(context.__parent__, "vendor") |
|
|
|
|
form = orders.EditOrderSchema.as_form( |
|
|
|
|
request, autocorrect_url=autocorrect_url |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
form_data = { |
|
|
|
|
"status": status, |
|
|
|
|
"item": item, |
|
|
|
|
"pricing": pricing, |
|
|
|
|
"optional": optional, |
|
|
|
|
} |
|
|
|
|
form_data = get_form_data_from_order(context.model) |
|
|
|
|
form.set_appstruct(form_data) |
|
|
|
|
|
|
|
|
|
return {"form": form} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -314,9 +342,10 @@ def edit_order(context, request):
@@ -314,9 +342,10 @@ def edit_order(context, request):
|
|
|
|
|
) |
|
|
|
|
def do_edit_order(context, request): |
|
|
|
|
""" process the edit order form """ |
|
|
|
|
print(request.POST) |
|
|
|
|
|
|
|
|
|
form = orders.EditOrderSchema.as_form(request) |
|
|
|
|
autocorrect_url = request.resource_url(context.__parent__, "vendor") |
|
|
|
|
form = orders.EditOrderSchema.as_form( |
|
|
|
|
request, autocorrect_url=autocorrect_url |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
if "Save_Changes" not in request.POST: |
|
|
|
|
return HTTPFound(request.resource_url(context.__parent__)) |
|
|
|
@ -330,25 +359,10 @@ def do_edit_order(context, request):
@@ -330,25 +359,10 @@ def do_edit_order(context, request):
|
|
|
|
|
|
|
|
|
|
# form validation sucessful, change order |
|
|
|
|
order = context.model |
|
|
|
|
form_status = appstruct["status"] |
|
|
|
|
form_item = appstruct["item"] |
|
|
|
|
form_pricing = appstruct["pricing"] |
|
|
|
|
form_optional = appstruct["optional"] |
|
|
|
|
|
|
|
|
|
order.cas_description = form_item["cas_description"] |
|
|
|
|
order.category = models.OrderCategory[form_item["category"]] |
|
|
|
|
order.vendor = form_item["vendor"] |
|
|
|
|
order.catalog_nr = form_item["catalog_nr"] |
|
|
|
|
order.package_size = form_item["package_size"] |
|
|
|
|
|
|
|
|
|
order.unit_price = form_pricing["unit_price"]["amount"] |
|
|
|
|
order.currency = form_pricing["unit_price"]["currency"] |
|
|
|
|
order.amount = form_pricing["quantity"] |
|
|
|
|
|
|
|
|
|
order.account = form_optional["account"] |
|
|
|
|
order.comment = form_optional["comment"] |
|
|
|
|
update_order_with_form_data(order, appstruct) |
|
|
|
|
form_status_section = appstruct["status"] |
|
|
|
|
|
|
|
|
|
status = models.OrderStatus[form_status["status"]] |
|
|
|
|
status = models.OrderStatus[form_status_section["status"]] |
|
|
|
|
is_noteworthy = services.create_log_entry(order, status, request.user) |
|
|
|
|
|
|
|
|
|
if is_noteworthy: |
|
|
|
@ -364,6 +378,67 @@ def do_edit_order(context, request):
@@ -364,6 +378,67 @@ def do_edit_order(context, request):
|
|
|
|
|
return HTTPFound(request.resource_url(context.__parent__)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@view_config( |
|
|
|
|
context="ordr3:resources.Order", |
|
|
|
|
name="reorder", |
|
|
|
|
permission="reorder", |
|
|
|
|
request_method="GET", |
|
|
|
|
renderer="ordr3:templates/orders/reorder.jinja2", |
|
|
|
|
) |
|
|
|
|
def reorder(context, request): |
|
|
|
|
autocorrect_url = request.resource_url(context.__parent__, "vendor") |
|
|
|
|
form = orders.AddOrderSchema.as_form( |
|
|
|
|
request, autocorrect_url=autocorrect_url |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
form_data = get_form_data_from_order(context.model) |
|
|
|
|
form.set_appstruct(form_data) |
|
|
|
|
|
|
|
|
|
return {"form": form} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@view_config( |
|
|
|
|
context="ordr3:resources.Order", |
|
|
|
|
name="reorder", |
|
|
|
|
permission="reorder", |
|
|
|
|
request_method="POST", |
|
|
|
|
renderer="ordr3:templates/orders/reorder.jinja2", |
|
|
|
|
) |
|
|
|
|
def place_reorder(context, request): |
|
|
|
|
""" process the reorder form """ |
|
|
|
|
autocorrect_url = request.resource_url(context.__parent__, "vendor") |
|
|
|
|
form = orders.AddOrderSchema.as_form( |
|
|
|
|
request, autocorrect_url=autocorrect_url |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
if "Place_Order" not in request.POST: |
|
|
|
|
return HTTPFound(request.resource_url(context.__parent__)) |
|
|
|
|
|
|
|
|
|
data = request.POST.items() |
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
appstruct = form.validate(data) |
|
|
|
|
except deform.ValidationFailure: |
|
|
|
|
return {"form": form} |
|
|
|
|
|
|
|
|
|
# form validation sucessful, change order |
|
|
|
|
default = [None] * 8 |
|
|
|
|
order = models.OrderItem(*default) |
|
|
|
|
update_order_with_form_data(order, appstruct) |
|
|
|
|
|
|
|
|
|
services.create_log_entry(order, models.OrderStatus.OPEN, request.user) |
|
|
|
|
|
|
|
|
|
request.repo.add_order(order) |
|
|
|
|
|
|
|
|
|
request.emit( |
|
|
|
|
events.FlashMessage.info( |
|
|
|
|
f"The order {order.cas_description} has been placed." |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
return HTTPFound(request.resource_url(context.__parent__)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@view_config( |
|
|
|
|
context="ordr3:resources.Order", |
|
|
|
|
name="delete", |
|
|
|
|