Model-config web apps: describe the app in configuration instead of writing code. Built on Polars and DuckDB.
orders_crud.yaml · 11.4 KB · 462 lines
| 1 | # DBBasic E-Commerce Template - Orders |
| 2 | # Complete order management with workflow, payments, and fulfillment |
| 3 | |
| 4 | resource: orders |
| 5 | database: ecommerce.db |
| 6 | |
| 7 | fields: |
| 8 | id: |
| 9 | type: primary_key |
| 10 | order_number: |
| 11 | type: string |
| 12 | unique: true |
| 13 | max_length: 20 |
| 14 | ui: |
| 15 | readonly: true |
| 16 | help_text: "Auto-generated order number" |
| 17 | |
| 18 | # Customer Information |
| 19 | customer_id: |
| 20 | type: foreign_key |
| 21 | references: customers |
| 22 | required: true |
| 23 | customer_email: |
| 24 | type: email |
| 25 | required: true |
| 26 | customer_phone: |
| 27 | type: string |
| 28 | max_length: 20 |
| 29 | |
| 30 | # Order Status and Workflow |
| 31 | status: |
| 32 | type: select |
| 33 | options: [pending, confirmed, processing, shipped, delivered, cancelled, refunded] |
| 34 | default: pending |
| 35 | required: true |
| 36 | ui: |
| 37 | variant: status_badge |
| 38 | colors: |
| 39 | pending: warning |
| 40 | confirmed: info |
| 41 | processing: primary |
| 42 | shipped: success |
| 43 | delivered: success |
| 44 | cancelled: danger |
| 45 | refunded: secondary |
| 46 | |
| 47 | payment_status: |
| 48 | type: select |
| 49 | options: [pending, authorized, paid, partially_paid, failed, refunded, partially_refunded] |
| 50 | default: pending |
| 51 | required: true |
| 52 | |
| 53 | fulfillment_status: |
| 54 | type: select |
| 55 | options: [pending, processing, shipped, partially_shipped, delivered, cancelled] |
| 56 | default: pending |
| 57 | |
| 58 | # Financial Information |
| 59 | subtotal: |
| 60 | type: decimal |
| 61 | precision: 10 |
| 62 | scale: 2 |
| 63 | required: true |
| 64 | min: 0 |
| 65 | ui: |
| 66 | prefix: "$" |
| 67 | readonly: true |
| 68 | tax_amount: |
| 69 | type: decimal |
| 70 | precision: 10 |
| 71 | scale: 2 |
| 72 | default: 0 |
| 73 | min: 0 |
| 74 | ui: |
| 75 | prefix: "$" |
| 76 | shipping_amount: |
| 77 | type: decimal |
| 78 | precision: 10 |
| 79 | scale: 2 |
| 80 | default: 0 |
| 81 | min: 0 |
| 82 | ui: |
| 83 | prefix: "$" |
| 84 | discount_amount: |
| 85 | type: decimal |
| 86 | precision: 10 |
| 87 | scale: 2 |
| 88 | default: 0 |
| 89 | min: 0 |
| 90 | ui: |
| 91 | prefix: "$" |
| 92 | total_amount: |
| 93 | type: decimal |
| 94 | precision: 10 |
| 95 | scale: 2 |
| 96 | required: true |
| 97 | min: 0 |
| 98 | ui: |
| 99 | prefix: "$" |
| 100 | readonly: true |
| 101 | |
| 102 | # Addresses |
| 103 | billing_address: |
| 104 | type: json |
| 105 | required: true |
| 106 | ui: |
| 107 | component: address_input |
| 108 | fields: [first_name, last_name, company, address1, address2, city, state, zip, country] |
| 109 | |
| 110 | shipping_address: |
| 111 | type: json |
| 112 | required: true |
| 113 | ui: |
| 114 | component: address_input |
| 115 | copy_from_billing: true |
| 116 | |
| 117 | # Shipping Information |
| 118 | shipping_method: |
| 119 | type: string |
| 120 | max_length: 100 |
| 121 | shipping_carrier: |
| 122 | type: string |
| 123 | max_length: 50 |
| 124 | tracking_number: |
| 125 | type: string |
| 126 | max_length: 100 |
| 127 | ui: |
| 128 | help_text: "Package tracking number" |
| 129 | tracking_url: |
| 130 | type: url |
| 131 | ui: |
| 132 | help_text: "Link to track shipment" |
| 133 | |
| 134 | # Payment Information |
| 135 | payment_method: |
| 136 | type: string |
| 137 | max_length: 50 |
| 138 | payment_reference: |
| 139 | type: string |
| 140 | max_length: 100 |
| 141 | ui: |
| 142 | help_text: "Payment gateway transaction ID" |
| 143 | |
| 144 | # Order Metadata |
| 145 | notes: |
| 146 | type: text |
| 147 | ui: |
| 148 | component: textarea |
| 149 | rows: 3 |
| 150 | placeholder: "Internal notes about this order" |
| 151 | customer_notes: |
| 152 | type: text |
| 153 | ui: |
| 154 | component: textarea |
| 155 | rows: 3 |
| 156 | placeholder: "Customer's order notes or special instructions" |
| 157 | |
| 158 | # Timestamps |
| 159 | order_date: |
| 160 | type: timestamp |
| 161 | auto_now_add: true |
| 162 | shipped_at: |
| 163 | type: timestamp |
| 164 | delivered_at: |
| 165 | type: timestamp |
| 166 | cancelled_at: |
| 167 | type: timestamp |
| 168 | created_at: |
| 169 | type: timestamp |
| 170 | auto_now_add: true |
| 171 | updated_at: |
| 172 | type: timestamp |
| 173 | auto_now: true |
| 174 | |
| 175 | # Complex Order Workflow Hooks |
| 176 | hooks: |
| 177 | before_create: |
| 178 | - validate_order_data # Comprehensive order validation |
| 179 | - calculate_taxes_and_shipping # Real-time tax/shipping calculation |
| 180 | - validate_inventory_availability # Ensure all items are in stock |
| 181 | - apply_promotions_and_discounts # Calculate final pricing |
| 182 | - generate_order_number # Create unique order identifier |
| 183 | |
| 184 | after_create: |
| 185 | - reserve_inventory # Hold inventory for this order |
| 186 | - send_order_confirmation # Email confirmation to customer |
| 187 | - process_payment_authorization # Authorize payment method |
| 188 | - create_fulfillment_tasks # Generate picking/packing tasks |
| 189 | - update_customer_analytics # Track customer behavior |
| 190 | - trigger_fraud_detection # Security screening |
| 191 | |
| 192 | before_update: |
| 193 | - validate_status_transition # Ensure valid workflow progression |
| 194 | - check_payment_requirements # Verify payment for status changes |
| 195 | - validate_address_changes # Prevent shipping after fulfillment |
| 196 | - calculate_refund_amounts # Compute partial refunds |
| 197 | |
| 198 | after_update: |
| 199 | - update_inventory_on_status # Adjust stock based on status |
| 200 | - send_status_notifications # Email/SMS customer updates |
| 201 | - sync_payment_status # Update payment gateway |
| 202 | - update_shipping_tracking # Sync with carrier APIs |
| 203 | - trigger_delivery_confirmation # Send delivery notifications |
| 204 | - process_automatic_reviews # Request product reviews |
| 205 | |
| 206 | before_delete: |
| 207 | - check_order_dependencies # Prevent deletion of processed orders |
| 208 | - validate_cancellation_policy # Check if cancellation is allowed |
| 209 | - calculate_cancellation_fees # Determine any penalties |
| 210 | |
| 211 | after_delete: |
| 212 | - restore_inventory_reservation # Return items to available stock |
| 213 | - process_payment_refund # Refund customer payment |
| 214 | - cancel_shipping_labels # Void shipping charges |
| 215 | - update_analytics_data # Adjust sales metrics |
| 216 | - send_cancellation_notice # Notify customer of cancellation |
| 217 | |
| 218 | # Advanced Order Management Permissions |
| 219 | permissions: |
| 220 | create: |
| 221 | - role: customer # Customers can place orders |
| 222 | - role: sales_rep # Sales reps can create orders |
| 223 | - role: admin |
| 224 | read: |
| 225 | - condition: customer_owns_order # Customers see their own orders |
| 226 | - role: sales_rep |
| 227 | - role: fulfillment_team |
| 228 | - role: admin |
| 229 | update: |
| 230 | - condition: order_editable # Only editable if status allows |
| 231 | - role: sales_rep |
| 232 | - role: admin |
| 233 | delete: |
| 234 | - condition: order_cancellable # Only if not yet processed |
| 235 | - role: admin |
| 236 | |
| 237 | # Comprehensive API Configuration |
| 238 | api: |
| 239 | base_path: /api/orders |
| 240 | enable_bulk: true |
| 241 | enable_export: true |
| 242 | rate_limiting: |
| 243 | read: 1000/hour |
| 244 | write: 200/hour |
| 245 | |
| 246 | # E-Commerce Specific Endpoints |
| 247 | custom_endpoints: |
| 248 | - path: /customer/{customer_id} |
| 249 | method: GET |
| 250 | filter: {customer_id: "{customer_id}"} |
| 251 | permissions: [customer_owns_account, staff] |
| 252 | |
| 253 | - path: /{id}/items |
| 254 | method: GET |
| 255 | related: order_items |
| 256 | ordering: [product_name] |
| 257 | |
| 258 | - path: /{id}/timeline |
| 259 | method: GET |
| 260 | action: get_order_timeline |
| 261 | returns: status_history |
| 262 | |
| 263 | - path: /{id}/invoice |
| 264 | method: GET |
| 265 | action: generate_invoice |
| 266 | format: pdf |
| 267 | |
| 268 | - path: /{id}/shipping-label |
| 269 | method: POST |
| 270 | action: generate_shipping_label |
| 271 | permissions: [fulfillment_team, admin] |
| 272 | |
| 273 | - path: /{id}/track |
| 274 | method: GET |
| 275 | action: get_tracking_info |
| 276 | external_api: shipping_carriers |
| 277 | |
| 278 | - path: /{id}/refund |
| 279 | method: POST |
| 280 | action: process_refund |
| 281 | permissions: [sales_rep, admin] |
| 282 | parameters: [amount, reason, refund_shipping] |
| 283 | |
| 284 | - path: /analytics/summary |
| 285 | method: GET |
| 286 | action: get_order_analytics |
| 287 | permissions: [manager, admin] |
| 288 | cache_ttl: 300 |
| 289 | |
| 290 | # Advanced Order Management Interface |
| 291 | interface: |
| 292 | # Order List for Admin/Staff |
| 293 | list_display: [order_number, customer_email, total_amount, status, payment_status, order_date] |
| 294 | list_filters: [status, payment_status, fulfillment_status, order_date, shipping_method] |
| 295 | search_fields: [order_number, customer_email, billing_address, shipping_address] |
| 296 | ordering: [-order_date] |
| 297 | per_page: 50 |
| 298 | |
| 299 | # Detailed Order Form |
| 300 | form_layout: |
| 301 | - section: "Order Information" |
| 302 | fields: [order_number, customer_id, customer_email, order_date] |
| 303 | columns: 2 |
| 304 | readonly: [order_number, order_date] |
| 305 | |
| 306 | - section: "Status & Workflow" |
| 307 | fields: [status, payment_status, fulfillment_status] |
| 308 | columns: 3 |
| 309 | |
| 310 | - section: "Financial Summary" |
| 311 | fields: [subtotal, tax_amount, shipping_amount, discount_amount, total_amount] |
| 312 | columns: 5 |
| 313 | readonly: [subtotal, total_amount] |
| 314 | |
| 315 | - section: "Billing Address" |
| 316 | fields: [billing_address] |
| 317 | columns: 1 |
| 318 | |
| 319 | - section: "Shipping Information" |
| 320 | fields: [shipping_address, shipping_method, tracking_number, tracking_url] |
| 321 | columns: 2 |
| 322 | |
| 323 | - section: "Payment Details" |
| 324 | fields: [payment_method, payment_reference] |
| 325 | columns: 2 |
| 326 | |
| 327 | - section: "Notes" |
| 328 | fields: [customer_notes, notes] |
| 329 | columns: 1 |
| 330 | |
| 331 | # Customer Order View |
| 332 | customer_template: order_details |
| 333 | customer_layout: |
| 334 | header: [order_number, status, order_date, total_amount] |
| 335 | progress: [status_timeline] |
| 336 | items: [order_items_list] |
| 337 | addresses: [billing_address, shipping_address] |
| 338 | tracking: [shipping_info, tracking_link] |
| 339 | actions: [download_invoice, contact_support, cancel_order] |
| 340 | |
| 341 | # Advanced Bootstrap E-Commerce UI |
| 342 | ui: |
| 343 | theme: bootstrap |
| 344 | variant: ecommerce_orders |
| 345 | |
| 346 | components: |
| 347 | list: |
| 348 | variant: table-responsive |
| 349 | density: comfortable |
| 350 | status_indicators: true |
| 351 | bulk_actions: [export, mark_shipped, mark_delivered, send_notifications] |
| 352 | |
| 353 | form: |
| 354 | variant: workflow |
| 355 | status_workflow: true |
| 356 | address_autocomplete: true |
| 357 | payment_integration: true |
| 358 | |
| 359 | detail: |
| 360 | variant: order_summary |
| 361 | timeline: true |
| 362 | printable: true |
| 363 | real_time_updates: true |
| 364 | |
| 365 | # Order-Specific Styling |
| 366 | css_classes: |
| 367 | order_total: "h3 text-success font-weight-bold" |
| 368 | status_pending: "badge badge-warning" |
| 369 | status_confirmed: "badge badge-info" |
| 370 | status_processing: "badge badge-primary" |
| 371 | status_shipped: "badge badge-success" |
| 372 | status_delivered: "badge badge-success" |
| 373 | status_cancelled: "badge badge-danger" |
| 374 | payment_paid: "text-success" |
| 375 | payment_pending: "text-warning" |
| 376 | payment_failed: "text-danger" |
| 377 | |
| 378 | # Order Workflow State Machine |
| 379 | workflow: |
| 380 | states: |
| 381 | pending: |
| 382 | transitions: [confirmed, cancelled] |
| 383 | permissions: [customer, sales_rep, admin] |
| 384 | |
| 385 | confirmed: |
| 386 | transitions: [processing, cancelled] |
| 387 | permissions: [sales_rep, admin] |
| 388 | actions: [authorize_payment, reserve_inventory] |
| 389 | |
| 390 | processing: |
| 391 | transitions: [shipped, cancelled] |
| 392 | permissions: [fulfillment_team, admin] |
| 393 | actions: [pick_items, pack_order, generate_shipping_label] |
| 394 | |
| 395 | shipped: |
| 396 | transitions: [delivered, cancelled] |
| 397 | permissions: [carrier_webhook, admin] |
| 398 | actions: [send_tracking_info, schedule_delivery] |
| 399 | |
| 400 | delivered: |
| 401 | transitions: [refunded] |
| 402 | permissions: [carrier_webhook, customer_confirmation, admin] |
| 403 | actions: [request_review, update_analytics] |
| 404 | |
| 405 | cancelled: |
| 406 | transitions: [] |
| 407 | permissions: [customer_if_early, admin] |
| 408 | actions: [process_refund, restore_inventory] |
| 409 | |
| 410 | # Integration Configuration |
| 411 | integrations: |
| 412 | payment_gateways: |
| 413 | - stripe |
| 414 | - paypal |
| 415 | - square |
| 416 | |
| 417 | shipping_carriers: |
| 418 | - ups |
| 419 | - fedex |
| 420 | - usps |
| 421 | - dhl |
| 422 | |
| 423 | tax_services: |
| 424 | - avalara |
| 425 | - taxjar |
| 426 | |
| 427 | analytics: |
| 428 | - google_analytics_ecommerce |
| 429 | - facebook_pixel |
| 430 | |
| 431 | email_services: |
| 432 | - sendgrid |
| 433 | - mailchimp |
| 434 | |
| 435 | # Order Analytics and Reporting |
| 436 | analytics: |
| 437 | track_conversion_funnel: true |
| 438 | track_order_value: true |
| 439 | track_customer_lifetime_value: true |
| 440 | track_fulfillment_performance: true |
| 441 | |
| 442 | reports: |
| 443 | - daily_orders_summary |
| 444 | - weekly_sales_report |
| 445 | - monthly_customer_analysis |
| 446 | - inventory_impact_report |
| 447 | - shipping_cost_analysis |
| 448 | |
| 449 | # Fraud Detection |
| 450 | fraud_detection: |
| 451 | enable: true |
| 452 | risk_factors: |
| 453 | - unusual_order_patterns |
| 454 | - high_value_orders |
| 455 | - mismatched_billing_shipping |
| 456 | - multiple_failed_payments |
| 457 | - velocity_checks |
| 458 | |
| 459 | actions: |
| 460 | low_risk: auto_approve |
| 461 | medium_risk: manual_review |
| 462 | high_risk: auto_hold |