2
0
mirror of https://github.com/frappe/books.git synced 2024-11-09 23:30:56 +00:00

feat: add default fields for Quick Payments

- fix punctuation
- improve submit dialog if quick payment
This commit is contained in:
18alantom 2023-04-20 11:40:23 +05:30
parent ef3f23bf2b
commit bc909f630a
9 changed files with 101 additions and 13 deletions

View File

@ -3,6 +3,10 @@ import { FiltersMap, HiddenMap } from 'fyo/model/types';
import { ModelNameEnum } from 'models/types';
export class Defaults extends Doc {
// Quick Payments
salesPaymentAccount?: string;
purchasePaymentAccount?: string;
// Number Series
salesInvoiceNumberSeries?: string;
purchaseInvoiceNumberSeries?: string;
@ -28,6 +32,9 @@ export class Defaults extends Doc {
stockMovementPrintTemplate?: string;
static commonFilters = {
// Quick Payments
salesPaymentAccount: () => ({ isGroup: false, accountType: 'Cash' }),
purchasePaymentAccount: () => ({ isGroup: false, accountType: 'Cash' }),
// Number Series
salesInvoiceNumberSeries: () => ({
referenceType: ModelNameEnum.SalesInvoice,

View File

@ -47,6 +47,7 @@ export abstract class Invoice extends Transactional {
submitted?: boolean;
cancelled?: boolean;
makeQuickPayment?: boolean;
get isSales() {
return this.schemaName === 'SalesInvoice';
@ -90,6 +91,18 @@ export abstract class Invoice extends Transactional {
return !this.baseGrandTotal?.eq(this.outstandingAmount!);
}
get quickPaymentAccount(): string | null {
const fieldname = this.isSales
? 'salesPaymentAccount'
: 'purchasePaymentAccount';
const value = this.fyo.singles.Defaults?.[fieldname];
if (typeof value === 'string' && value.length) {
return value;
}
return null;
}
constructor(schema: Schema, data: DocValueMap, fyo: Fyo) {
super(schema, data, fyo);
this._setGetCurrencies();
@ -389,6 +402,10 @@ export abstract class Invoice extends Transactional {
},
dependsOn: ['items'],
},
makeQuickPayment: {
formula: () => !!this.quickPaymentAccount,
dependsOn: [],
},
};
getStockTransferred() {
@ -424,6 +441,17 @@ export abstract class Invoice extends Transactional {
}
hidden: HiddenMap = {
makeQuickPayment: () => {
if (this.submitted) {
return true;
}
if (!this.quickPaymentAccount) {
return true;
}
return false;
},
setDiscountAmount: () => true || !this.enableDiscounting,
discountAmount: () =>
true || !(this.enableDiscounting && !!this.setDiscountAmount),
@ -446,6 +474,8 @@ export abstract class Invoice extends Transactional {
};
static defaults: DefaultMap = {
makeQuickPayment: (doc) =>
doc instanceof Invoice && !!doc.quickPaymentAccount,
numberSeries: (doc) => getNumberSeries(doc.schemaName, doc.fyo),
terms: (doc) => {
const defaults = doc.fyo.singles.Defaults as Defaults | undefined;

View File

@ -4,6 +4,22 @@
"isSingle": true,
"isChild": false,
"fields": [
{
"fieldname": "salesPaymentAccount",
"label": "Sales Payment Account",
"fieldtype": "Link",
"target": "Account",
"create": true,
"section": "Quick Payments"
},
{
"fieldname": "purchasePaymentAccount",
"label": "Purchase Payment Account",
"fieldtype": "Link",
"target": "Account",
"create": true,
"section": "Quick Payments"
},
{
"fieldname": "salesInvoiceNumberSeries",
"label": "Sales Invoice Number Series",

View File

@ -133,12 +133,21 @@
},
{
"fieldname": "discountAfterTax",
"label": "Discount After Tax",
"label": "Apply Discount After Tax",
"fieldtype": "Check",
"default": false,
"readOnly": false,
"tab": "Settings"
},
{
"fieldname": "makeQuickPayment",
"label": "Make Payment On Submit",
"fieldtype": "Check",
"computed": true,
"default": false,
"readOnly": false,
"tab": "Settings"
},
{
"fieldname": "outstandingAmount",
"label": "Outstanding Amount",

View File

@ -797,7 +797,7 @@ export default defineComponent({
await showDialog({
title,
type: 'error',
detail: this.t`Following cells have errors: ${cellErrors.join(', ')}`,
detail: this.t`Following cells have errors: ${cellErrors.join(', ')}.`,
});
return false;
}
@ -809,7 +809,7 @@ export default defineComponent({
type: 'error',
detail: this.t`Following links do not exist: ${absentLinks
.map((l) => `(${l.schemaLabel}, ${l.name})`)
.join(', ')}`,
.join(', ')}.`,
});
return false;
}
@ -927,7 +927,7 @@ export default defineComponent({
if (!isValid) {
await showDialog({
title: this.t`Cannot read file`,
detail: this.t`Bad import data, could not read file`,
detail: this.t`Bad import data, could not read file.`,
type: 'error',
});
return;

View File

@ -153,7 +153,7 @@ export default defineComponent({
if (!this.areAllValuesFilled) {
return await showDialog({
title: this.t`Mandatory Error`,
detail: this.t`Please fill all values`,
detail: this.t`Please fill all values.`,
type: 'error',
});
}

View File

@ -465,7 +465,7 @@ export default defineComponent({
await showDialog({
title: this.t`No Display Entries Found`,
detail: this
.t`Please create a ${label} entry to view Template Preview`,
.t`Please create a ${label} entry to view Template Preview.`,
type: 'warning',
});

View File

@ -42,19 +42,19 @@ export async function deleteDb(filePath: string) {
if (error?.code === 'EBUSY') {
showDialog({
title: t`Delete Failed`,
detail: t`Please restart and try again`,
detail: t`Please restart and try again.`,
type: 'error',
});
} else if (error?.code === 'ENOENT') {
showDialog({
title: t`Delete Failed`,
detail: t`File ${filePath} does not exist`,
detail: t`File ${filePath} does not exist.`,
type: 'error',
});
} else if (error?.code === 'EPERM') {
showDialog({
title: t`Cannot Delete`,
detail: t`Close Frappe Books and try manually`,
detail: t`Close Frappe Books and try manually.`,
type: 'error',
});
} else if (error) {

View File

@ -7,6 +7,8 @@ import type { Doc } from 'fyo/model/doc';
import { Action } from 'fyo/model/types';
import { getActions } from 'fyo/utils';
import { getDbError, LinkValidationError, ValueError } from 'fyo/utils/errors';
import { PurchaseInvoice } from 'models/baseModels/PurchaseInvoice/PurchaseInvoice';
import { SalesInvoice } from 'models/baseModels/SalesInvoice/SalesInvoice';
import { getLedgerLink } from 'models/helpers';
import { Transfer } from 'models/inventory/Transfer';
import { Transactional } from 'models/Transactional/Transactional';
@ -92,7 +94,7 @@ export async function deleteDocWithPrompt(doc: Doc) {
if (getDbError(err as Error) === LinkValidationError) {
showDialog({
title: t`Delete Failed`,
detail: t`Cannot delete ${schemaLabel} ${doc.name!} because of linked entries.`,
detail: t`Cannot delete ${schemaLabel} "${doc.name!}" because of linked entries.`,
type: 'error',
});
} else {
@ -548,9 +550,9 @@ async function showSubmitOrSyncDialog(doc: Doc, type: 'submit' | 'sync') {
title = t`Save ${label}?`;
}
let detail = t`Mark ${doc.schema.label} as submitted`;
if (type === 'sync') {
detail = t`Save ${doc.schema.label} to database`;
let detail = t`Save ${doc.schema.label} to database.`;
if (type === 'submit') {
detail = getDocSubmitMessage(doc);
}
const yesAction = async () => {
@ -584,6 +586,30 @@ async function showSubmitOrSyncDialog(doc: Doc, type: 'submit' | 'sync') {
});
}
function getDocSubmitMessage(doc: Doc): string {
const details = [t`Mark ${doc.schema.label} as submitted?`];
if (doc instanceof SalesInvoice && doc.makeQuickPayment) {
const toAccount = doc.quickPaymentAccount!;
const fromAccount = doc.account!;
const amount = fyo.format(doc.outstandingAmount, 'Currency');
details.push(
t`Payment of ${amount} will be made from account "${fromAccount}" to account "${toAccount}" on Submit.`
);
} else if (doc instanceof PurchaseInvoice && doc.makeQuickPayment) {
const fromAccount = doc.quickPaymentAccount!;
const toAccount = doc.account!;
const amount = fyo.format(doc.outstandingAmount, 'Currency');
details.push(
t`Payment of ${amount} will be made from account "${fromAccount}" to account "${toAccount}" on Submit.`
);
}
return details.join(' ');
}
function showActionToast(doc: Doc, type: 'sync' | 'cancel' | 'delete') {
const label = getActionLabel(doc);
const message = {