2
0
mirror of https://github.com/frappe/books.git synced 2025-02-08 23:18:31 +00:00

fix: openQuickEdit

- Common method to route to quick edit form
This commit is contained in:
Faris Ansari 2019-12-03 18:40:21 +05:30
parent e5480bbfef
commit b367164a52
11 changed files with 61 additions and 107 deletions

View File

@ -35,6 +35,7 @@ module.exports = {
target: 'Account', target: 'Account',
placeholder: 'Sales', placeholder: 'Sales',
required: 1, required: 1,
disableCreation: true,
getFilters: query => { getFilters: query => {
return { return {
isGroup: 0, isGroup: 0,
@ -49,6 +50,7 @@ module.exports = {
target: 'Account', target: 'Account',
placeholder: 'Cost of Goods Sold', placeholder: 'Cost of Goods Sold',
required: 1, required: 1,
disableCreation: true,
getFilters: query => { getFilters: query => {
return { return {
isGroup: 0, isGroup: 0,

View File

@ -1,5 +1,6 @@
const frappe = require('frappejs'); const frappe = require('frappejs');
const utils = require('../../../accounting/utils'); const utils = require('../../../accounting/utils');
const { openQuickEdit } = require('@/utils');
const router = require('@/router').default; const router = require('@/router').default;
const InvoiceTemplate = require('./InvoiceTemplate.vue').default; const InvoiceTemplate = require('./InvoiceTemplate.vue').default;
@ -135,25 +136,22 @@ module.exports = {
payment.once('afterInsert', () => { payment.once('afterInsert', () => {
payment.submit(); payment.submit();
}); });
this.$router.push({ openQuickEdit({
query: { doctype: 'Payment',
edit: 1, name: payment.name,
doctype: 'Payment', hideFields: ['party', 'date', 'account', 'paymentType', 'for'],
name: payment.name, defaults: {
hideFields: ['party', 'date', 'account', 'paymentType', 'for'], party: doc.customer,
values: { account: doc.account,
party: doc.customer, date: new Date().toISOString().slice(0, 10),
account: doc.account, paymentType: 'Receive',
date: new Date().toISOString().slice(0, 10), for: [
paymentType: 'Receive', {
for: [ referenceType: doc.doctype,
{ referenceName: doc.name,
referenceType: doc.doctype, amount: doc.outstandingAmount
referenceName: doc.name, }
amount: doc.outstandingAmount ]
}
]
}
} }
}); });
} }
@ -174,5 +172,5 @@ module.exports = {
} }
}, },
utils.ledgerLink utils.ledgerLink
], ]
}; };

View File

@ -2,6 +2,7 @@
import frappe from 'frappejs'; import frappe from 'frappejs';
import AutoComplete from './AutoComplete'; import AutoComplete from './AutoComplete';
import Badge from '@/components/Badge'; import Badge from '@/components/Badge';
import { openQuickEdit } from '@/utils';
export default { export default {
name: 'Link', name: 'Link',
@ -79,20 +80,16 @@ export default {
let currentPath = this.$route.path; let currentPath = this.$route.path;
let currentQuery = this.$route.query; let currentQuery = this.$route.query;
let filters = await this.getFilters(); let filters = await this.getFilters();
this.$router.push({ openQuickEdit({
path: currentPath, doctype,
query: { name: doc.name,
edit: 1, defaults: Object.assign({}, filters, {
doctype, name: this.linkValue
name: doc.name, })
values: Object.assign({}, filters, {
name: this.linkValue
})
}
}); });
doc.once('afterInsert', () => { doc.once('afterInsert', () => {
this.$emit('new-doc', doc); this.$emit('new-doc', doc);
this.$router.go(-1); this.$router.back();
}); });
} }
} }

View File

@ -63,6 +63,7 @@
" "
@change="value => onChange(df, value)" @change="value => onChange(df, value)"
@focus="activateInlineEditing(df)" @focus="activateInlineEditing(df)"
@new-doc="newdoc => onChange(df, newdoc.name)"
/> />
</div> </div>
</div> </div>

View File

@ -34,6 +34,7 @@
import frappe from 'frappejs'; import frappe from 'frappejs';
import PageHeader from '@/components/PageHeader'; import PageHeader from '@/components/PageHeader';
import SearchBar from '@/components/SearchBar'; import SearchBar from '@/components/SearchBar';
import { openQuickEdit } from '@/utils';
export default { export default {
components: { components: {
@ -63,12 +64,9 @@ export default {
}, },
onClick(account) { onClick(account) {
if (account.isGroup === 0) { if (account.isGroup === 0) {
this.$router.push({ openQuickEdit({
query: { doctype: 'Account',
edit: 1, name: account.name
doctype: 'Account',
name: account.name
}
}); });
} else { } else {
this.toggleChildren(account); this.toggleChildren(account);

View File

@ -40,7 +40,7 @@
</div> </div>
</div> </div>
</div> </div>
<div v-if="total === 0" class="absolute inset-0 flex justify-center items-center"> <div v-if="totalExpense === 0" class="absolute inset-0 flex justify-center items-center">
<span class="text-base text-gray-600"> <span class="text-base text-gray-600">
{{ _('No transactions yet') }} {{ _('No transactions yet') }}
</span> </span>

View File

@ -187,7 +187,7 @@ import FormControl from '@/components/Controls/FormControl';
import Row from '@/components/Row'; import Row from '@/components/Row';
import Dropdown from '@/components/Dropdown'; import Dropdown from '@/components/Dropdown';
import { openSettings } from '@/pages/Settings/utils'; import { openSettings } from '@/pages/Settings/utils';
import { deleteDocWithPrompt } from '@/utils'; import { deleteDocWithPrompt, openQuickEdit } from '@/utils';
export default { export default {
name: 'InvoiceForm', name: 'InvoiceForm',
@ -309,33 +309,6 @@ export default {
async onSubmitClick() { async onSubmitClick() {
await this.doc.submit(); await this.doc.submit();
}, },
async makePayment() {
let payment = await frappe.getNewDoc('Payment');
payment.once('afterInsert', () => {
payment.submit();
});
this.$router.push({
query: {
edit: 1,
doctype: 'Payment',
name: payment.name,
hideFields: ['party', 'date', 'account', 'paymentType', 'for'],
values: {
party: this.doc[this.partyField.fieldname],
account: this.doc.account,
date: new Date().toISOString().slice(0, 10),
paymentType: this.doctype === 'SalesInvoice' ? 'Receive' : 'Pay',
for: [
{
referenceType: this.doctype,
referenceName: this.doc.name,
amount: this.doc.outstandingAmount
}
]
}
}
});
},
async fetchPartyDoc() { async fetchPartyDoc() {
if (this.doc[this.partyField.fieldname]) { if (this.doc[this.partyField.fieldname]) {
this.partyDoc = await frappe.getDoc( this.partyDoc = await frappe.getDoc(

View File

@ -119,6 +119,7 @@ import Button from '@/components/Button';
import FormControl from '@/components/Controls/FormControl'; import FormControl from '@/components/Controls/FormControl';
import Row from '@/components/Row'; import Row from '@/components/Row';
import Dropdown from '@/components/Dropdown'; import Dropdown from '@/components/Dropdown';
import { openQuickEdit } from '@/utils';
export default { export default {
name: 'JournalEntryForm', name: 'JournalEntryForm',
@ -171,42 +172,11 @@ export default {
this.doc.append('items'); this.doc.append('items');
}, },
async onSaveClick() { async onSaveClick() {
// await this.doc.set(
// 'items',
// this.doc.items.filter(row => row.item)
// );
return this.doc.insertOrUpdate(); return this.doc.insertOrUpdate();
}, },
async onSubmitClick() { async onSubmitClick() {
await this.doc.submit(); await this.doc.submit();
}, },
async makePayment() {
let payment = await frappe.getNewDoc('Payment');
payment.once('afterInsert', () => {
payment.submit();
});
this.$router.push({
query: {
edit: 1,
doctype: 'Payment',
name: payment.name,
hideFields: ['party', 'date', 'account', 'paymentType', 'for'],
values: {
party: this.doc[this.partyField.fieldname],
account: this.doc.account,
date: new Date().toISOString().slice(0, 10),
paymentType: this.doctype === 'SalesInvoice' ? 'Receive' : 'Pay',
for: [
{
referenceType: this.doctype,
referenceName: this.doc.name,
amount: this.doc.outstandingAmount
}
]
}
}
});
},
async fetchPartyDoc() { async fetchPartyDoc() {
this.partyDoc = await frappe.getDoc( this.partyDoc = await frappe.getDoc(
'Party', 'Party',

View File

@ -105,7 +105,8 @@ export default {
this.$router.push(this.listConfig.formRoute(doc.name)); this.$router.push(this.listConfig.formRoute(doc.name));
return; return;
} }
this.$router.push({ let method = this.$route.query.edit ? 'replace' : 'push';
this.$router[method]({
path: `/list/${this.doctype}`, path: `/list/${this.doctype}`,
query: { query: {
edit: 1, edit: 1,

View File

@ -2,7 +2,7 @@
<div class="border-l h-full"> <div class="border-l h-full">
<div class="flex items-center justify-between px-4 pt-4"> <div class="flex items-center justify-between px-4 pt-4">
<div class="flex items-center"> <div class="flex items-center">
<Button :icon="true" @click="routeToList"> <Button :icon="true" @click="routeToPrevious">
<feather-icon name="x" class="w-4 h-4" /> <feather-icon name="x" class="w-4 h-4" />
</Button> </Button>
<span v-if="statusText" class="ml-2 text-base text-gray-600">{{ <span v-if="statusText" class="ml-2 text-base text-gray-600">{{
@ -93,7 +93,7 @@ import Button from '@/components/Button';
import FormControl from '@/components/Controls/FormControl'; import FormControl from '@/components/Controls/FormControl';
import TwoColumnForm from '@/components/TwoColumnForm'; import TwoColumnForm from '@/components/TwoColumnForm';
import Dropdown from '@/components/Dropdown'; import Dropdown from '@/components/Dropdown';
import { deleteDocWithPrompt } from '@/utils'; import { deleteDocWithPrompt, openQuickEdit } from '@/utils';
export default { export default {
name: 'QuickEditForm', name: 'QuickEditForm',
@ -199,15 +199,11 @@ export default {
this.doc = await frappe.getDoc(this.doctype, this.name); this.doc = await frappe.getDoc(this.doctype, this.name);
this.doc.once('afterRename', () => { this.doc.once('afterRename', () => {
this.$router.push({ openQuickEdit({
query: { doctype: this.doctype,
edit: 1, name: this.doc.name
doctype: this.doctype,
name: this.doc.name
}
}); });
}); });
this.doc.on('beforeUpdate', () => { this.doc.on('beforeUpdate', () => {
this.statusText = _('Saving...'); this.statusText = _('Saving...');
}); });
@ -258,6 +254,9 @@ export default {
routeToList() { routeToList() {
this.$router.push(`/list/${this.doctype}`); this.$router.push(`/list/${this.doctype}`);
}, },
routeToPrevious() {
this.$router.back();
},
setTitleSize() { setTitleSize() {
if (this.$refs.titleControl) { if (this.$refs.titleControl) {
let input = this.$refs.titleControl.getInput(); let input = this.$refs.titleControl.getInput();

View File

@ -1,4 +1,5 @@
import frappe from 'frappejs'; import frappe from 'frappejs';
import router from '@/router';
import Avatar from '@/components/Avatar'; import Avatar from '@/components/Avatar';
import { _ } from 'frappejs'; import { _ } from 'frappejs';
import { remote } from 'electron'; import { remote } from 'electron';
@ -124,3 +125,17 @@ export function partyWithAvatar(party) {
` `
}; };
} }
export function openQuickEdit({ doctype, name, hideFields, defaults = {} }) {
let currentRoute = router.currentRoute;
router.push({
query: {
edit: 1,
doctype,
name,
hideFields,
values: defaults,
lastRoute: currentRoute
}
});
}