mirror of
https://github.com/frappe/books.git
synced 2024-11-08 14:50: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;
|
||||
}
|
||||
|
||||
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 {
|
||||
if (schema.naming === 'random') {
|
||||
return getRandomString();
|
||||
@ -116,11 +122,9 @@ export class DocHandler {
|
||||
|
||||
const idx = this.#temporaryNameCounters[schema.name];
|
||||
this.#temporaryNameCounters[schema.name] = idx + 1;
|
||||
const label = schema.label ?? schema.name;
|
||||
|
||||
return this.fyo.t`New ${schema.label ?? schema.name} ${String(idx).padStart(
|
||||
2,
|
||||
'0'
|
||||
)}`;
|
||||
return this.fyo.t`New ${label} ${String(idx).padStart(2, '0')}`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -76,7 +76,6 @@
|
||||
}
|
||||
],
|
||||
"quickEditFields": [
|
||||
"name",
|
||||
"addressLine1",
|
||||
"addressLine2",
|
||||
"city",
|
||||
|
@ -9,7 +9,6 @@
|
||||
}
|
||||
],
|
||||
"quickEditFields": [
|
||||
"name",
|
||||
"addressLine1",
|
||||
"addressLine2",
|
||||
"city",
|
||||
|
@ -10,7 +10,6 @@ import AutoComplete from './AutoComplete.vue';
|
||||
export default {
|
||||
name: 'Link',
|
||||
extends: AutoComplete,
|
||||
emits: ['new-doc'],
|
||||
data() {
|
||||
return { results: [] };
|
||||
},
|
||||
@ -35,22 +34,13 @@ export default {
|
||||
|
||||
const value = newValue ?? this.value;
|
||||
const { fieldname, target } = this.df ?? {};
|
||||
const displayField = fyo.schemaMap[target ?? '']?.linkDisplayField;
|
||||
|
||||
if (!displayField) {
|
||||
const linkDisplayField = fyo.schemaMap[target ?? '']?.linkDisplayField;
|
||||
if (!linkDisplayField) {
|
||||
return (this.linkValue = value);
|
||||
}
|
||||
|
||||
let displayValue = this.docs?.links?.[fieldname]?.get(displayField);
|
||||
if (!displayValue) {
|
||||
displayValue = await fyo.getValue(
|
||||
target,
|
||||
this.value ?? '',
|
||||
displayField
|
||||
);
|
||||
}
|
||||
|
||||
this.linkValue = displayValue;
|
||||
const linkDoc = await this.doc?.loadAndGetLink(fieldname);
|
||||
this.linkValue = linkDoc?.get(linkDisplayField) ?? '';
|
||||
},
|
||||
getTargetSchemaName() {
|
||||
return this.df.target;
|
||||
@ -141,7 +131,7 @@ export default {
|
||||
},
|
||||
async openNewDoc() {
|
||||
const schemaName = this.df.target;
|
||||
const doc = fyo.doc.getNewDoc(schemaName);
|
||||
const linkDoc = fyo.doc.getNewDoc(schemaName);
|
||||
|
||||
const filters = await this.getCreateFilters();
|
||||
|
||||
@ -149,17 +139,16 @@ export default {
|
||||
|
||||
openQuickEdit({
|
||||
schemaName,
|
||||
name: doc.name,
|
||||
name: linkDoc.name,
|
||||
defaults: Object.assign({}, filters, {
|
||||
name: this.linkValue,
|
||||
}),
|
||||
});
|
||||
|
||||
doc.once('afterSync', () => {
|
||||
this.$emit('new-doc', doc);
|
||||
linkDoc.once('afterSync', () => {
|
||||
this.$router.back();
|
||||
this.results = [];
|
||||
this.triggerChange(doc.name);
|
||||
this.triggerChange(linkDoc.name);
|
||||
});
|
||||
},
|
||||
async getCreateFilters() {
|
||||
|
@ -35,7 +35,6 @@
|
||||
:df="df"
|
||||
:value="row[df.fieldname]"
|
||||
@change="(value) => onChange(df, value)"
|
||||
@new-doc="(doc) => row.set(df.fieldname, doc.name)"
|
||||
/>
|
||||
<Button
|
||||
:icon="true"
|
||||
|
@ -113,6 +113,10 @@ export default defineComponent({
|
||||
shortcut: [ShortcutKey.pmod, 'N'],
|
||||
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' }"
|
||||
:text-end="false"
|
||||
@change="async (value) => await onChange(df, value)"
|
||||
@new-doc="async (newdoc) => await onChange(df, newdoc.name)"
|
||||
/>
|
||||
<div
|
||||
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 }">
|
||||
<Transition name="quickedit">
|
||||
<keep-alive>
|
||||
<div v-if="route?.query?.edit">
|
||||
<keep-alive>
|
||||
<component
|
||||
:is="Component"
|
||||
:key="route.query.schemaName + route.query.name"
|
||||
/>
|
||||
</div>
|
||||
</keep-alive>
|
||||
</div>
|
||||
</Transition>
|
||||
</router-view>
|
||||
</div>
|
||||
|
@ -74,7 +74,6 @@
|
||||
:df="getField('party')"
|
||||
:value="doc.party"
|
||||
@change="(value) => doc.set('party', value, true)"
|
||||
@new-doc="(party) => doc.set('party', party.name, true)"
|
||||
:read-only="doc?.submitted"
|
||||
/>
|
||||
<FormControl
|
||||
|
@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<div class="flex flex-col">
|
||||
<PageHeader :title="title">
|
||||
<Button :icon="false" @click="openExportModal = true">
|
||||
<Button :icon="false" @click="openExportModal = true" ref="exportButton">
|
||||
{{ t`Export` }}
|
||||
</Button>
|
||||
<FilterDropdown
|
||||
@ -16,6 +16,7 @@
|
||||
@click="makeNewDoc"
|
||||
:padding="false"
|
||||
class="px-3"
|
||||
ref="makeNewDocButton"
|
||||
>
|
||||
<feather-icon name="plus" class="w-4 h-4" />
|
||||
</Button>
|
||||
@ -41,7 +42,6 @@
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import { thisExpression } from '@babel/types';
|
||||
import Button from 'src/components/Button.vue';
|
||||
import ExportWizard from 'src/components/ExportWizard.vue';
|
||||
import FilterDropdown from 'src/components/FilterDropdown.vue';
|
||||
@ -93,11 +93,17 @@ export default {
|
||||
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() {
|
||||
docsPathRef.value = '';
|
||||
this.shortcuts.pmod.delete(['KeyN']);
|
||||
this.shortcuts.pmod.delete(['KeyE']);
|
||||
},
|
||||
methods: {
|
||||
updatedData(listFilters) {
|
||||
|
@ -118,6 +118,7 @@ import { focusedDocsRef } from 'src/utils/refs';
|
||||
import {
|
||||
commonDocSubmit,
|
||||
commonDocSync,
|
||||
focusOrSelectFormControl,
|
||||
getActionsForDoc,
|
||||
openQuickEdit,
|
||||
} from 'src/utils/ui';
|
||||
@ -168,6 +169,7 @@ export default {
|
||||
}
|
||||
|
||||
await this.fetchFieldsAndDoc();
|
||||
focusOrSelectFormControl(this.doc, this.$refs.titleControl, false);
|
||||
focusedDocsRef.add(this.doc);
|
||||
|
||||
if (fyo.store.isDevelopment) {
|
||||
@ -243,37 +245,11 @@ export default {
|
||||
this.imageField = fyo.getField(this.schemaName, 'image');
|
||||
|
||||
await this.fetchDoc();
|
||||
|
||||
// setup the title field
|
||||
this.setTitleField();
|
||||
|
||||
// set default values
|
||||
if (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() {
|
||||
if (this.sourceDoc) {
|
||||
return (this.doc = this.sourceDoc);
|
||||
|
@ -473,11 +473,19 @@ export function focusOrSelectFormControl(
|
||||
ref: any,
|
||||
clear: boolean = true
|
||||
) {
|
||||
if (!doc?.fyo) {
|
||||
return;
|
||||
}
|
||||
|
||||
const naming = doc.fyo.schemaMap[doc.schemaName]?.naming;
|
||||
if (naming !== 'manual' || doc.inserted) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!doc.fyo.doc.isTemporaryName(doc.name ?? '', doc.schema)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Array.isArray(ref) && ref.length > 0) {
|
||||
ref = ref[0];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user