RFC: Unifying Direct Orders into CustomerOrder
1. Objective
Section titled “1. Objective”Consolidate the conceptually fragmented direct_order_i and direct_order_ii DocTypes (traditionally split between AFD-I and AFD-II models) into a single, unified CustomerOrder table. This shift centralizes the business logic, reduces schema duplication, and provides a scalable routing architecture based on distinct category tags rather than isolated database tables.
2. Proposed Architecture
Section titled “2. Proposed Architecture”Instead of utilizing hardcoded tables for separate order flows, the CustomerOrder table will utilize two distinct categorical fields to decouple Compliance / Business Logic from Supply Chain Logistics.
2.1 Order Category (order_category)
Section titled “2.1 Order Category (order_category)”Dictates what is being ordered. This field handles legal, compliance, and business groupings.
Standard: Regular consumer items and general orders.Dropship: Items shipped directly from vendors.Special_Demand: Specially negotiated, bulk, or high-value procurement requests.Classified: Sensitive products requiring restricted visibility.Restricted: Highly regulated goods requiring explicit clearance and compliance checks (e.g., Weapons).
2.2 Fulfillment Method (fulfillment_method)
Section titled “2.2 Fulfillment Method (fulfillment_method)”Dictates how it gets to the user. This field explicitly targets supply chain flow and operational routing.
dealer_direct: The dealer directly supplies the item to the customer (Replaces the physical routing ofAFD-I/direct_order_i).DC_Pickup: The customer picks up the fulfillment from the Distribution Center (Replaces the physical routing ofAFD-II/direct_order_ii).Store_Pickup: Standard store fulfillment where the customer secures the product from their local Retail Outlet.
3. Scope & Migration Impact
Section titled “3. Scope & Migration Impact”- Schema Construction: Adding
CustomerOrdertolibs/wms/doctypes. Consolidating all fields previously resident indirect_order_ianddirect_order_ii(likecustomer,business_price,outlet). - Logic Routing: Transitioning services from checking
if isinstance(order, DirectOrderI)to utilizingif order.fulfillment_method == 'dealer_direct'. - Simplification / Cleanup: Deprecation and explicit removal of the
direct_order_ianddirect_order_iisub-modules. - Upstream Dependencies: The
supplier_apiandsupplier_portal_servicewill now consume one uniform payload definition for external orders.
4. Implementation Steps
Section titled “4. Implementation Steps”-
Scaffold the Unified DocType
- Create
libs/wms/src/wms/doctypes/customer_order. - Define
CustomerOrderindoctype.pyapplying the unified properties and settingtable_name = "customer_order". - Add
order_categoryandfulfillment_methodas enumerations.
- Create
-
Merge Controller Logic
- Combine the validation hooks in
DirectOrderIControllerandDirectOrderIIControllerintoCustomerOrderController. - Implement logical branching dependent on
order_category(for compliance checks) andfulfillment_method(for status/delivery orchestration).
- Combine the validation hooks in
-
Refactor Integrated Services
- Update
SupplierPortalServiceand API route aggregators to query and accept the singleCustomerOrderinterface. - Refactor queries that previously performed bulk pulls across both models.
- Update
-
Deprecate Legacy Models
- Delete
libs/wms/src/wms/doctypes/direct_order_i(andafd_order_i). - Delete
libs/wms/src/wms/doctypes/direct_order_ii(andafd_order_ii).
- Delete
-
Test Assertions
- Implement unit tests mapping scenarios: e.g., validating that setting
fulfillment_method = "dealer_direct"accurately shadows the original AFD-I supply chain rules.
- Implement unit tests mapping scenarios: e.g., validating that setting