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

fix: error type

- allow translation string folding
This commit is contained in:
18alantom 2022-02-07 14:31:28 +05:30
parent 29c1621882
commit 838ae87642
4 changed files with 23 additions and 14 deletions

View File

@ -1,3 +1,4 @@
import frappe from 'frappe';
import { DateTime } from 'luxon';
export async function getExchangeRate({ fromCurrency, toCurrency, date }) {
@ -5,7 +6,7 @@ export async function getExchangeRate({ fromCurrency, toCurrency, date }) {
date = DateTime.local().toISODate();
}
if (!fromCurrency || !toCurrency) {
throw new Error(
throw new frappe.errors.NotFoundError(
'Please provide `fromCurrency` and `toCurrency` to get exchange rate.'
);
}

View File

@ -122,7 +122,7 @@ export default class LedgerPosting {
validateEntries() {
let { debit, credit } = this.getTotalDebitAndCredit();
if (debit.neq(credit)) {
throw new Error(
throw new frappe.errors.ValidationError(
`Total Debit: ${frappe.format(
debit,
'Currency'

View File

@ -64,6 +64,7 @@ class TranslationString {
return strList
.map((s, i) => this.#translate(s) + this.#formatArg(argList[i]))
.join('')
.replace(/\s+/g, ' ')
.trim();
}

View File

@ -64,31 +64,38 @@ export default class PaymentServer extends BaseDocument {
validateAccounts() {
if (this.paymentAccount !== this.account || !this.account) return;
throw new Error(
throw new frappe.errors.ValidationError(
`To Account and From Account can't be the same: ${this.account}`
);
}
validateReferenceAmount() {
if (!this.for?.length) return;
const referenceAmountTotal = this.for
.map(({ amount }) => amount)
.reduce((a, b) => a.add(b), frappe.pesa(0));
if (this.amount.add(this.writeoff ?? 0).lt(referenceAmountTotal)) {
const writeoff = frappe.format(this.writeoff, 'Currency');
const payment = frappe.format(this.amount, 'Currency');
const refAmount = frappe.format(referenceAmountTotal, 'Currency');
const writeoffString = this.writeoff.gt(0)
? `and writeoff: ${writeoff} `
: '';
if (this.amount.add(this.writeoff ?? 0).gte(referenceAmountTotal)) {
return;
}
throw new Error(
frappe.t(
`Amount: ${payment} ${writeoffString}is less than the total amount allocated to references: ${refAmount}.`
)
const writeoff = frappe.format(this.writeoff, 'Currency');
const payment = frappe.format(this.amount, 'Currency');
const refAmount = frappe.format(referenceAmountTotal, 'Currency');
if (this.writeoff.gt(0)) {
throw new frappe.errors.ValidationError(
frappe.t`Amount: ${payment} and writeoff: ${writeoff}
is less than the total amount allocated to
references: ${refAmount}.`
);
}
throw new frappe.errors.ValidationError(
frappe.t`Amount: ${payment} is less than the total
amount allocated to references: ${refAmount}.`
);
}
async getPosting() {