Compare commits

...

2 Commits

Author SHA1 Message Date
seb
1aa1582682 u 2026-10-21 11:59:39 +02:00
seb
be834412e7 u 2026-10-21 11:55:19 +02:00
2 changed files with 27 additions and 22 deletions

View File

@@ -138,6 +138,11 @@ export async function executeCompanyImport({
// #endregion // #endregion
// MARK: - Phase 3: Articles (base data, variants, pfand, pictures) // 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 // #region Phase 3: Articles
const articlesResult = await importArticles({ const articlesResult = await importArticles({
store, store,

View File

@@ -203,7 +203,7 @@ export async function importOrders({
log.warn('Could not list carriers:', err.message); log.warn('Could not list carriers:', err.message);
} }
const resolveCarrierId = async (name) => { const resolveCarrierId = async (name, { hasPackages = true } = {}) => {
const cleanName = (name || '').trim() || 'Standard'; const cleanName = (name || '').trim() || 'Standard';
const key = cleanName.toLowerCase(); const key = cleanName.toLowerCase();
if (carrierMap.has(key)) return carrierMap.get(key); if (carrierMap.has(key)) return carrierMap.get(key);
@@ -211,7 +211,7 @@ export async function importOrders({
try { try {
const carrier = await store.carrier.create(googleAuthId, { const carrier = await store.carrier.create(googleAuthId, {
name: cleanName, name: cleanName,
hasPackages: true, hasPackages,
}); });
carrierMap.set(key, carrier.id); carrierMap.set(key, carrier.id);
return carrier.id; return carrier.id;
@@ -379,31 +379,31 @@ export async function importOrders({
const isSelbstabholer = (shippingType || '').trim().toLowerCase() === 'selbstabholer'; const isSelbstabholer = (shippingType || '').trim().toLowerCase() === 'selbstabholer';
const deliveryState = isShipped ? 'delivered' : 'new'; 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, orderId: createdOrder.id,
date: validDate, date: validDate,
state: deliveryState, state: deliveryState,
lines: shippableLines, lines: shippableLines,
shipping: {
carrierId,
type: shippingType || 'standard',
state: isShipped ? 'shipped' : 'draft',
trackingCode: trackingCode || undefined,
warehouseId: defaultWarehouseId || undefined,
},
}); });
shippingsImported++;
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++;
}
}
} catch (err) { } catch (err) {
log.warn(`Failed to create shipment/shipping for order ${orderNumber}:`, err.message); log.warn(`Failed to create shipment/shipping for order ${orderNumber}:`, err.message);
} }