38964-vm/backend/src/db/seeders/20231127130745-sample-data.js
2026-03-04 10:46:46 +00:00

6415 lines
132 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Warehouses = db.warehouses;
const Locations = db.locations;
const Products = db.products;
const Customers = db.customers;
const Carriers = db.carriers;
const InventoryBalances = db.inventory_balances;
const Receipts = db.receipts;
const ReceiptLines = db.receipt_lines;
const SalesOrders = db.sales_orders;
const SalesOrderLines = db.sales_order_lines;
const PickLists = db.pick_lists;
const PickListLines = db.pick_list_lines;
const PackingSlips = db.packing_slips;
const Packages = db.packages;
const Shipments = db.shipments;
const ShipmentPackages = db.shipment_packages;
const StockMovements = db.stock_movements;
const AuditEvents = db.audit_events;
const WarehousesData = [
{
"name": "East Coast DC",
"code": "ECDC",
"address": "1200 Harbor Parkway, Newark NJ 07114",
"timezone": "America/New_York",
"is_active": true,
},
{
"name": "Midwest Fulfillment Center",
"code": "MWFC",
"address": "4550 Logistics Way, Joliet IL 60431",
"timezone": "America/Chicago",
"is_active": true,
},
{
"name": "West Coast DC",
"code": "WCDC",
"address": "9800 Industrial Blvd, Ontario CA 91761",
"timezone": "America/Los_Angeles",
"is_active": true,
},
];
const LocationsData = [
{
// type code here for "relation_one" field
"name": "Receiving Dock 1",
"code": "ECDC-REC-01",
"location_type": "picking",
"is_pickable": false,
"is_receivable": true,
"is_active": true,
},
{
// type code here for "relation_one" field
"name": "Aisle A Bin 01",
"code": "ECDC-A-01",
"location_type": "quarantine",
"is_pickable": true,
"is_receivable": true,
"is_active": true,
},
{
// type code here for "relation_one" field
"name": "Aisle A Bin 02",
"code": "ECDC-A-02",
"location_type": "picking",
"is_pickable": true,
"is_receivable": false,
"is_active": true,
},
];
const ProductsData = [
{
"sku": "NW-TSHIRT-BLK-M",
"name": "Northwind T-Shirt Black M",
"barcode": "840100000101",
"description": "Cotton t-shirt, black, size M",
"weight_kg": 0.22,
"length_cm": 25,
"width_cm": 20,
"height_cm": 2,
"is_serialized": true,
"reorder_point": 50,
"reorder_qty": 200,
// type code here for "images" field
"is_active": true,
},
{
"sku": "NW-MUG-WHT-12OZ",
"name": "Northwind Mug White 12oz",
"barcode": "840100000102",
"description": "Ceramic mug, 12oz, white",
"weight_kg": 0.38,
"length_cm": 12,
"width_cm": 9,
"height_cm": 10,
"is_serialized": true,
"reorder_point": 40,
"reorder_qty": 120,
// type code here for "images" field
"is_active": true,
},
{
"sku": "NW-HOODIE-GRY-L",
"name": "Northwind Hoodie Grey L",
"barcode": "840100000103",
"description": "Fleece hoodie, grey, size L",
"weight_kg": 0.68,
"length_cm": 35,
"width_cm": 28,
"height_cm": 6,
"is_serialized": true,
"reorder_point": 30,
"reorder_qty": 80,
// type code here for "images" field
"is_active": true,
},
];
const CustomersData = [
{
"name": "Acme Retail Co",
"email": "ops@acmeretail.com",
"phone": "212-555-0148",
"billing_address": "10 Madison Ave, New York NY 10010",
"shipping_address_default": "500 Warehouse Rd, Secaucus NJ 07094",
"is_active": true,
},
{
"name": "BlueSky Outfitters",
"email": "fulfillment@blueskyoutfitters.com",
"phone": "303-555-0182",
"billing_address": "2200 Market St, Denver CO 80205",
"shipping_address_default": "1800 Commerce Dr, Aurora CO 80011",
"is_active": true,
},
{
"name": "Cedar & Stone",
"email": "orders@cedarandstone.com",
"phone": "512-555-0199",
"billing_address": "77 Congress Ave, Austin TX 78701",
"shipping_address_default": "1400 Distribution Blvd, Round Rock TX 78664",
"is_active": true,
},
];
const CarriersData = [
{
"name": "UPS",
"service_level": "Ground",
"account_number": "UPS-ACCT-20481",
"is_active": true,
},
{
"name": "FedEx",
"service_level": "Home Delivery",
"account_number": "FDX-ACCT-77120",
"is_active": true,
},
{
"name": "USPS",
"service_level": "Priority Mail",
"account_number": "USPS-ACCT-33011",
"is_active": true,
},
];
const InventoryBalancesData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"lot_number": "LOT-TS-2402",
"serial_number": "NA",
"expiration_at": new Date('2028-12-31T00:00:00Z'),
"on_hand_qty": 320,
"reserved_qty": 40,
"available_qty": 280,
"last_counted_at": new Date('2026-02-15T14:00:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"lot_number": "LOT-MG-2401",
"serial_number": "NA",
"expiration_at": new Date('2029-12-31T00:00:00Z'),
"on_hand_qty": 180,
"reserved_qty": 20,
"available_qty": 160,
"last_counted_at": new Date('2026-02-20T10:30:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"lot_number": "LOT-HD-2402",
"serial_number": "NA",
"expiration_at": new Date('2029-12-31T00:00:00Z'),
"on_hand_qty": 95,
"reserved_qty": 10,
"available_qty": 85,
"last_counted_at": new Date('2026-02-22T09:15:00Z'),
},
];
const ReceiptsData = [
{
"receipt_number": "RCPT-10001",
// type code here for "relation_one" field
"vendor_name": "Global Apparel Manufacturing",
"reference_number": "PO-77821",
"status": "receiving",
"expected_at": new Date('2026-02-10T13:00:00Z'),
"received_at": new Date('2026-02-10T15:10:00Z'),
"notes": "Delivered on time, pallet count matched ASN",
// type code here for "relation_one" field
// type code here for "files" field
},
{
"receipt_number": "RCPT-10002",
// type code here for "relation_one" field
"vendor_name": "Stoneware Imports",
"reference_number": "PO-77834",
"status": "expected",
"expected_at": new Date('2026-02-12T13:00:00Z'),
"received_at": new Date('2026-02-12T14:35:00Z'),
"notes": "Minor carton crush, items inspected OK",
// type code here for "relation_one" field
// type code here for "files" field
},
{
"receipt_number": "RCPT-10003",
// type code here for "relation_one" field
"vendor_name": "AudioWorks Supply",
"reference_number": "PO-77850",
"status": "closed",
"expected_at": new Date('2026-03-01T13:00:00Z'),
"received_at": new Date('2026-03-01T13:25:00Z'),
"notes": "Serial numbers being captured during receipt",
// type code here for "relation_one" field
// type code here for "files" field
},
];
const ReceiptLinesData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"expected_qty": 200,
"received_qty": 200,
// type code here for "relation_one" field
"lot_number": "LOT-TS-2402",
"serial_number": "NA",
"expiration_at": new Date('2028-12-31T00:00:00Z'),
"line_notes": "Received 10 cartons",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"expected_qty": 120,
"received_qty": 120,
// type code here for "relation_one" field
"lot_number": "LOT-MG-2401",
"serial_number": "NA",
"expiration_at": new Date('2029-12-31T00:00:00Z'),
"line_notes": "Carton damage noted, no breakage",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"expected_qty": 30,
"received_qty": 10,
// type code here for "relation_one" field
"lot_number": "LOT-HP-2403",
"serial_number": "SN-HP-000873",
"expiration_at": new Date('2029-12-31T00:00:00Z'),
"line_notes": "Partial receipt, remaining due tomorrow",
},
];
const SalesOrdersData = [
{
"order_number": "SO-50001",
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "released",
"priority": "normal",
"order_date": new Date('2026-02-26T09:00:00Z'),
"required_ship_at": new Date('2026-02-28T17:00:00Z'),
"ship_to_name": "Acme Retail Receiving",
"ship_to_address": "500 Warehouse Rd, Secaucus NJ 07094",
"ship_to_phone": "201-555-0119",
"ship_to_email": "receiving@acmeretail.com",
"customer_reference": "ACME-INV-88421",
"notes": "Deliver before 5pm, dock 3",
// type code here for "relation_one" field
},
{
"order_number": "SO-50002",
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "draft",
"priority": "urgent",
"order_date": new Date('2026-02-27T11:30:00Z'),
"required_ship_at": new Date('2026-03-01T17:00:00Z'),
"ship_to_name": "BlueSky Receiving",
"ship_to_address": "1800 Commerce Dr, Aurora CO 80011",
"ship_to_phone": "303-555-0190",
"ship_to_email": "receiving@blueskyoutfitters.com",
"customer_reference": "BSO-PO-77110",
"notes": "Include packing slip in pouch",
// type code here for "relation_one" field
},
{
"order_number": "SO-50003",
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "cancelled",
"priority": "high",
"order_date": new Date('2026-02-27T15:05:00Z'),
"required_ship_at": new Date('2026-03-02T17:00:00Z'),
"ship_to_name": "Cedar and Stone Dock",
"ship_to_address": "1400 Distribution Blvd, Round Rock TX 78664",
"ship_to_phone": "512-555-0133",
"ship_to_email": "dock@cedarandstone.com",
"customer_reference": "CS-44210",
"notes": "Ship in two cartons max if possible",
// type code here for "relation_one" field
},
];
const SalesOrderLinesData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"ordered_qty": 40,
"allocated_qty": 40,
"picked_qty": 0,
"shipped_qty": 0,
"line_notes": "Pick from ECDC-A-01",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"ordered_qty": 25,
"allocated_qty": 25,
"picked_qty": 0,
"shipped_qty": 0,
"line_notes": "Standard pack",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"ordered_qty": 10,
"allocated_qty": 10,
"picked_qty": 6,
"shipped_qty": 0,
"line_notes": "Backorder not allowed",
},
];
const PickListsData = [
{
"pick_list_number": "PICK-70001",
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "released",
// type code here for "relation_one" field
"released_at": new Date('2026-02-26T10:00:00Z'),
"completed_at": new Date('2026-02-26T00:00:00Z'),
"notes": "High priority batch",
},
{
"pick_list_number": "PICK-70002",
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "completed",
// type code here for "relation_one" field
"released_at": new Date('2026-02-27T12:00:00Z'),
"completed_at": new Date('2026-02-27T00:00:00Z'),
"notes": "Pick hoodies first",
},
{
"pick_list_number": "PICK-70003",
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "cancelled",
// type code here for "relation_one" field
"released_at": new Date('2026-02-27T15:30:00Z'),
"completed_at": new Date('2026-02-27T16:10:00Z'),
"notes": "Fragile items",
},
];
const PickListLinesData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"requested_qty": 40,
"picked_qty": 0,
"lot_number": "LOT-TS-2402",
"serial_number": "NA",
"line_status": "cancelled",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"requested_qty": 25,
"picked_qty": 0,
"lot_number": "LOT-WB-2402",
"serial_number": "NA",
"line_status": "short",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"requested_qty": 10,
"picked_qty": 6,
"lot_number": "LOT-HD-2402",
"serial_number": "NA",
"line_status": "cancelled",
},
];
const PackingSlipsData = [
{
"packing_slip_number": "PACK-80001",
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "packed",
// type code here for "relation_one" field
"started_at": new Date('2026-02-26T11:30:00Z'),
"packed_at": new Date('2026-02-26T00:00:00Z'),
"notes": "Awaiting picks",
},
{
"packing_slip_number": "PACK-80002",
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "packed",
// type code here for "relation_one" field
"started_at": new Date('2026-02-27T14:00:00Z'),
"packed_at": new Date('2026-02-27T00:00:00Z'),
"notes": "Include packing slip",
},
{
"packing_slip_number": "PACK-80003",
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "packed",
// type code here for "relation_one" field
"started_at": new Date('2026-02-27T16:15:00Z'),
"packed_at": new Date('2026-02-27T16:45:00Z'),
"notes": "Fragile handling",
},
];
const PackagesData = [
{
// type code here for "relation_one" field
"package_code": "PKG-90001",
"weight_kg": 6.2,
"length_cm": 40,
"width_cm": 30,
"height_cm": 25,
"notes": "Box with dividers",
},
{
// type code here for "relation_one" field
"package_code": "PKG-90002",
"weight_kg": 1.1,
"length_cm": 30,
"width_cm": 22,
"height_cm": 10,
"notes": "Headphones with protective fill",
},
{
// type code here for "relation_one" field
"package_code": "PKG-90003",
"weight_kg": 0.0,
"length_cm": 0,
"width_cm": 0,
"height_cm": 0,
"notes": "To be packed after pick complete",
},
];
const ShipmentsData = [
{
"shipment_number": "SHIP-60001",
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "ready",
"ship_at": new Date('2026-02-25T15:20:00Z'),
"delivered_at": new Date('2026-02-27T19:10:00Z'),
"tracking_number": "FDX9273601123",
// type code here for "relation_one" field
// type code here for "files" field
"notes": "Adult signature requested",
},
{
"shipment_number": "SHIP-60002",
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "delivered",
"ship_at": new Date('2026-02-28T16:00:00Z'),
"delivered_at": new Date('2026-03-03T00:00:00Z'),
"tracking_number": "1Z20481E0301122334",
// type code here for "relation_one" field
// type code here for "files" field
"notes": "Hold for pickup if missed",
},
{
"shipment_number": "SHIP-60003",
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "exception",
"ship_at": new Date('2026-03-01T16:30:00Z'),
"delivered_at": new Date('2026-03-04T00:00:00Z'),
"tracking_number": "9405511202555800012345",
// type code here for "relation_one" field
// type code here for "files" field
"notes": "Address correction required by carrier",
},
];
const ShipmentPackagesData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"tracking_number": "FDX9273601123",
// type code here for "files" field
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"tracking_number": "1Z20481E0301122334",
// type code here for "files" field
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"tracking_number": "1Z20481E0301122334",
// type code here for "files" field
},
];
const StockMovementsData = [
{
"movement_number": "MOVE-30001",
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"movement_type": "putaway",
"qty": 200,
"lot_number": "LOT-TS-2402",
"serial_number": "NA",
"moved_at": new Date('2026-02-10T16:05:00Z'),
// type code here for "relation_one" field
"reference": "RCPT-10001",
"reason": "Putaway from receiving",
},
{
"movement_number": "MOVE-30002",
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"movement_type": "putaway",
"qty": 120,
"lot_number": "LOT-MG-2401",
"serial_number": "NA",
"moved_at": new Date('2026-02-12T15:10:00Z'),
// type code here for "relation_one" field
"reference": "RCPT-10002",
"reason": "Putaway from receiving",
},
{
"movement_number": "MOVE-30003",
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"movement_type": "return",
"qty": 1,
"lot_number": "LOT-HP-2403",
"serial_number": "SN-HP-000873",
"moved_at": new Date('2026-02-25T13:50:00Z'),
// type code here for "relation_one" field
"reference": "SO-50004",
"reason": "Picked for shipment",
},
];
const AuditEventsData = [
{
"event_at": new Date('2026-02-25T13:12:00Z'),
// type code here for "relation_one" field
"entity_name": "sales_orders",
"entity_reference": "SO-50004",
"action": "status_change",
"details": "Order created via EDI import",
"ip_address": "10.10.2.15",
},
{
"event_at": new Date('2026-02-25T15:25:00Z'),
// type code here for "relation_one" field
"entity_name": "shipments",
"entity_reference": "SHIP-60001",
"action": "import",
"details": "Shipment status changed to shipped",
"ip_address": "10.10.2.21",
},
{
"event_at": new Date('2026-02-26T10:05:00Z'),
// type code here for "relation_one" field
"entity_name": "pick_lists",
"entity_reference": "PICK-70001",
"action": "logout",
"details": "Pick list released for SO-50001",
"ip_address": "10.10.2.18",
},
];
// Similar logic for "relation_many"
async function associateLocationWithWarehouse() {
const relatedWarehouse0 = await Warehouses.findOne({
offset: Math.floor(Math.random() * (await Warehouses.count())),
});
const Location0 = await Locations.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Location0?.setWarehouse)
{
await
Location0.
setWarehouse(relatedWarehouse0);
}
const relatedWarehouse1 = await Warehouses.findOne({
offset: Math.floor(Math.random() * (await Warehouses.count())),
});
const Location1 = await Locations.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Location1?.setWarehouse)
{
await
Location1.
setWarehouse(relatedWarehouse1);
}
const relatedWarehouse2 = await Warehouses.findOne({
offset: Math.floor(Math.random() * (await Warehouses.count())),
});
const Location2 = await Locations.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Location2?.setWarehouse)
{
await
Location2.
setWarehouse(relatedWarehouse2);
}
}
async function associateInventoryBalanceWithWarehouse() {
const relatedWarehouse0 = await Warehouses.findOne({
offset: Math.floor(Math.random() * (await Warehouses.count())),
});
const InventoryBalance0 = await InventoryBalances.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (InventoryBalance0?.setWarehouse)
{
await
InventoryBalance0.
setWarehouse(relatedWarehouse0);
}
const relatedWarehouse1 = await Warehouses.findOne({
offset: Math.floor(Math.random() * (await Warehouses.count())),
});
const InventoryBalance1 = await InventoryBalances.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (InventoryBalance1?.setWarehouse)
{
await
InventoryBalance1.
setWarehouse(relatedWarehouse1);
}
const relatedWarehouse2 = await Warehouses.findOne({
offset: Math.floor(Math.random() * (await Warehouses.count())),
});
const InventoryBalance2 = await InventoryBalances.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (InventoryBalance2?.setWarehouse)
{
await
InventoryBalance2.
setWarehouse(relatedWarehouse2);
}
}
async function associateInventoryBalanceWithLocation() {
const relatedLocation0 = await Locations.findOne({
offset: Math.floor(Math.random() * (await Locations.count())),
});
const InventoryBalance0 = await InventoryBalances.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (InventoryBalance0?.setLocation)
{
await
InventoryBalance0.
setLocation(relatedLocation0);
}
const relatedLocation1 = await Locations.findOne({
offset: Math.floor(Math.random() * (await Locations.count())),
});
const InventoryBalance1 = await InventoryBalances.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (InventoryBalance1?.setLocation)
{
await
InventoryBalance1.
setLocation(relatedLocation1);
}
const relatedLocation2 = await Locations.findOne({
offset: Math.floor(Math.random() * (await Locations.count())),
});
const InventoryBalance2 = await InventoryBalances.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (InventoryBalance2?.setLocation)
{
await
InventoryBalance2.
setLocation(relatedLocation2);
}
}
async function associateInventoryBalanceWithProduct() {
const relatedProduct0 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const InventoryBalance0 = await InventoryBalances.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (InventoryBalance0?.setProduct)
{
await
InventoryBalance0.
setProduct(relatedProduct0);
}
const relatedProduct1 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const InventoryBalance1 = await InventoryBalances.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (InventoryBalance1?.setProduct)
{
await
InventoryBalance1.
setProduct(relatedProduct1);
}
const relatedProduct2 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const InventoryBalance2 = await InventoryBalances.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (InventoryBalance2?.setProduct)
{
await
InventoryBalance2.
setProduct(relatedProduct2);
}
}
async function associateReceiptWithWarehouse() {
const relatedWarehouse0 = await Warehouses.findOne({
offset: Math.floor(Math.random() * (await Warehouses.count())),
});
const Receipt0 = await Receipts.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Receipt0?.setWarehouse)
{
await
Receipt0.
setWarehouse(relatedWarehouse0);
}
const relatedWarehouse1 = await Warehouses.findOne({
offset: Math.floor(Math.random() * (await Warehouses.count())),
});
const Receipt1 = await Receipts.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Receipt1?.setWarehouse)
{
await
Receipt1.
setWarehouse(relatedWarehouse1);
}
const relatedWarehouse2 = await Warehouses.findOne({
offset: Math.floor(Math.random() * (await Warehouses.count())),
});
const Receipt2 = await Receipts.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Receipt2?.setWarehouse)
{
await
Receipt2.
setWarehouse(relatedWarehouse2);
}
}
async function associateReceiptWithReceived_by_user() {
const relatedReceived_by_user0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Receipt0 = await Receipts.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Receipt0?.setReceived_by_user)
{
await
Receipt0.
setReceived_by_user(relatedReceived_by_user0);
}
const relatedReceived_by_user1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Receipt1 = await Receipts.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Receipt1?.setReceived_by_user)
{
await
Receipt1.
setReceived_by_user(relatedReceived_by_user1);
}
const relatedReceived_by_user2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Receipt2 = await Receipts.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Receipt2?.setReceived_by_user)
{
await
Receipt2.
setReceived_by_user(relatedReceived_by_user2);
}
}
async function associateReceiptLineWithReceipt() {
const relatedReceipt0 = await Receipts.findOne({
offset: Math.floor(Math.random() * (await Receipts.count())),
});
const ReceiptLine0 = await ReceiptLines.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ReceiptLine0?.setReceipt)
{
await
ReceiptLine0.
setReceipt(relatedReceipt0);
}
const relatedReceipt1 = await Receipts.findOne({
offset: Math.floor(Math.random() * (await Receipts.count())),
});
const ReceiptLine1 = await ReceiptLines.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ReceiptLine1?.setReceipt)
{
await
ReceiptLine1.
setReceipt(relatedReceipt1);
}
const relatedReceipt2 = await Receipts.findOne({
offset: Math.floor(Math.random() * (await Receipts.count())),
});
const ReceiptLine2 = await ReceiptLines.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ReceiptLine2?.setReceipt)
{
await
ReceiptLine2.
setReceipt(relatedReceipt2);
}
}
async function associateReceiptLineWithProduct() {
const relatedProduct0 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const ReceiptLine0 = await ReceiptLines.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ReceiptLine0?.setProduct)
{
await
ReceiptLine0.
setProduct(relatedProduct0);
}
const relatedProduct1 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const ReceiptLine1 = await ReceiptLines.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ReceiptLine1?.setProduct)
{
await
ReceiptLine1.
setProduct(relatedProduct1);
}
const relatedProduct2 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const ReceiptLine2 = await ReceiptLines.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ReceiptLine2?.setProduct)
{
await
ReceiptLine2.
setProduct(relatedProduct2);
}
}
async function associateReceiptLineWithPutaway_location() {
const relatedPutaway_location0 = await Locations.findOne({
offset: Math.floor(Math.random() * (await Locations.count())),
});
const ReceiptLine0 = await ReceiptLines.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ReceiptLine0?.setPutaway_location)
{
await
ReceiptLine0.
setPutaway_location(relatedPutaway_location0);
}
const relatedPutaway_location1 = await Locations.findOne({
offset: Math.floor(Math.random() * (await Locations.count())),
});
const ReceiptLine1 = await ReceiptLines.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ReceiptLine1?.setPutaway_location)
{
await
ReceiptLine1.
setPutaway_location(relatedPutaway_location1);
}
const relatedPutaway_location2 = await Locations.findOne({
offset: Math.floor(Math.random() * (await Locations.count())),
});
const ReceiptLine2 = await ReceiptLines.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ReceiptLine2?.setPutaway_location)
{
await
ReceiptLine2.
setPutaway_location(relatedPutaway_location2);
}
}
async function associateSalesOrderWithCustomer() {
const relatedCustomer0 = await Customers.findOne({
offset: Math.floor(Math.random() * (await Customers.count())),
});
const SalesOrder0 = await SalesOrders.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (SalesOrder0?.setCustomer)
{
await
SalesOrder0.
setCustomer(relatedCustomer0);
}
const relatedCustomer1 = await Customers.findOne({
offset: Math.floor(Math.random() * (await Customers.count())),
});
const SalesOrder1 = await SalesOrders.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (SalesOrder1?.setCustomer)
{
await
SalesOrder1.
setCustomer(relatedCustomer1);
}
const relatedCustomer2 = await Customers.findOne({
offset: Math.floor(Math.random() * (await Customers.count())),
});
const SalesOrder2 = await SalesOrders.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (SalesOrder2?.setCustomer)
{
await
SalesOrder2.
setCustomer(relatedCustomer2);
}
}
async function associateSalesOrderWithWarehouse() {
const relatedWarehouse0 = await Warehouses.findOne({
offset: Math.floor(Math.random() * (await Warehouses.count())),
});
const SalesOrder0 = await SalesOrders.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (SalesOrder0?.setWarehouse)
{
await
SalesOrder0.
setWarehouse(relatedWarehouse0);
}
const relatedWarehouse1 = await Warehouses.findOne({
offset: Math.floor(Math.random() * (await Warehouses.count())),
});
const SalesOrder1 = await SalesOrders.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (SalesOrder1?.setWarehouse)
{
await
SalesOrder1.
setWarehouse(relatedWarehouse1);
}
const relatedWarehouse2 = await Warehouses.findOne({
offset: Math.floor(Math.random() * (await Warehouses.count())),
});
const SalesOrder2 = await SalesOrders.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (SalesOrder2?.setWarehouse)
{
await
SalesOrder2.
setWarehouse(relatedWarehouse2);
}
}
async function associateSalesOrderWithAssigned_to_user() {
const relatedAssigned_to_user0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const SalesOrder0 = await SalesOrders.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (SalesOrder0?.setAssigned_to_user)
{
await
SalesOrder0.
setAssigned_to_user(relatedAssigned_to_user0);
}
const relatedAssigned_to_user1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const SalesOrder1 = await SalesOrders.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (SalesOrder1?.setAssigned_to_user)
{
await
SalesOrder1.
setAssigned_to_user(relatedAssigned_to_user1);
}
const relatedAssigned_to_user2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const SalesOrder2 = await SalesOrders.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (SalesOrder2?.setAssigned_to_user)
{
await
SalesOrder2.
setAssigned_to_user(relatedAssigned_to_user2);
}
}
async function associateSalesOrderLineWithSales_order() {
const relatedSales_order0 = await SalesOrders.findOne({
offset: Math.floor(Math.random() * (await SalesOrders.count())),
});
const SalesOrderLine0 = await SalesOrderLines.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (SalesOrderLine0?.setSales_order)
{
await
SalesOrderLine0.
setSales_order(relatedSales_order0);
}
const relatedSales_order1 = await SalesOrders.findOne({
offset: Math.floor(Math.random() * (await SalesOrders.count())),
});
const SalesOrderLine1 = await SalesOrderLines.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (SalesOrderLine1?.setSales_order)
{
await
SalesOrderLine1.
setSales_order(relatedSales_order1);
}
const relatedSales_order2 = await SalesOrders.findOne({
offset: Math.floor(Math.random() * (await SalesOrders.count())),
});
const SalesOrderLine2 = await SalesOrderLines.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (SalesOrderLine2?.setSales_order)
{
await
SalesOrderLine2.
setSales_order(relatedSales_order2);
}
}
async function associateSalesOrderLineWithProduct() {
const relatedProduct0 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const SalesOrderLine0 = await SalesOrderLines.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (SalesOrderLine0?.setProduct)
{
await
SalesOrderLine0.
setProduct(relatedProduct0);
}
const relatedProduct1 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const SalesOrderLine1 = await SalesOrderLines.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (SalesOrderLine1?.setProduct)
{
await
SalesOrderLine1.
setProduct(relatedProduct1);
}
const relatedProduct2 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const SalesOrderLine2 = await SalesOrderLines.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (SalesOrderLine2?.setProduct)
{
await
SalesOrderLine2.
setProduct(relatedProduct2);
}
}
async function associatePickListWithWarehouse() {
const relatedWarehouse0 = await Warehouses.findOne({
offset: Math.floor(Math.random() * (await Warehouses.count())),
});
const PickList0 = await PickLists.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (PickList0?.setWarehouse)
{
await
PickList0.
setWarehouse(relatedWarehouse0);
}
const relatedWarehouse1 = await Warehouses.findOne({
offset: Math.floor(Math.random() * (await Warehouses.count())),
});
const PickList1 = await PickLists.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (PickList1?.setWarehouse)
{
await
PickList1.
setWarehouse(relatedWarehouse1);
}
const relatedWarehouse2 = await Warehouses.findOne({
offset: Math.floor(Math.random() * (await Warehouses.count())),
});
const PickList2 = await PickLists.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (PickList2?.setWarehouse)
{
await
PickList2.
setWarehouse(relatedWarehouse2);
}
}
async function associatePickListWithSales_order() {
const relatedSales_order0 = await SalesOrders.findOne({
offset: Math.floor(Math.random() * (await SalesOrders.count())),
});
const PickList0 = await PickLists.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (PickList0?.setSales_order)
{
await
PickList0.
setSales_order(relatedSales_order0);
}
const relatedSales_order1 = await SalesOrders.findOne({
offset: Math.floor(Math.random() * (await SalesOrders.count())),
});
const PickList1 = await PickLists.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (PickList1?.setSales_order)
{
await
PickList1.
setSales_order(relatedSales_order1);
}
const relatedSales_order2 = await SalesOrders.findOne({
offset: Math.floor(Math.random() * (await SalesOrders.count())),
});
const PickList2 = await PickLists.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (PickList2?.setSales_order)
{
await
PickList2.
setSales_order(relatedSales_order2);
}
}
async function associatePickListWithPicker_user() {
const relatedPicker_user0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const PickList0 = await PickLists.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (PickList0?.setPicker_user)
{
await
PickList0.
setPicker_user(relatedPicker_user0);
}
const relatedPicker_user1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const PickList1 = await PickLists.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (PickList1?.setPicker_user)
{
await
PickList1.
setPicker_user(relatedPicker_user1);
}
const relatedPicker_user2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const PickList2 = await PickLists.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (PickList2?.setPicker_user)
{
await
PickList2.
setPicker_user(relatedPicker_user2);
}
}
async function associatePickListLineWithPick_list() {
const relatedPick_list0 = await PickLists.findOne({
offset: Math.floor(Math.random() * (await PickLists.count())),
});
const PickListLine0 = await PickListLines.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (PickListLine0?.setPick_list)
{
await
PickListLine0.
setPick_list(relatedPick_list0);
}
const relatedPick_list1 = await PickLists.findOne({
offset: Math.floor(Math.random() * (await PickLists.count())),
});
const PickListLine1 = await PickListLines.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (PickListLine1?.setPick_list)
{
await
PickListLine1.
setPick_list(relatedPick_list1);
}
const relatedPick_list2 = await PickLists.findOne({
offset: Math.floor(Math.random() * (await PickLists.count())),
});
const PickListLine2 = await PickListLines.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (PickListLine2?.setPick_list)
{
await
PickListLine2.
setPick_list(relatedPick_list2);
}
}
async function associatePickListLineWithSales_order_line() {
const relatedSales_order_line0 = await SalesOrderLines.findOne({
offset: Math.floor(Math.random() * (await SalesOrderLines.count())),
});
const PickListLine0 = await PickListLines.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (PickListLine0?.setSales_order_line)
{
await
PickListLine0.
setSales_order_line(relatedSales_order_line0);
}
const relatedSales_order_line1 = await SalesOrderLines.findOne({
offset: Math.floor(Math.random() * (await SalesOrderLines.count())),
});
const PickListLine1 = await PickListLines.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (PickListLine1?.setSales_order_line)
{
await
PickListLine1.
setSales_order_line(relatedSales_order_line1);
}
const relatedSales_order_line2 = await SalesOrderLines.findOne({
offset: Math.floor(Math.random() * (await SalesOrderLines.count())),
});
const PickListLine2 = await PickListLines.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (PickListLine2?.setSales_order_line)
{
await
PickListLine2.
setSales_order_line(relatedSales_order_line2);
}
}
async function associatePickListLineWithProduct() {
const relatedProduct0 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const PickListLine0 = await PickListLines.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (PickListLine0?.setProduct)
{
await
PickListLine0.
setProduct(relatedProduct0);
}
const relatedProduct1 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const PickListLine1 = await PickListLines.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (PickListLine1?.setProduct)
{
await
PickListLine1.
setProduct(relatedProduct1);
}
const relatedProduct2 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const PickListLine2 = await PickListLines.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (PickListLine2?.setProduct)
{
await
PickListLine2.
setProduct(relatedProduct2);
}
}
async function associatePickListLineWithFrom_location() {
const relatedFrom_location0 = await Locations.findOne({
offset: Math.floor(Math.random() * (await Locations.count())),
});
const PickListLine0 = await PickListLines.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (PickListLine0?.setFrom_location)
{
await
PickListLine0.
setFrom_location(relatedFrom_location0);
}
const relatedFrom_location1 = await Locations.findOne({
offset: Math.floor(Math.random() * (await Locations.count())),
});
const PickListLine1 = await PickListLines.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (PickListLine1?.setFrom_location)
{
await
PickListLine1.
setFrom_location(relatedFrom_location1);
}
const relatedFrom_location2 = await Locations.findOne({
offset: Math.floor(Math.random() * (await Locations.count())),
});
const PickListLine2 = await PickListLines.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (PickListLine2?.setFrom_location)
{
await
PickListLine2.
setFrom_location(relatedFrom_location2);
}
}
async function associatePackingSlipWithWarehouse() {
const relatedWarehouse0 = await Warehouses.findOne({
offset: Math.floor(Math.random() * (await Warehouses.count())),
});
const PackingSlip0 = await PackingSlips.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (PackingSlip0?.setWarehouse)
{
await
PackingSlip0.
setWarehouse(relatedWarehouse0);
}
const relatedWarehouse1 = await Warehouses.findOne({
offset: Math.floor(Math.random() * (await Warehouses.count())),
});
const PackingSlip1 = await PackingSlips.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (PackingSlip1?.setWarehouse)
{
await
PackingSlip1.
setWarehouse(relatedWarehouse1);
}
const relatedWarehouse2 = await Warehouses.findOne({
offset: Math.floor(Math.random() * (await Warehouses.count())),
});
const PackingSlip2 = await PackingSlips.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (PackingSlip2?.setWarehouse)
{
await
PackingSlip2.
setWarehouse(relatedWarehouse2);
}
}
async function associatePackingSlipWithSales_order() {
const relatedSales_order0 = await SalesOrders.findOne({
offset: Math.floor(Math.random() * (await SalesOrders.count())),
});
const PackingSlip0 = await PackingSlips.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (PackingSlip0?.setSales_order)
{
await
PackingSlip0.
setSales_order(relatedSales_order0);
}
const relatedSales_order1 = await SalesOrders.findOne({
offset: Math.floor(Math.random() * (await SalesOrders.count())),
});
const PackingSlip1 = await PackingSlips.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (PackingSlip1?.setSales_order)
{
await
PackingSlip1.
setSales_order(relatedSales_order1);
}
const relatedSales_order2 = await SalesOrders.findOne({
offset: Math.floor(Math.random() * (await SalesOrders.count())),
});
const PackingSlip2 = await PackingSlips.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (PackingSlip2?.setSales_order)
{
await
PackingSlip2.
setSales_order(relatedSales_order2);
}
}
async function associatePackingSlipWithPacker_user() {
const relatedPacker_user0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const PackingSlip0 = await PackingSlips.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (PackingSlip0?.setPacker_user)
{
await
PackingSlip0.
setPacker_user(relatedPacker_user0);
}
const relatedPacker_user1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const PackingSlip1 = await PackingSlips.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (PackingSlip1?.setPacker_user)
{
await
PackingSlip1.
setPacker_user(relatedPacker_user1);
}
const relatedPacker_user2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const PackingSlip2 = await PackingSlips.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (PackingSlip2?.setPacker_user)
{
await
PackingSlip2.
setPacker_user(relatedPacker_user2);
}
}
async function associatePackageWithPacking_slip() {
const relatedPacking_slip0 = await PackingSlips.findOne({
offset: Math.floor(Math.random() * (await PackingSlips.count())),
});
const Package0 = await Packages.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Package0?.setPacking_slip)
{
await
Package0.
setPacking_slip(relatedPacking_slip0);
}
const relatedPacking_slip1 = await PackingSlips.findOne({
offset: Math.floor(Math.random() * (await PackingSlips.count())),
});
const Package1 = await Packages.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Package1?.setPacking_slip)
{
await
Package1.
setPacking_slip(relatedPacking_slip1);
}
const relatedPacking_slip2 = await PackingSlips.findOne({
offset: Math.floor(Math.random() * (await PackingSlips.count())),
});
const Package2 = await Packages.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Package2?.setPacking_slip)
{
await
Package2.
setPacking_slip(relatedPacking_slip2);
}
}
async function associateShipmentWithWarehouse() {
const relatedWarehouse0 = await Warehouses.findOne({
offset: Math.floor(Math.random() * (await Warehouses.count())),
});
const Shipment0 = await Shipments.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Shipment0?.setWarehouse)
{
await
Shipment0.
setWarehouse(relatedWarehouse0);
}
const relatedWarehouse1 = await Warehouses.findOne({
offset: Math.floor(Math.random() * (await Warehouses.count())),
});
const Shipment1 = await Shipments.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Shipment1?.setWarehouse)
{
await
Shipment1.
setWarehouse(relatedWarehouse1);
}
const relatedWarehouse2 = await Warehouses.findOne({
offset: Math.floor(Math.random() * (await Warehouses.count())),
});
const Shipment2 = await Shipments.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Shipment2?.setWarehouse)
{
await
Shipment2.
setWarehouse(relatedWarehouse2);
}
}
async function associateShipmentWithSales_order() {
const relatedSales_order0 = await SalesOrders.findOne({
offset: Math.floor(Math.random() * (await SalesOrders.count())),
});
const Shipment0 = await Shipments.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Shipment0?.setSales_order)
{
await
Shipment0.
setSales_order(relatedSales_order0);
}
const relatedSales_order1 = await SalesOrders.findOne({
offset: Math.floor(Math.random() * (await SalesOrders.count())),
});
const Shipment1 = await Shipments.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Shipment1?.setSales_order)
{
await
Shipment1.
setSales_order(relatedSales_order1);
}
const relatedSales_order2 = await SalesOrders.findOne({
offset: Math.floor(Math.random() * (await SalesOrders.count())),
});
const Shipment2 = await Shipments.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Shipment2?.setSales_order)
{
await
Shipment2.
setSales_order(relatedSales_order2);
}
}
async function associateShipmentWithCarrier() {
const relatedCarrier0 = await Carriers.findOne({
offset: Math.floor(Math.random() * (await Carriers.count())),
});
const Shipment0 = await Shipments.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Shipment0?.setCarrier)
{
await
Shipment0.
setCarrier(relatedCarrier0);
}
const relatedCarrier1 = await Carriers.findOne({
offset: Math.floor(Math.random() * (await Carriers.count())),
});
const Shipment1 = await Shipments.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Shipment1?.setCarrier)
{
await
Shipment1.
setCarrier(relatedCarrier1);
}
const relatedCarrier2 = await Carriers.findOne({
offset: Math.floor(Math.random() * (await Carriers.count())),
});
const Shipment2 = await Shipments.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Shipment2?.setCarrier)
{
await
Shipment2.
setCarrier(relatedCarrier2);
}
}
async function associateShipmentWithShipped_by_user() {
const relatedShipped_by_user0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Shipment0 = await Shipments.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Shipment0?.setShipped_by_user)
{
await
Shipment0.
setShipped_by_user(relatedShipped_by_user0);
}
const relatedShipped_by_user1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Shipment1 = await Shipments.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Shipment1?.setShipped_by_user)
{
await
Shipment1.
setShipped_by_user(relatedShipped_by_user1);
}
const relatedShipped_by_user2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Shipment2 = await Shipments.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Shipment2?.setShipped_by_user)
{
await
Shipment2.
setShipped_by_user(relatedShipped_by_user2);
}
}
async function associateShipmentPackageWithShipment() {
const relatedShipment0 = await Shipments.findOne({
offset: Math.floor(Math.random() * (await Shipments.count())),
});
const ShipmentPackage0 = await ShipmentPackages.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ShipmentPackage0?.setShipment)
{
await
ShipmentPackage0.
setShipment(relatedShipment0);
}
const relatedShipment1 = await Shipments.findOne({
offset: Math.floor(Math.random() * (await Shipments.count())),
});
const ShipmentPackage1 = await ShipmentPackages.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ShipmentPackage1?.setShipment)
{
await
ShipmentPackage1.
setShipment(relatedShipment1);
}
const relatedShipment2 = await Shipments.findOne({
offset: Math.floor(Math.random() * (await Shipments.count())),
});
const ShipmentPackage2 = await ShipmentPackages.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ShipmentPackage2?.setShipment)
{
await
ShipmentPackage2.
setShipment(relatedShipment2);
}
}
async function associateShipmentPackageWithPackage() {
const relatedPackage0 = await Packages.findOne({
offset: Math.floor(Math.random() * (await Packages.count())),
});
const ShipmentPackage0 = await ShipmentPackages.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ShipmentPackage0?.setPackage)
{
await
ShipmentPackage0.
setPackage(relatedPackage0);
}
const relatedPackage1 = await Packages.findOne({
offset: Math.floor(Math.random() * (await Packages.count())),
});
const ShipmentPackage1 = await ShipmentPackages.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ShipmentPackage1?.setPackage)
{
await
ShipmentPackage1.
setPackage(relatedPackage1);
}
const relatedPackage2 = await Packages.findOne({
offset: Math.floor(Math.random() * (await Packages.count())),
});
const ShipmentPackage2 = await ShipmentPackages.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ShipmentPackage2?.setPackage)
{
await
ShipmentPackage2.
setPackage(relatedPackage2);
}
}
async function associateStockMovementWithWarehouse() {
const relatedWarehouse0 = await Warehouses.findOne({
offset: Math.floor(Math.random() * (await Warehouses.count())),
});
const StockMovement0 = await StockMovements.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (StockMovement0?.setWarehouse)
{
await
StockMovement0.
setWarehouse(relatedWarehouse0);
}
const relatedWarehouse1 = await Warehouses.findOne({
offset: Math.floor(Math.random() * (await Warehouses.count())),
});
const StockMovement1 = await StockMovements.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (StockMovement1?.setWarehouse)
{
await
StockMovement1.
setWarehouse(relatedWarehouse1);
}
const relatedWarehouse2 = await Warehouses.findOne({
offset: Math.floor(Math.random() * (await Warehouses.count())),
});
const StockMovement2 = await StockMovements.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (StockMovement2?.setWarehouse)
{
await
StockMovement2.
setWarehouse(relatedWarehouse2);
}
}
async function associateStockMovementWithProduct() {
const relatedProduct0 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const StockMovement0 = await StockMovements.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (StockMovement0?.setProduct)
{
await
StockMovement0.
setProduct(relatedProduct0);
}
const relatedProduct1 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const StockMovement1 = await StockMovements.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (StockMovement1?.setProduct)
{
await
StockMovement1.
setProduct(relatedProduct1);
}
const relatedProduct2 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const StockMovement2 = await StockMovements.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (StockMovement2?.setProduct)
{
await
StockMovement2.
setProduct(relatedProduct2);
}
}
async function associateStockMovementWithFrom_location() {
const relatedFrom_location0 = await Locations.findOne({
offset: Math.floor(Math.random() * (await Locations.count())),
});
const StockMovement0 = await StockMovements.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (StockMovement0?.setFrom_location)
{
await
StockMovement0.
setFrom_location(relatedFrom_location0);
}
const relatedFrom_location1 = await Locations.findOne({
offset: Math.floor(Math.random() * (await Locations.count())),
});
const StockMovement1 = await StockMovements.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (StockMovement1?.setFrom_location)
{
await
StockMovement1.
setFrom_location(relatedFrom_location1);
}
const relatedFrom_location2 = await Locations.findOne({
offset: Math.floor(Math.random() * (await Locations.count())),
});
const StockMovement2 = await StockMovements.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (StockMovement2?.setFrom_location)
{
await
StockMovement2.
setFrom_location(relatedFrom_location2);
}
}
async function associateStockMovementWithTo_location() {
const relatedTo_location0 = await Locations.findOne({
offset: Math.floor(Math.random() * (await Locations.count())),
});
const StockMovement0 = await StockMovements.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (StockMovement0?.setTo_location)
{
await
StockMovement0.
setTo_location(relatedTo_location0);
}
const relatedTo_location1 = await Locations.findOne({
offset: Math.floor(Math.random() * (await Locations.count())),
});
const StockMovement1 = await StockMovements.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (StockMovement1?.setTo_location)
{
await
StockMovement1.
setTo_location(relatedTo_location1);
}
const relatedTo_location2 = await Locations.findOne({
offset: Math.floor(Math.random() * (await Locations.count())),
});
const StockMovement2 = await StockMovements.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (StockMovement2?.setTo_location)
{
await
StockMovement2.
setTo_location(relatedTo_location2);
}
}
async function associateStockMovementWithPerformed_by_user() {
const relatedPerformed_by_user0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const StockMovement0 = await StockMovements.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (StockMovement0?.setPerformed_by_user)
{
await
StockMovement0.
setPerformed_by_user(relatedPerformed_by_user0);
}
const relatedPerformed_by_user1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const StockMovement1 = await StockMovements.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (StockMovement1?.setPerformed_by_user)
{
await
StockMovement1.
setPerformed_by_user(relatedPerformed_by_user1);
}
const relatedPerformed_by_user2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const StockMovement2 = await StockMovements.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (StockMovement2?.setPerformed_by_user)
{
await
StockMovement2.
setPerformed_by_user(relatedPerformed_by_user2);
}
}
async function associateAuditEventWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const AuditEvent0 = await AuditEvents.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (AuditEvent0?.setUser)
{
await
AuditEvent0.
setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const AuditEvent1 = await AuditEvents.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (AuditEvent1?.setUser)
{
await
AuditEvent1.
setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const AuditEvent2 = await AuditEvents.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (AuditEvent2?.setUser)
{
await
AuditEvent2.
setUser(relatedUser2);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Warehouses.bulkCreate(WarehousesData);
await Locations.bulkCreate(LocationsData);
await Products.bulkCreate(ProductsData);
await Customers.bulkCreate(CustomersData);
await Carriers.bulkCreate(CarriersData);
await InventoryBalances.bulkCreate(InventoryBalancesData);
await Receipts.bulkCreate(ReceiptsData);
await ReceiptLines.bulkCreate(ReceiptLinesData);
await SalesOrders.bulkCreate(SalesOrdersData);
await SalesOrderLines.bulkCreate(SalesOrderLinesData);
await PickLists.bulkCreate(PickListsData);
await PickListLines.bulkCreate(PickListLinesData);
await PackingSlips.bulkCreate(PackingSlipsData);
await Packages.bulkCreate(PackagesData);
await Shipments.bulkCreate(ShipmentsData);
await ShipmentPackages.bulkCreate(ShipmentPackagesData);
await StockMovements.bulkCreate(StockMovementsData);
await AuditEvents.bulkCreate(AuditEventsData);
await Promise.all([
// Similar logic for "relation_many"
await associateLocationWithWarehouse(),
await associateInventoryBalanceWithWarehouse(),
await associateInventoryBalanceWithLocation(),
await associateInventoryBalanceWithProduct(),
await associateReceiptWithWarehouse(),
await associateReceiptWithReceived_by_user(),
await associateReceiptLineWithReceipt(),
await associateReceiptLineWithProduct(),
await associateReceiptLineWithPutaway_location(),
await associateSalesOrderWithCustomer(),
await associateSalesOrderWithWarehouse(),
await associateSalesOrderWithAssigned_to_user(),
await associateSalesOrderLineWithSales_order(),
await associateSalesOrderLineWithProduct(),
await associatePickListWithWarehouse(),
await associatePickListWithSales_order(),
await associatePickListWithPicker_user(),
await associatePickListLineWithPick_list(),
await associatePickListLineWithSales_order_line(),
await associatePickListLineWithProduct(),
await associatePickListLineWithFrom_location(),
await associatePackingSlipWithWarehouse(),
await associatePackingSlipWithSales_order(),
await associatePackingSlipWithPacker_user(),
await associatePackageWithPacking_slip(),
await associateShipmentWithWarehouse(),
await associateShipmentWithSales_order(),
await associateShipmentWithCarrier(),
await associateShipmentWithShipped_by_user(),
await associateShipmentPackageWithShipment(),
await associateShipmentPackageWithPackage(),
await associateStockMovementWithWarehouse(),
await associateStockMovementWithProduct(),
await associateStockMovementWithFrom_location(),
await associateStockMovementWithTo_location(),
await associateStockMovementWithPerformed_by_user(),
await associateAuditEventWithUser(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('warehouses', null, {});
await queryInterface.bulkDelete('locations', null, {});
await queryInterface.bulkDelete('products', null, {});
await queryInterface.bulkDelete('customers', null, {});
await queryInterface.bulkDelete('carriers', null, {});
await queryInterface.bulkDelete('inventory_balances', null, {});
await queryInterface.bulkDelete('receipts', null, {});
await queryInterface.bulkDelete('receipt_lines', null, {});
await queryInterface.bulkDelete('sales_orders', null, {});
await queryInterface.bulkDelete('sales_order_lines', null, {});
await queryInterface.bulkDelete('pick_lists', null, {});
await queryInterface.bulkDelete('pick_list_lines', null, {});
await queryInterface.bulkDelete('packing_slips', null, {});
await queryInterface.bulkDelete('packages', null, {});
await queryInterface.bulkDelete('shipments', null, {});
await queryInterface.bulkDelete('shipment_packages', null, {});
await queryInterface.bulkDelete('stock_movements', null, {});
await queryInterface.bulkDelete('audit_events', null, {});
},
};