Improve UI, customization hooks for new custorder batch
still not done yet, but a savepoint
This commit is contained in:
parent
4d742bacb1
commit
c2ea1be83f
3 changed files with 49 additions and 10 deletions
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2020 Lance Edgar
|
||||
# Copyright © 2010-2021 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -52,6 +52,8 @@ class CustomerOrderBatchView(BatchMasterView):
|
|||
'total_price',
|
||||
'created',
|
||||
'created_by',
|
||||
'executed',
|
||||
'executed_by',
|
||||
]
|
||||
|
||||
form_fields = [
|
||||
|
|
|
@ -32,7 +32,7 @@ import six
|
|||
from sqlalchemy import orm
|
||||
|
||||
from rattail import pod
|
||||
from rattail.db import api, model
|
||||
from rattail.db import model
|
||||
from rattail.util import pretty_quantity
|
||||
from rattail.batch import get_batch_handler
|
||||
|
||||
|
@ -263,7 +263,8 @@ class CustomerOrderView(MasterView):
|
|||
if not upc:
|
||||
return {'error': "Must specify a product UPC"}
|
||||
|
||||
product = api.get_product_by_upc(self.Session(), upc)
|
||||
product = self.handler.locate_product_for_entry(
|
||||
self.Session(), upc, product_key='upc')
|
||||
if not product:
|
||||
return {'error': "Product not found"}
|
||||
|
||||
|
@ -299,14 +300,15 @@ class CustomerOrderView(MasterView):
|
|||
|
||||
# Case
|
||||
case_text = None
|
||||
if product.case_size is None:
|
||||
case_size = self.handler.get_case_size_for_product(product)
|
||||
if case_size is None:
|
||||
case_text = "{} (× ?? {})".format(
|
||||
self.enum.UNIT_OF_MEASURE[self.enum.UNIT_OF_MEASURE_CASE],
|
||||
unit_name)
|
||||
elif product.case_size > 1:
|
||||
elif case_size > 1:
|
||||
case_text = "{} (× {} {})".format(
|
||||
self.enum.UNIT_OF_MEASURE[self.enum.UNIT_OF_MEASURE_CASE],
|
||||
pretty_quantity(product.case_size),
|
||||
pretty_quantity(case_size),
|
||||
unit_name)
|
||||
if case_text:
|
||||
choices.append({'key': self.enum.UNIT_OF_MEASURE_CASE,
|
||||
|
@ -334,6 +336,9 @@ class CustomerOrderView(MasterView):
|
|||
}
|
||||
|
||||
def normalize_row(self, row):
|
||||
product = row.product
|
||||
department = product.department if product else None
|
||||
cost = product.cost if product else None
|
||||
data = {
|
||||
'uuid': row.uuid,
|
||||
'sequence': row.sequence,
|
||||
|
@ -344,7 +349,7 @@ class CustomerOrderView(MasterView):
|
|||
'product_brand': row.product_brand,
|
||||
'product_description': row.product_description,
|
||||
'product_size': row.product_size,
|
||||
'product_full_description': row.product.full_description if row.product else row.product_description,
|
||||
'product_full_description': product.full_description if product else row.product_description,
|
||||
'product_weighed': row.product_weighed,
|
||||
|
||||
'case_quantity': pretty_quantity(row.case_quantity),
|
||||
|
@ -352,7 +357,10 @@ class CustomerOrderView(MasterView):
|
|||
'units_ordered': pretty_quantity(row.units_ordered),
|
||||
'order_quantity': pretty_quantity(row.order_quantity),
|
||||
'order_uom': row.order_uom,
|
||||
'order_uom_choices': self.uom_choices_for_product(row.product),
|
||||
'order_uom_choices': self.uom_choices_for_product(product),
|
||||
|
||||
'department_display': department.name if department else None,
|
||||
'vendor_display': cost.vendor.name if cost else None,
|
||||
|
||||
'unit_price': six.text_type(row.unit_price) if row.unit_price is not None else None,
|
||||
'unit_price_display': "${:0.2f}".format(row.unit_price) if row.unit_price is not None else None,
|
||||
|
@ -468,7 +476,7 @@ class CustomerOrderView(MasterView):
|
|||
'batch': self.normalize_batch(batch)}
|
||||
|
||||
def submit_new_order(self, batch, data):
|
||||
result = self.handler.do_execute(batch, self.request.user)
|
||||
result = self.execute_new_order_batch(batch, data)
|
||||
if not result:
|
||||
return {'error': "Batch failed to execute"}
|
||||
|
||||
|
@ -478,6 +486,9 @@ class CustomerOrderView(MasterView):
|
|||
|
||||
return {'ok': True, 'next_url': next_url}
|
||||
|
||||
def execute_new_order_batch(self, batch, data):
|
||||
return self.handler.do_execute(batch, self.request.user)
|
||||
|
||||
# TODO: deprecate / remove this
|
||||
CustomerOrdersView = CustomerOrderView
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue