fix(products): preserve manual SKU on creation and publish transition in product.service.js

This commit is contained in:
Inamul-hasan-tec
2026-08-19 15:12:52 +05:30
parent b0c1c9e210
commit cc0491939c
@@ -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;