Saltar al contenido principal

Stock Count Task Generation Implementation

Overview

The task generation functionality creates tasks for stock count sessions based on different strategies. This implementation supports three main strategies for organizing and assigning stock count work to users.

Key Features

1. Task Generation Strategies

By Zone/Bin (by_zone_bin)

  • Creates tasks based on zone and bin assignments
  • Each assignee rule creates a separate task
  • Useful for warehouse layouts with defined zones and bins
  • Tasks are assigned to specific users based on their zone/bin responsibilities

By Category (by_category)

  • Creates tasks based on product categories
  • Each category scope creates a separate task
  • Useful for organizing counts by product type
  • Tasks can be assigned to category specialists

By Assignee (by_assignee)

  • Creates tasks based on assignee rules
  • Each assignee gets their own task
  • Useful for distributing work among available counters
  • Requires assignee rules to be defined

2. Assignee Rules

Assignee rules allow you to specify:

  • Zone: Specific warehouse zone
  • Bin: Specific storage bin
  • Assignee ID: User responsible for the task

Rules can be:

  • Zone-specific: { zone: "A1", assigneeId: "user123" }
  • Bin-specific: { bin: "B2", assigneeId: "user456" }
  • Zone and bin specific: { zone: "A1", bin: "B2", assigneeId: "user789" }

3. Task Status Management

Tasks are created with the following status flow:

  • PENDING: Initial status when task is created
  • IN_PROGRESS: When counter starts working on the task
  • PAUSED: When task is temporarily paused
  • COMPLETED: When counting is finished
  • RECONCILED: When variances are reviewed and approved

Implementation Details

Database Transaction

All task creation operations are wrapped in a database transaction to ensure data consistency.

Error Handling

  • Validates session status (must be DRAFT)
  • Checks for scope definitions
  • Validates assignee rules for required strategies
  • Provides detailed logging for debugging

Task Creation Process

  1. Validation: Check session status and scope existence
  2. Strategy Selection: Choose appropriate task generation method
  3. Task Creation: Generate task objects based on strategy
  4. Database Insertion: Create tasks in the database
  5. Logging: Record the number of tasks created

Usage Examples

Zone/Bin Strategy

{
"strategy": "by_zone_bin",
"assigneeRules": [
{
"zone": "A1",
"assigneeId": "user123"
},
{
"zone": "A2",
"assigneeId": "user456"
}
],
"createdBy": "planner123"
}

Category Strategy

{
"strategy": "by_category",
"assigneeRules": [
{
"assigneeId": "user789"
}
],
"createdBy": "planner123"
}

Assignee Strategy

{
"strategy": "by_assignee",
"assigneeRules": [
{
"assigneeId": "user123"
},
{
"assigneeId": "user456"
}
],
"createdBy": "planner123"
}

API Endpoints

Generate Tasks

POST /stock-count/sessions/{sessionId}/tasks:generate

Request Body:

{
strategy: "by_zone_bin" | "by_category" | "by_assignee";
assigneeRules?: AssigneeRuleDTO[];
createdBy: string;
}

Response:

SelectableStockCountTask[]

List Tasks

GET /stock-count/tasks?sessionId={sessionId}&assigneeId={assigneeId}&status={status}

Database Schema

Stock Count Task Table

CREATE TABLE stock_count_task (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
session_id UUID NOT NULL REFERENCES stock_count_session(id),
assignee_user_id UUID REFERENCES user(id),
zone VARCHAR,
bin VARCHAR,
status stock_count_task_status DEFAULT 'pending',
notes TEXT,
created_by UUID NOT NULL REFERENCES user(id),
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMPTZ,
updated_by UUID REFERENCES user(id),
started_at TIMESTAMPTZ,
completed_at TIMESTAMPTZ
);

Workflow Integration

The task generation is part of the overall stock count workflow:

  1. Create Session: Initialize stock count session
  2. Add Scopes: Define which products to count
  3. Generate Tasks: Create tasks based on strategy
  4. Start Session: Begin the counting process
  5. Create Snapshot: Capture system quantities
  6. Complete Tasks: Counters complete their assigned tasks
  7. Post Session: Process variances and update inventory

Future Enhancements

Potential improvements for the task generation system:

  1. Dynamic Task Sizing: Automatically split large tasks into smaller ones
  2. Load Balancing: Distribute work evenly among available counters
  3. Priority Assignment: Assign high-value or critical items to experienced counters
  4. Time Estimation: Calculate expected completion time based on task size
  5. Route Optimization: Optimize counting routes within zones/bins
  6. Real-time Assignment: Allow dynamic task reassignment during counting