2
0
mirror of https://github.com/frappe/books.git synced 2025-02-02 12:08:27 +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'; import { DateTime } from 'luxon';
export async function getExchangeRate({ fromCurrency, toCurrency, date }) { export async function getExchangeRate({ fromCurrency, toCurrency, date }) {
@ -5,7 +6,7 @@ export async function getExchangeRate({ fromCurrency, toCurrency, date }) {
date = DateTime.local().toISODate(); date = DateTime.local().toISODate();
} }
if (!fromCurrency || !toCurrency) { if (!fromCurrency || !toCurrency) {
throw new Error( throw new frappe.errors.NotFoundError(
'Please provide `fromCurrency` and `toCurrency` to get exchange rate.' 'Please provide `fromCurrency` and `toCurrency` to get exchange rate.'
); );
} }

View File

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

View File

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

View File

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