2
0
mirror of https://github.com/frappe/books.git synced 2025-02-02 12:08:27 +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',
placeholder: 'Sales',
required: 1,
disableCreation: true,
getFilters: query => {
return {
isGroup: 0,
@ -49,6 +50,7 @@ module.exports = {
target: 'Account',
placeholder: 'Cost of Goods Sold',
required: 1,
disableCreation: true,
getFilters: query => {
return {
isGroup: 0,

View File

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

View File

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

View File

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

View File

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

View File

@ -40,7 +40,7 @@
</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">
{{ _('No transactions yet') }}
</span>

View File

@ -187,7 +187,7 @@ import FormControl from '@/components/Controls/FormControl';
import Row from '@/components/Row';
import Dropdown from '@/components/Dropdown';
import { openSettings } from '@/pages/Settings/utils';
import { deleteDocWithPrompt } from '@/utils';
import { deleteDocWithPrompt, openQuickEdit } from '@/utils';
export default {
name: 'InvoiceForm',
@ -309,33 +309,6 @@ export default {
async onSubmitClick() {
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() {
if (this.doc[this.partyField.fieldname]) {
this.partyDoc = await frappe.getDoc(

View File

@ -119,6 +119,7 @@ import Button from '@/components/Button';
import FormControl from '@/components/Controls/FormControl';
import Row from '@/components/Row';
import Dropdown from '@/components/Dropdown';
import { openQuickEdit } from '@/utils';
export default {
name: 'JournalEntryForm',
@ -171,42 +172,11 @@ export default {
this.doc.append('items');
},
async onSaveClick() {
// await this.doc.set(
// 'items',
// this.doc.items.filter(row => row.item)
// );
return this.doc.insertOrUpdate();
},
async onSubmitClick() {
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() {
this.partyDoc = await frappe.getDoc(
'Party',

View File

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

View File

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

View File

@ -1,4 +1,5 @@
import frappe from 'frappejs';
import router from '@/router';
import Avatar from '@/components/Avatar';
import { _ } from 'frappejs';
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
}
});
}