From 25483a21a057a76eb556b125dee92e91b98f2db7 2021-09-27 11:31:12 From: Lance Edgar Date: 2021-09-27 11:31:12 Subject: [PATCH] Add "all" enum values for custorder item status, event also attach "initiated" event(s) when creating new custorder --- diff --git a/rattail/batch/custorder.py b/rattail/batch/custorder.py index 3b921b4b39dbdb659744a8b8294aec0c9454e6e9..b5f404c42167f02484c3024cd55a2695c53f3c8f 100644 --- a/rattail/batch/custorder.py +++ b/rattail/batch/custorder.py @@ -381,11 +381,16 @@ class CustomerOrderBatchHandler(BatchHandler): def convert(row, i): item = model.CustomerOrderItem() item.sequence = i - item.status_code = self.enum.CUSTORDER_ITEM_STATUS_ORDERED + item.status_code = self.enum.CUSTORDER_ITEM_STATUS_INITIATED for field in row_fields: setattr(item, field, getattr(row, field)) order.items.append(item) + # attach event + item.events.append(model.CustomerOrderItemEvent( + type_code=self.enum.CUSTORDER_ITEM_EVENT_INITIATED, + user=user)) + self.progress_loop(convert, batch.active_rows(), progress, message="Converting batch rows to order items") diff --git a/rattail/enum.py b/rattail/enum.py index 1e53ec82e2cd2b6a263f7b28a389a236cfd0a496..c61df73118d2e630c21922d410c792aec4263d7c 100644 --- a/rattail/enum.py +++ b/rattail/enum.py @@ -56,6 +56,8 @@ The following enumerations are provided: from __future__ import unicode_literals, absolute_import +from rattail.util import OrderedDict + BATCH_ACTION_ADD = 'ADD' BATCH_ACTION_ADD_REPLACE = 'ADDRPL' @@ -90,13 +92,70 @@ CUSTORDER_STATUS = { } -CUSTORDER_ITEM_STATUS_ORDERED = 10 -# CUSTORDER_ITEM_STATUS_PAID = 20 - -CUSTORDER_ITEM_STATUS = { - CUSTORDER_ITEM_STATUS_ORDERED : "ordered", - # CUSTORDER_ITEM_STATUS_PAID : "paid", -} +CUSTORDER_ITEM_STATUS_INITIATED = 10 +# TODO: deprecate / remove this one +CUSTORDER_ITEM_STATUS_ORDERED = CUSTORDER_ITEM_STATUS_INITIATED +CUSTORDER_ITEM_STATUS_PAID = 20 +CUSTORDER_ITEM_STATUS_PLACED = 30 +CUSTORDER_ITEM_STATUS_RECEIVED = 40 +CUSTORDER_ITEM_STATUS_CONTACTED = 50 +CUSTORDER_ITEM_STATUS_CONTACT_FAILED = 60 +CUSTORDER_ITEM_STATUS_DELIVERED = 70 +CUSTORDER_ITEM_STATUS_CANCELED = 900 +CUSTORDER_ITEM_STATUS_REFUND_PENDING = 910 +CUSTORDER_ITEM_STATUS_REFUNDED = 920 +CUSTORDER_ITEM_STATUS_RESTOCKED = 930 +CUSTORDER_ITEM_STATUS_EXPIRED = 940 +CUSTORDER_ITEM_STATUS_INACTIVE = 950 + +CUSTORDER_ITEM_STATUS = OrderedDict([ + (CUSTORDER_ITEM_STATUS_INITIATED, "customer order initiated"), + (CUSTORDER_ITEM_STATUS_PAID, "payment received"), + (CUSTORDER_ITEM_STATUS_PLACED, "order placed with vendor"), + (CUSTORDER_ITEM_STATUS_RECEIVED, "received from vendor"), + (CUSTORDER_ITEM_STATUS_CONTACTED, "customer contacted"), + (CUSTORDER_ITEM_STATUS_CONTACT_FAILED, "unable to contact customer"), + (CUSTORDER_ITEM_STATUS_DELIVERED, "delivered to customer"), + (CUSTORDER_ITEM_STATUS_CANCELED, "canceled"), + (CUSTORDER_ITEM_STATUS_REFUND_PENDING, "refund pending"), + (CUSTORDER_ITEM_STATUS_REFUNDED, "refunded"), + (CUSTORDER_ITEM_STATUS_RESTOCKED, "restocked"), + (CUSTORDER_ITEM_STATUS_EXPIRED, "expired"), + (CUSTORDER_ITEM_STATUS_INACTIVE, "inactive"), +]) + + +CUSTORDER_ITEM_EVENT_INITIATED = 10 +CUSTORDER_ITEM_EVENT_PAID = 20 +CUSTORDER_ITEM_EVENT_PLACED = 30 +CUSTORDER_ITEM_EVENT_RECEIVED = 40 +CUSTORDER_ITEM_EVENT_CONTACTED = 50 +CUSTORDER_ITEM_EVENT_CONTACT_FAILED = 60 +CUSTORDER_ITEM_EVENT_DELIVERED = 70 +CUSTORDER_ITEM_EVENT_STATUS_CHANGE = 500 # nb. this is not in STATUS enum +CUSTORDER_ITEM_EVENT_CANCELED = 900 +CUSTORDER_ITEM_EVENT_REFUND_PENDING = 910 +CUSTORDER_ITEM_EVENT_REFUNDED = 920 +CUSTORDER_ITEM_EVENT_RESTOCKED = 930 +CUSTORDER_ITEM_EVENT_EXPIRED = 940 +CUSTORDER_ITEM_EVENT_INACTIVE = 950 + +CUSTORDER_ITEM_EVENT = OrderedDict([ + (CUSTORDER_ITEM_EVENT_INITIATED, "customer order initiated"), + (CUSTORDER_ITEM_EVENT_PAID, "payment received"), + (CUSTORDER_ITEM_EVENT_PLACED, "order placed with vendor"), + (CUSTORDER_ITEM_EVENT_RECEIVED, "received from vendor"), + (CUSTORDER_ITEM_EVENT_CONTACTED, "customer contacted"), + (CUSTORDER_ITEM_EVENT_CONTACT_FAILED, "unable to contact customer"), + (CUSTORDER_ITEM_EVENT_DELIVERED, "delivered to customer"), + (CUSTORDER_ITEM_EVENT_STATUS_CHANGE, "manual status change"), + (CUSTORDER_ITEM_EVENT_CANCELED, "canceled"), + (CUSTORDER_ITEM_EVENT_REFUND_PENDING, "refund pending"), + (CUSTORDER_ITEM_EVENT_REFUNDED, "refunded"), + (CUSTORDER_ITEM_EVENT_RESTOCKED, "restocked"), + (CUSTORDER_ITEM_EVENT_EXPIRED, "expired"), + (CUSTORDER_ITEM_EVENT_INACTIVE, "inactive"), +]) EMAIL_ATTEMPT_CREATED = 0