mirror of
https://github.com/frappe/books.git
synced 2024-11-08 23:00:56 +00:00
fix: address setting on create new
- fix link field typo - remove name from address quickedit form list - add export shortcut
This commit is contained in:
parent
8cef2ae60f
commit
9bce0f1ae8
@ -107,6 +107,12 @@ export class DocHandler {
|
|||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isTemporaryName(name: string, schema: Schema): boolean {
|
||||||
|
const label = schema.label ?? schema.name;
|
||||||
|
const template = this.fyo.t`New ${label} `;
|
||||||
|
return name.includes(template);
|
||||||
|
}
|
||||||
|
|
||||||
getTemporaryName(schema: Schema): string {
|
getTemporaryName(schema: Schema): string {
|
||||||
if (schema.naming === 'random') {
|
if (schema.naming === 'random') {
|
||||||
return getRandomString();
|
return getRandomString();
|
||||||
@ -116,11 +122,9 @@ export class DocHandler {
|
|||||||
|
|
||||||
const idx = this.#temporaryNameCounters[schema.name];
|
const idx = this.#temporaryNameCounters[schema.name];
|
||||||
this.#temporaryNameCounters[schema.name] = idx + 1;
|
this.#temporaryNameCounters[schema.name] = idx + 1;
|
||||||
|
const label = schema.label ?? schema.name;
|
||||||
|
|
||||||
return this.fyo.t`New ${schema.label ?? schema.name} ${String(idx).padStart(
|
return this.fyo.t`New ${label} ${String(idx).padStart(2, '0')}`;
|
||||||
2,
|
|
||||||
'0'
|
|
||||||
)}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,7 +76,6 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"quickEditFields": [
|
"quickEditFields": [
|
||||||
"name",
|
|
||||||
"addressLine1",
|
"addressLine1",
|
||||||
"addressLine2",
|
"addressLine2",
|
||||||
"city",
|
"city",
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"quickEditFields": [
|
"quickEditFields": [
|
||||||
"name",
|
|
||||||
"addressLine1",
|
"addressLine1",
|
||||||
"addressLine2",
|
"addressLine2",
|
||||||
"city",
|
"city",
|
||||||
|
@ -10,7 +10,6 @@ import AutoComplete from './AutoComplete.vue';
|
|||||||
export default {
|
export default {
|
||||||
name: 'Link',
|
name: 'Link',
|
||||||
extends: AutoComplete,
|
extends: AutoComplete,
|
||||||
emits: ['new-doc'],
|
|
||||||
data() {
|
data() {
|
||||||
return { results: [] };
|
return { results: [] };
|
||||||
},
|
},
|
||||||
@ -35,22 +34,13 @@ export default {
|
|||||||
|
|
||||||
const value = newValue ?? this.value;
|
const value = newValue ?? this.value;
|
||||||
const { fieldname, target } = this.df ?? {};
|
const { fieldname, target } = this.df ?? {};
|
||||||
const displayField = fyo.schemaMap[target ?? '']?.linkDisplayField;
|
const linkDisplayField = fyo.schemaMap[target ?? '']?.linkDisplayField;
|
||||||
|
if (!linkDisplayField) {
|
||||||
if (!displayField) {
|
|
||||||
return (this.linkValue = value);
|
return (this.linkValue = value);
|
||||||
}
|
}
|
||||||
|
|
||||||
let displayValue = this.docs?.links?.[fieldname]?.get(displayField);
|
const linkDoc = await this.doc?.loadAndGetLink(fieldname);
|
||||||
if (!displayValue) {
|
this.linkValue = linkDoc?.get(linkDisplayField) ?? '';
|
||||||
displayValue = await fyo.getValue(
|
|
||||||
target,
|
|
||||||
this.value ?? '',
|
|
||||||
displayField
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.linkValue = displayValue;
|
|
||||||
},
|
},
|
||||||
getTargetSchemaName() {
|
getTargetSchemaName() {
|
||||||
return this.df.target;
|
return this.df.target;
|
||||||
@ -141,7 +131,7 @@ export default {
|
|||||||
},
|
},
|
||||||
async openNewDoc() {
|
async openNewDoc() {
|
||||||
const schemaName = this.df.target;
|
const schemaName = this.df.target;
|
||||||
const doc = fyo.doc.getNewDoc(schemaName);
|
const linkDoc = fyo.doc.getNewDoc(schemaName);
|
||||||
|
|
||||||
const filters = await this.getCreateFilters();
|
const filters = await this.getCreateFilters();
|
||||||
|
|
||||||
@ -149,17 +139,16 @@ export default {
|
|||||||
|
|
||||||
openQuickEdit({
|
openQuickEdit({
|
||||||
schemaName,
|
schemaName,
|
||||||
name: doc.name,
|
name: linkDoc.name,
|
||||||
defaults: Object.assign({}, filters, {
|
defaults: Object.assign({}, filters, {
|
||||||
name: this.linkValue,
|
name: this.linkValue,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
doc.once('afterSync', () => {
|
linkDoc.once('afterSync', () => {
|
||||||
this.$emit('new-doc', doc);
|
|
||||||
this.$router.back();
|
this.$router.back();
|
||||||
this.results = [];
|
this.results = [];
|
||||||
this.triggerChange(doc.name);
|
this.triggerChange(linkDoc.name);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
async getCreateFilters() {
|
async getCreateFilters() {
|
||||||
|
@ -35,7 +35,6 @@
|
|||||||
:df="df"
|
:df="df"
|
||||||
:value="row[df.fieldname]"
|
:value="row[df.fieldname]"
|
||||||
@change="(value) => onChange(df, value)"
|
@change="(value) => onChange(df, value)"
|
||||||
@new-doc="(doc) => row.set(df.fieldname, doc.name)"
|
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
:icon="true"
|
:icon="true"
|
||||||
|
@ -113,6 +113,10 @@ export default defineComponent({
|
|||||||
shortcut: [ShortcutKey.pmod, 'N'],
|
shortcut: [ShortcutKey.pmod, 'N'],
|
||||||
description: t`Create a new entry of the same type as the List View`,
|
description: t`Create a new entry of the same type as the List View`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
shortcut: [ShortcutKey.pmod, 'E'],
|
||||||
|
description: t`Open the Export Wizard modal`,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -40,7 +40,6 @@
|
|||||||
:class="{ 'p-2': df.fieldtype === 'Check' }"
|
:class="{ 'p-2': df.fieldtype === 'Check' }"
|
||||||
:text-end="false"
|
:text-end="false"
|
||||||
@change="async (value) => await onChange(df, value)"
|
@change="async (value) => await onChange(df, value)"
|
||||||
@new-doc="async (newdoc) => await onChange(df, newdoc.name)"
|
|
||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
class="text-sm text-red-600 mt-2 ps-2"
|
class="text-sm text-red-600 mt-2 ps-2"
|
||||||
|
@ -21,14 +21,14 @@ import { toggleSidebar } from 'src/utils/ui';
|
|||||||
|
|
||||||
<router-view name="edit" v-slot="{ Component, route }">
|
<router-view name="edit" v-slot="{ Component, route }">
|
||||||
<Transition name="quickedit">
|
<Transition name="quickedit">
|
||||||
<keep-alive>
|
|
||||||
<div v-if="route?.query?.edit">
|
<div v-if="route?.query?.edit">
|
||||||
|
<keep-alive>
|
||||||
<component
|
<component
|
||||||
:is="Component"
|
:is="Component"
|
||||||
:key="route.query.schemaName + route.query.name"
|
:key="route.query.schemaName + route.query.name"
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
</keep-alive>
|
</keep-alive>
|
||||||
|
</div>
|
||||||
</Transition>
|
</Transition>
|
||||||
</router-view>
|
</router-view>
|
||||||
</div>
|
</div>
|
||||||
|
@ -74,7 +74,6 @@
|
|||||||
:df="getField('party')"
|
:df="getField('party')"
|
||||||
:value="doc.party"
|
:value="doc.party"
|
||||||
@change="(value) => doc.set('party', value, true)"
|
@change="(value) => doc.set('party', value, true)"
|
||||||
@new-doc="(party) => doc.set('party', party.name, true)"
|
|
||||||
:read-only="doc?.submitted"
|
:read-only="doc?.submitted"
|
||||||
/>
|
/>
|
||||||
<FormControl
|
<FormControl
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
<PageHeader :title="title">
|
<PageHeader :title="title">
|
||||||
<Button :icon="false" @click="openExportModal = true">
|
<Button :icon="false" @click="openExportModal = true" ref="exportButton">
|
||||||
{{ t`Export` }}
|
{{ t`Export` }}
|
||||||
</Button>
|
</Button>
|
||||||
<FilterDropdown
|
<FilterDropdown
|
||||||
@ -16,6 +16,7 @@
|
|||||||
@click="makeNewDoc"
|
@click="makeNewDoc"
|
||||||
:padding="false"
|
:padding="false"
|
||||||
class="px-3"
|
class="px-3"
|
||||||
|
ref="makeNewDocButton"
|
||||||
>
|
>
|
||||||
<feather-icon name="plus" class="w-4 h-4" />
|
<feather-icon name="plus" class="w-4 h-4" />
|
||||||
</Button>
|
</Button>
|
||||||
@ -41,7 +42,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import { thisExpression } from '@babel/types';
|
|
||||||
import Button from 'src/components/Button.vue';
|
import Button from 'src/components/Button.vue';
|
||||||
import ExportWizard from 'src/components/ExportWizard.vue';
|
import ExportWizard from 'src/components/ExportWizard.vue';
|
||||||
import FilterDropdown from 'src/components/FilterDropdown.vue';
|
import FilterDropdown from 'src/components/FilterDropdown.vue';
|
||||||
@ -93,11 +93,17 @@ export default {
|
|||||||
window.lv = this;
|
window.lv = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.shortcuts.pmod.set(['KeyN'], this.makeNewDoc);
|
this.shortcuts.pmod.set(['KeyN'], () =>
|
||||||
|
this.$refs.makeNewDocButton.$el.click()
|
||||||
|
);
|
||||||
|
this.shortcuts.pmod.set(['KeyE'], () =>
|
||||||
|
this.$refs.exportButton.$el.click()
|
||||||
|
);
|
||||||
},
|
},
|
||||||
deactivated() {
|
deactivated() {
|
||||||
docsPathRef.value = '';
|
docsPathRef.value = '';
|
||||||
this.shortcuts.pmod.delete(['KeyN']);
|
this.shortcuts.pmod.delete(['KeyN']);
|
||||||
|
this.shortcuts.pmod.delete(['KeyE']);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
updatedData(listFilters) {
|
updatedData(listFilters) {
|
||||||
|
@ -118,6 +118,7 @@ import { focusedDocsRef } from 'src/utils/refs';
|
|||||||
import {
|
import {
|
||||||
commonDocSubmit,
|
commonDocSubmit,
|
||||||
commonDocSync,
|
commonDocSync,
|
||||||
|
focusOrSelectFormControl,
|
||||||
getActionsForDoc,
|
getActionsForDoc,
|
||||||
openQuickEdit,
|
openQuickEdit,
|
||||||
} from 'src/utils/ui';
|
} from 'src/utils/ui';
|
||||||
@ -168,6 +169,7 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await this.fetchFieldsAndDoc();
|
await this.fetchFieldsAndDoc();
|
||||||
|
focusOrSelectFormControl(this.doc, this.$refs.titleControl, false);
|
||||||
focusedDocsRef.add(this.doc);
|
focusedDocsRef.add(this.doc);
|
||||||
|
|
||||||
if (fyo.store.isDevelopment) {
|
if (fyo.store.isDevelopment) {
|
||||||
@ -243,37 +245,11 @@ export default {
|
|||||||
this.imageField = fyo.getField(this.schemaName, 'image');
|
this.imageField = fyo.getField(this.schemaName, 'image');
|
||||||
|
|
||||||
await this.fetchDoc();
|
await this.fetchDoc();
|
||||||
|
|
||||||
// setup the title field
|
|
||||||
this.setTitleField();
|
|
||||||
|
|
||||||
// set default values
|
// set default values
|
||||||
if (this.values) {
|
if (this.values) {
|
||||||
this.doc?.set(this.values);
|
this.doc?.set(this.values);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setTitleField() {
|
|
||||||
const { fieldname, readOnly } = this.titleField;
|
|
||||||
if (!this.doc?.notInserted || !this?.doc[fieldname]) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const isManual = this.schema.naming === 'manual';
|
|
||||||
const isNumberSeries = fyo.getField(this.schemaName, 'numberSeries');
|
|
||||||
if (readOnly && (!this?.doc[fieldname] || isNumberSeries)) {
|
|
||||||
this.doc.set(fieldname, t`New ${this.schema.label}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this?.doc[fieldname] && !isManual) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.doc.set(fieldname, '');
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
this.$refs.titleControl?.focus();
|
|
||||||
}, 300);
|
|
||||||
},
|
|
||||||
async fetchDoc() {
|
async fetchDoc() {
|
||||||
if (this.sourceDoc) {
|
if (this.sourceDoc) {
|
||||||
return (this.doc = this.sourceDoc);
|
return (this.doc = this.sourceDoc);
|
||||||
|
@ -473,11 +473,19 @@ export function focusOrSelectFormControl(
|
|||||||
ref: any,
|
ref: any,
|
||||||
clear: boolean = true
|
clear: boolean = true
|
||||||
) {
|
) {
|
||||||
|
if (!doc?.fyo) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const naming = doc.fyo.schemaMap[doc.schemaName]?.naming;
|
const naming = doc.fyo.schemaMap[doc.schemaName]?.naming;
|
||||||
if (naming !== 'manual' || doc.inserted) {
|
if (naming !== 'manual' || doc.inserted) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!doc.fyo.doc.isTemporaryName(doc.name ?? '', doc.schema)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (Array.isArray(ref) && ref.length > 0) {
|
if (Array.isArray(ref) && ref.length > 0) {
|
||||||
ref = ref[0];
|
ref = ref[0];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user