Compare commits
2 Commits
5be5644329
...
1aa1582682
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1aa1582682 | ||
|
|
be834412e7 |
@@ -138,6 +138,11 @@ export async function executeCompanyImport({
|
||||
// #endregion
|
||||
|
||||
// MARK: - Phase 3: Articles (base data, variants, pfand, pictures)
|
||||
// Articles with stock tracking require at least one warehouse; create a default one implicitly.
|
||||
const existingWarehouses = await store.warehouse.list(googleAuthId);
|
||||
if (!existingWarehouses || existingWarehouses.length === 0) {
|
||||
await store.warehouse.create(googleAuthId, { name: 'Standardlager' });
|
||||
}
|
||||
// #region Phase 3: Articles
|
||||
const articlesResult = await importArticles({
|
||||
store,
|
||||
|
||||
@@ -203,7 +203,7 @@ export async function importOrders({
|
||||
log.warn('Could not list carriers:', err.message);
|
||||
}
|
||||
|
||||
const resolveCarrierId = async (name) => {
|
||||
const resolveCarrierId = async (name, { hasPackages = true } = {}) => {
|
||||
const cleanName = (name || '').trim() || 'Standard';
|
||||
const key = cleanName.toLowerCase();
|
||||
if (carrierMap.has(key)) return carrierMap.get(key);
|
||||
@@ -211,7 +211,7 @@ export async function importOrders({
|
||||
try {
|
||||
const carrier = await store.carrier.create(googleAuthId, {
|
||||
name: cleanName,
|
||||
hasPackages: true,
|
||||
hasPackages,
|
||||
});
|
||||
carrierMap.set(key, carrier.id);
|
||||
return carrier.id;
|
||||
@@ -379,31 +379,31 @@ export async function importOrders({
|
||||
const isSelbstabholer = (shippingType || '').trim().toLowerCase() === 'selbstabholer';
|
||||
const deliveryState = isShipped ? 'delivered' : 'new';
|
||||
|
||||
const shipment = await store.shipment.create(googleAuthId, {
|
||||
const trackingCode = isSelbstabholer
|
||||
? ''
|
||||
: cleanValue(m.trackingCode ?? m.tracking_code ?? m.cTracking);
|
||||
const carrierName = isSelbstabholer
|
||||
? 'Selbstabholer'
|
||||
: cleanValue(m.carrier ?? m.cCarrier) || 'Standard';
|
||||
const carrierId = await resolveCarrierId(carrierName, { hasPackages: !isSelbstabholer });
|
||||
if (!carrierId) {
|
||||
throw new Error(`Could not resolve carrier "${carrierName}"`);
|
||||
}
|
||||
|
||||
await store.shipment.create(googleAuthId, {
|
||||
orderId: createdOrder.id,
|
||||
date: validDate,
|
||||
state: deliveryState,
|
||||
lines: shippableLines,
|
||||
shipping: {
|
||||
carrierId,
|
||||
type: shippingType || 'standard',
|
||||
state: isShipped ? 'shipped' : 'draft',
|
||||
trackingCode: trackingCode || undefined,
|
||||
warehouseId: defaultWarehouseId || undefined,
|
||||
},
|
||||
});
|
||||
|
||||
if (!isSelbstabholer) {
|
||||
const trackingCode = cleanValue(m.trackingCode ?? m.tracking_code ?? m.cTracking);
|
||||
const carrierName = cleanValue(m.carrier ?? m.cCarrier) || 'Standard';
|
||||
const carrierId = await resolveCarrierId(carrierName);
|
||||
const shippingState = isShipped ? 'shipped' : 'draft';
|
||||
|
||||
if (carrierId) {
|
||||
await store.shipping.create(googleAuthId, {
|
||||
manifestId: shipment.id,
|
||||
carrierId,
|
||||
type: shippingType || 'standard',
|
||||
state: shippingState,
|
||||
trackingCode: trackingCode || undefined,
|
||||
warehouseId: defaultWarehouseId || undefined,
|
||||
});
|
||||
shippingsImported++;
|
||||
}
|
||||
}
|
||||
shippingsImported++;
|
||||
} catch (err) {
|
||||
log.warn(`Failed to create shipment/shipping for order ${orderNumber}:`, err.message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user