diff --git a/src/app/core/substance-form/substance-form.component.ts b/src/app/core/substance-form/substance-form.component.ts index 7fe1795b1..0b4857342 100644 --- a/src/app/core/substance-form/substance-form.component.ts +++ b/src/app/core/substance-form/substance-form.component.ts @@ -1467,8 +1467,10 @@ export class SubstanceFormComponent implements OnInit, AfterViewInit, AfterViewC const json = this.substanceFormService.cleanSubstance(); const time = new Date().getTime(); - this.substanceFormService.regenUUID(); - json.uuid = this.substanceFormService.cleanSubstance().uuid; + // Always generate a fresh UUID for the draft copy — do NOT mutate the live substance, + // otherwise the save logic will treat a new substance as an existing one (PUT vs POST). + // A new UUID on every save ensures no two drafts share the same UUID. + json.uuid = this.utilsService.newUUID(); const uuid = json.uuid ? json.uuid : 'register'; const type = json.substanceClass; diff --git a/src/app/core/substance/substance.service.ts b/src/app/core/substance/substance.service.ts index c0340a270..ebebbcbb2 100644 --- a/src/app/core/substance/substance.service.ts +++ b/src/app/core/substance/substance.service.ts @@ -887,7 +887,8 @@ export class SubstanceService extends BaseHttpService { delete (substance as any).$$tmpStructureId; } - const method = type === 'import' || !substance.uuid ? 'POST' : 'PUT'; + // Use POST for new substances (no uuid OR no version), PUT for existing ones + const method = type === 'import' || !substance.uuid || !substance.version ? 'POST' : 'PUT'; const options = { body: substance }; const url = `${this.apiBaseUrl}substances?view=internal`; @@ -915,10 +916,8 @@ export class SubstanceService extends BaseHttpService { saveSubstanceWithoutValidation(substance: SubstanceDetail, type?: string): Observable { const url = `${this.apiBaseUrl}substances/novalid?view=internal`; - let method = 'PUT'; - if (type && type === 'import') { - method = 'POST'; - } + // Use POST for imports or new substances (no uuid or no version) + let method = (type === 'import' || !substance.uuid || !substance.version) ? 'POST' : 'PUT'; const options = { body: substance };