From 48daa042d17827e133f7107b139251ce460e85b0 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sun, 10 Sep 2023 07:45:25 -0500 Subject: [PATCH] Show related customer orders for Pending Product view and similar tweaks --- tailbone/templates/products/pending/view.mako | 22 +++---- tailbone/views/products.py | 64 ++++++++++++++++--- 2 files changed, 65 insertions(+), 21 deletions(-) diff --git a/tailbone/templates/products/pending/view.mako b/tailbone/templates/products/pending/view.mako index 90d9c687..be61a44f 100644 --- a/tailbone/templates/products/pending/view.mako +++ b/tailbone/templates/products/pending/view.mako @@ -53,24 +53,22 @@ diff --git a/tailbone/views/products.py b/tailbone/views/products.py index 92c99c34..e0183d14 100644 --- a/tailbone/views/products.py +++ b/tailbone/views/products.py @@ -2229,6 +2229,7 @@ class PendingProductView(MasterView): form_fields = [ '_product_key_', + 'product', 'brand_name', 'brand', 'description', @@ -2237,14 +2238,34 @@ class PendingProductView(MasterView): 'department', 'vendor_name', 'vendor', + 'vendor_item_code', 'unit_cost', 'case_size', 'regular_price_amount', 'special_order', 'notes', + 'status_code', 'created', 'user', - 'status_code', + 'resolved', + 'resolved_by', + ] + + has_rows = True + model_row_class = model.CustomerOrderItem + rows_title = "Customer Orders" + # TODO: add support for this someday + rows_viewable = False + + # TODO: this clearly needs help + row_grid_columns = [ + # 'upc', + 'brand_name', + 'description', + 'size', + 'vendor_name', + # 'regular_price', + # 'current_price', ] def configure_grid(self, g): @@ -2264,6 +2285,10 @@ class PendingProductView(MasterView): model = self.model pending = f.model_instance + # product + f.set_readonly('product') # TODO + f.set_renderer('product', self.render_product) + # department if self.creating or self.editing: if 'department' in f: @@ -2342,13 +2367,6 @@ class PendingProductView(MasterView): else: f.set_readonly('created') - # user - if self.creating: - f.remove('user') - else: - f.set_readonly('user') - f.set_renderer('user', self.render_user) - # status_code if self.creating: f.remove('status_code') @@ -2356,7 +2374,23 @@ class PendingProductView(MasterView): # f.set_readonly('status_code') f.set_enum('status_code', self.enum.PENDING_PRODUCT_STATUS) + # user + if self.creating: + f.remove('user') + else: + f.set_readonly('user') + f.set_renderer('user', self.render_user) + + # resolved* + if self.creating: + f.remove('resolved', 'resolved_by') + else: + if not pending.resolved: + f.remove('resolved', 'resolved_by') + def editable_instance(self, pending): + if self.request.is_root: + return True if pending.status_code == self.enum.PENDING_PRODUCT_STATUS_RESOLVED: return False return True @@ -2419,9 +2453,21 @@ class PendingProductView(MasterView): app = self.get_rattail_app() products_handler = app.get_products_handler() - products_handler.resolve_product(pending, product, self.request.user) + kwargs = self.get_resolve_product_kwargs() + products_handler.resolve_product(pending, product, self.request.user, **kwargs) return redirect + def get_resolve_product_kwargs(self, **kwargs): + return kwargs + + def get_row_data(self, pending): + model = self.model + return self.Session.query(model.CustomerOrderItem)\ + .filter(model.CustomerOrderItem.pending_product == pending) + + def get_parent(self, item): + return item.pending_product + @classmethod def defaults(cls, config): cls._defaults(config)