2020-08-02 15:27:10 -05:00
|
|
|
# -*- coding: utf-8; -*-
|
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# Rattail -- Retail Software Framework
|
2023-02-12 09:34:38 -06:00
|
|
|
# Copyright © 2010-2023 Lance Edgar
|
2020-08-02 15:27:10 -05:00
|
|
|
#
|
|
|
|
# This file is part of Rattail.
|
|
|
|
#
|
|
|
|
# Rattail is free software: you can redistribute it and/or modify it under the
|
|
|
|
# terms of the GNU General Public License as published by the Free Software
|
|
|
|
# Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
# version.
|
|
|
|
#
|
|
|
|
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
# details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along with
|
|
|
|
# Rattail. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
"""
|
|
|
|
Base class for customer order batch views
|
|
|
|
"""
|
|
|
|
|
|
|
|
from rattail.db import model
|
|
|
|
|
2020-08-02 20:59:16 -05:00
|
|
|
import colander
|
2021-10-06 17:22:29 -05:00
|
|
|
from webhelpers2.html import tags
|
2020-08-02 20:59:16 -05:00
|
|
|
|
|
|
|
from tailbone import forms
|
2020-08-02 15:27:10 -05:00
|
|
|
from tailbone.views.batch import BatchMasterView
|
|
|
|
|
|
|
|
|
|
|
|
class CustomerOrderBatchView(BatchMasterView):
|
|
|
|
"""
|
|
|
|
Master view base class, for customer order batches. The views for the
|
|
|
|
various mode/workflow batches will derive from this.
|
|
|
|
"""
|
|
|
|
model_class = model.CustomerOrderBatch
|
|
|
|
model_row_class = model.CustomerOrderBatchRow
|
|
|
|
default_handler_spec = 'rattail.batch.custorder:CustomerOrderBatchHandler'
|
2020-08-02 20:59:16 -05:00
|
|
|
|
|
|
|
grid_columns = [
|
|
|
|
'id',
|
2021-10-07 11:33:52 -05:00
|
|
|
'contact_name',
|
2021-01-26 20:10:05 -06:00
|
|
|
'rowcount',
|
|
|
|
'total_price',
|
2020-08-02 20:59:16 -05:00
|
|
|
'created',
|
|
|
|
'created_by',
|
2021-08-29 16:38:30 -05:00
|
|
|
'executed',
|
|
|
|
'executed_by',
|
2020-08-02 20:59:16 -05:00
|
|
|
]
|
|
|
|
|
|
|
|
form_fields = [
|
|
|
|
'id',
|
2021-09-25 17:55:53 -05:00
|
|
|
'store',
|
2020-08-02 20:59:16 -05:00
|
|
|
'customer',
|
|
|
|
'person',
|
2021-10-06 17:22:29 -05:00
|
|
|
'pending_customer',
|
2021-10-17 16:28:28 -05:00
|
|
|
'contact_name',
|
2020-08-02 20:59:16 -05:00
|
|
|
'phone_number',
|
|
|
|
'email_address',
|
2021-10-06 13:49:13 -05:00
|
|
|
'params',
|
2020-08-02 20:59:16 -05:00
|
|
|
'created',
|
|
|
|
'created_by',
|
2021-01-26 20:10:05 -06:00
|
|
|
'rowcount',
|
|
|
|
'total_price',
|
|
|
|
]
|
|
|
|
|
|
|
|
row_labels = {
|
|
|
|
'product_brand': "Brand",
|
|
|
|
'product_description': "Description",
|
|
|
|
'product_size': "Size",
|
|
|
|
'order_uom': "Order UOM",
|
|
|
|
}
|
|
|
|
|
|
|
|
row_grid_columns = [
|
|
|
|
'sequence',
|
2021-12-22 12:06:00 -06:00
|
|
|
'_product_key_',
|
2021-01-26 20:10:05 -06:00
|
|
|
'product_brand',
|
|
|
|
'product_description',
|
|
|
|
'product_size',
|
|
|
|
'order_quantity',
|
|
|
|
'order_uom',
|
2021-09-21 13:49:51 -05:00
|
|
|
'case_quantity',
|
2021-01-26 20:10:05 -06:00
|
|
|
'total_price',
|
2020-08-02 20:59:16 -05:00
|
|
|
'status_code',
|
|
|
|
]
|
|
|
|
|
2021-12-22 12:06:00 -06:00
|
|
|
product_key_fields = {
|
|
|
|
'upc': 'product_upc',
|
|
|
|
'item_id': 'product_item_id',
|
|
|
|
'scancode': 'product_scancode',
|
|
|
|
}
|
|
|
|
|
|
|
|
row_form_fields = [
|
|
|
|
'sequence',
|
|
|
|
'item_entry',
|
|
|
|
'product',
|
|
|
|
'pending_product',
|
|
|
|
'_product_key_',
|
|
|
|
'product_brand',
|
|
|
|
'product_description',
|
|
|
|
'product_size',
|
|
|
|
'product_weighed',
|
|
|
|
'product_unit_of_measure',
|
|
|
|
'department_number',
|
|
|
|
'department_name',
|
|
|
|
'product_unit_cost',
|
|
|
|
'case_quantity',
|
|
|
|
'unit_price',
|
|
|
|
'price_needs_confirmation',
|
|
|
|
'order_quantity',
|
|
|
|
'order_uom',
|
|
|
|
'discount_percent',
|
|
|
|
'total_price',
|
|
|
|
'paid_amount',
|
|
|
|
# 'payment_transaction_number',
|
|
|
|
'status_code',
|
|
|
|
]
|
|
|
|
|
2020-08-02 20:59:16 -05:00
|
|
|
def configure_grid(self, g):
|
|
|
|
super(CustomerOrderBatchView, self).configure_grid(g)
|
|
|
|
|
2021-01-26 20:10:05 -06:00
|
|
|
g.set_type('total_price', 'currency')
|
|
|
|
|
2021-10-07 11:33:52 -05:00
|
|
|
g.set_link('contact_name')
|
2020-08-02 20:59:16 -05:00
|
|
|
g.set_link('created')
|
|
|
|
g.set_link('created_by')
|
|
|
|
|
|
|
|
def configure_form(self, f):
|
|
|
|
super(CustomerOrderBatchView, self).configure_form(f)
|
|
|
|
order = f.model_instance
|
|
|
|
model = self.rattail_config.get_model()
|
|
|
|
|
|
|
|
# readonly fields
|
|
|
|
f.set_readonly('rows')
|
|
|
|
f.set_readonly('status_code')
|
|
|
|
|
2021-09-25 17:55:53 -05:00
|
|
|
f.set_renderer('store', self.render_store)
|
|
|
|
|
2020-08-02 20:59:16 -05:00
|
|
|
# customer
|
|
|
|
if 'customer' in f.fields and self.editing:
|
|
|
|
f.replace('customer', 'customer_uuid')
|
|
|
|
f.set_node('customer_uuid', colander.String(), missing=colander.null)
|
|
|
|
customer_display = ""
|
|
|
|
if self.request.method == 'POST':
|
|
|
|
if self.request.POST.get('customer_uuid'):
|
2023-02-12 09:34:38 -06:00
|
|
|
customer = self.Session.get(model.Customer,
|
|
|
|
self.request.POST['customer_uuid'])
|
2020-08-02 20:59:16 -05:00
|
|
|
if customer:
|
2023-02-12 09:34:38 -06:00
|
|
|
customer_display = str(customer)
|
2020-08-02 20:59:16 -05:00
|
|
|
elif self.editing:
|
2023-02-12 09:34:38 -06:00
|
|
|
customer_display = str(order.customer or "")
|
2020-08-02 20:59:16 -05:00
|
|
|
customers_url = self.request.route_url('customers.autocomplete')
|
|
|
|
f.set_widget('customer_uuid', forms.widgets.JQueryAutocompleteWidget(
|
|
|
|
field_display=customer_display, service_url=customers_url))
|
|
|
|
f.set_label('customer_uuid', "Customer")
|
|
|
|
else:
|
|
|
|
f.set_renderer('customer', self.render_customer)
|
|
|
|
|
|
|
|
# person
|
|
|
|
if 'person' in f.fields and self.editing:
|
|
|
|
f.replace('person', 'person_uuid')
|
|
|
|
f.set_node('person_uuid', colander.String(), missing=colander.null)
|
|
|
|
person_display = ""
|
|
|
|
if self.request.method == 'POST':
|
|
|
|
if self.request.POST.get('person_uuid'):
|
2023-02-12 09:34:38 -06:00
|
|
|
person = self.Session.get(model.Person,
|
|
|
|
self.request.POST['person_uuid'])
|
2020-08-02 20:59:16 -05:00
|
|
|
if person:
|
2023-02-12 09:34:38 -06:00
|
|
|
person_display = str(person)
|
2020-08-02 20:59:16 -05:00
|
|
|
elif self.editing:
|
2023-02-12 09:34:38 -06:00
|
|
|
person_display = str(order.person or "")
|
2020-08-02 20:59:16 -05:00
|
|
|
people_url = self.request.route_url('people.autocomplete')
|
|
|
|
f.set_widget('person_uuid', forms.widgets.JQueryAutocompleteWidget(
|
|
|
|
field_display=person_display, service_url=people_url))
|
|
|
|
f.set_label('person_uuid', "Person")
|
|
|
|
else:
|
|
|
|
f.set_renderer('person', self.render_person)
|
2021-01-26 20:10:05 -06:00
|
|
|
|
2021-10-06 17:22:29 -05:00
|
|
|
# pending_customer
|
|
|
|
f.set_renderer('pending_customer', self.render_pending_customer)
|
|
|
|
|
2021-01-26 20:10:05 -06:00
|
|
|
f.set_type('total_price', 'currency')
|
|
|
|
|
2021-10-06 17:22:29 -05:00
|
|
|
def render_pending_customer(self, batch, field):
|
|
|
|
pending = batch.pending_customer
|
|
|
|
if not pending:
|
|
|
|
return
|
2023-02-12 09:34:38 -06:00
|
|
|
text = str(pending)
|
2021-10-06 17:22:29 -05:00
|
|
|
url = self.request.route_url('pending_customers.view', uuid=pending.uuid)
|
|
|
|
return tags.link_to(text, url)
|
|
|
|
|
2021-01-26 20:10:05 -06:00
|
|
|
def row_grid_extra_class(self, row, i):
|
|
|
|
if row.status_code == row.STATUS_PRODUCT_NOT_FOUND:
|
|
|
|
return 'warning'
|
2021-12-22 12:06:00 -06:00
|
|
|
if row.status_code == row.STATUS_PENDING_PRODUCT:
|
|
|
|
return 'notice'
|
2021-01-26 20:10:05 -06:00
|
|
|
|
|
|
|
def configure_row_grid(self, g):
|
|
|
|
super(CustomerOrderBatchView, self).configure_row_grid(g)
|
|
|
|
|
|
|
|
g.set_type('case_quantity', 'quantity')
|
|
|
|
g.set_type('cases_ordered', 'quantity')
|
|
|
|
g.set_type('units_ordered', 'quantity')
|
|
|
|
g.set_type('order_quantity', 'quantity')
|
|
|
|
g.set_enum('order_uom', self.enum.UNIT_OF_MEASURE)
|
|
|
|
g.set_type('unit_price', 'currency')
|
|
|
|
g.set_type('total_price', 'currency')
|
|
|
|
|
|
|
|
g.set_link('product_upc')
|
|
|
|
g.set_link('product_description')
|
|
|
|
|
|
|
|
def configure_row_form(self, f):
|
|
|
|
super(CustomerOrderBatchView, self).configure_row_form(f)
|
|
|
|
|
|
|
|
f.set_renderer('product', self.render_product)
|
2021-12-22 12:06:00 -06:00
|
|
|
f.set_renderer('pending_product', self.render_pending_product)
|
|
|
|
|
|
|
|
f.set_renderer('product_upc', self.render_upc)
|
2021-01-26 20:10:05 -06:00
|
|
|
|
|
|
|
f.set_type('case_quantity', 'quantity')
|
|
|
|
f.set_type('cases_ordered', 'quantity')
|
|
|
|
f.set_type('units_ordered', 'quantity')
|
|
|
|
f.set_type('order_quantity', 'quantity')
|
|
|
|
f.set_enum('order_uom', self.enum.UNIT_OF_MEASURE)
|
|
|
|
f.set_type('unit_price', 'currency')
|
|
|
|
f.set_type('total_price', 'currency')
|
2021-12-22 12:06:00 -06:00
|
|
|
f.set_type('paid_amount', 'currency')
|