diff --git a/src/features/products/products/product.service.js b/src/features/products/products/product.service.js index ec6e7a7..07aa92f 100644 --- a/src/features/products/products/product.service.js +++ b/src/features/products/products/product.service.js @@ -440,7 +440,9 @@ export class ProductService { // Pack general form fields into metadata since they aren't core columns const initialStatus = data.status || 'draft'; - if (initialStatus === 'pending') { + if (data.sku && String(data.sku).trim() !== '') { + metadata.sku = String(data.sku).trim(); + } else if (initialStatus === 'pending' || initialStatus === 'active') { metadata.sku = await this.generateSku(family, finalCode, transaction); } else { metadata.sku = null; @@ -655,12 +657,13 @@ export class ProductService { const oldStatus = record.status || record.metadata?.currentStage || 'draft'; const newStatus = data.status || metadata.currentStage || oldStatus; - if (!metadata.sku && oldStatus === 'draft' && newStatus === 'pending') { + if (data.hasOwnProperty('sku') && data.sku && String(data.sku).trim() !== '') { + metadata.sku = String(data.sku).trim(); + } else if (!metadata.sku && (newStatus === 'pending' || newStatus === 'active')) { metadata.sku = await this.generateSku(family, record.code, transaction); } // Keep general fields inside metadata up to date - if (data.hasOwnProperty('sku')) metadata.sku = data.sku; if (data.hasOwnProperty('price')) metadata.price = data.price; if (data.hasOwnProperty('stock')) metadata.stock = data.stock; if (data.hasOwnProperty('barcode')) metadata.barcode = data.barcode;