mirror of
https://github.com/frappe/books.git
synced 2024-12-23 03:19:01 +00:00
fix: prevent converter errors on duplication
This commit is contained in:
parent
71a3a45b99
commit
819e6821e1
@ -6,7 +6,7 @@ import Observable from 'fyo/utils/observable';
|
||||
import { Schema } from 'schemas/types';
|
||||
import { getRandomString } from 'utils';
|
||||
import { Fyo } from '..';
|
||||
import { DocValueMap } from './types';
|
||||
import { DocValueMap, RawValueMap } from './types';
|
||||
|
||||
export class DocHandler {
|
||||
fyo: Fyo;
|
||||
@ -79,10 +79,11 @@ export class DocHandler {
|
||||
|
||||
getNewDoc(
|
||||
schemaName: string,
|
||||
data: DocValueMap = {},
|
||||
data: DocValueMap | RawValueMap = {},
|
||||
cacheDoc: boolean = true,
|
||||
schema?: Schema,
|
||||
Model?: typeof Doc
|
||||
Model?: typeof Doc,
|
||||
isRawValueMap: boolean = true
|
||||
): Doc {
|
||||
if (!this.models[schemaName] && Model) {
|
||||
this.models[schemaName] = Model;
|
||||
@ -95,7 +96,7 @@ export class DocHandler {
|
||||
throw new NotFoundError(`Schema not found for ${schemaName}`);
|
||||
}
|
||||
|
||||
const doc = new Model!(schema, data, this.fyo);
|
||||
const doc = new Model!(schema, data, this.fyo, isRawValueMap);
|
||||
doc.name ??= getRandomString();
|
||||
if (cacheDoc) {
|
||||
this.#addToCache(doc);
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Fyo } from 'fyo';
|
||||
import { Converter } from 'fyo/core/converter';
|
||||
import { DocValue, DocValueMap } from 'fyo/core/types';
|
||||
import { DocValue, DocValueMap, RawValueMap } from 'fyo/core/types';
|
||||
import { Verb } from 'fyo/telemetry/types';
|
||||
import { DEFAULT_USER } from 'fyo/utils/consts';
|
||||
import { ConflictError, MandatoryError, NotFoundError } from 'fyo/utils/errors';
|
||||
@ -66,7 +66,12 @@ export class Doc extends Observable<DocValue | Doc[]> {
|
||||
_notInserted: boolean = true;
|
||||
|
||||
_syncing = false;
|
||||
constructor(schema: Schema, data: DocValueMap, fyo: Fyo) {
|
||||
constructor(
|
||||
schema: Schema,
|
||||
data: DocValueMap,
|
||||
fyo: Fyo,
|
||||
convertToDocValue: boolean = true
|
||||
) {
|
||||
super();
|
||||
this.fyo = markRaw(fyo);
|
||||
this.schema = schema;
|
||||
@ -77,7 +82,7 @@ export class Doc extends Observable<DocValue | Doc[]> {
|
||||
}
|
||||
|
||||
this._setDefaults();
|
||||
this._setValuesWithoutChecks(data, true);
|
||||
this._setValuesWithoutChecks(data, convertToDocValue);
|
||||
}
|
||||
|
||||
get schemaName(): string {
|
||||
@ -364,6 +369,9 @@ export class Doc extends Observable<DocValue | Doc[]> {
|
||||
const childDoc = this.fyo.doc.getNewDoc(
|
||||
childSchemaName,
|
||||
docValueMap,
|
||||
false,
|
||||
undefined,
|
||||
undefined,
|
||||
false
|
||||
);
|
||||
childDoc.parentdoc = this;
|
||||
@ -913,7 +921,12 @@ export class Doc extends Observable<DocValue | Doc[]> {
|
||||
updateMap.name = updateMap.name + ' CPY';
|
||||
}
|
||||
|
||||
return this.fyo.doc.getNewDoc(this.schemaName, updateMap);
|
||||
const rawUpdateMap = this.fyo.db.converter.toRawValueMap(
|
||||
this.schemaName,
|
||||
updateMap
|
||||
) as RawValueMap;
|
||||
|
||||
return this.fyo.doc.getNewDoc(this.schemaName, rawUpdateMap, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user