fix(products): preserve manual SKU on creation and publish transition in product.service.js
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user