2
0
mirror of https://github.com/frappe/books.git synced 2024-12-23 11:29:03 +00:00
books/models/baseModels/TaxSummary/TaxSummary.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

49 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-10-03 08:18:02 +00:00
import { Fyo } from 'fyo';
import { DocValueMap } from 'fyo/core/types';
import { Doc } from 'fyo/model/doc';
2022-10-03 08:18:02 +00:00
import { CurrenciesMap } from 'fyo/model/types';
import { DEFAULT_CURRENCY } from 'fyo/utils/consts';
2022-05-23 05:30:54 +00:00
import { Money } from 'pesa';
2022-10-03 08:18:02 +00:00
import { FieldTypeEnum, Schema } from 'schemas/types';
import { Invoice } from '../Invoice/Invoice';
export class TaxSummary extends Doc {
account?: string;
rate?: number;
amount?: Money;
2022-10-03 08:18:02 +00:00
parentdoc?: Invoice;
get exchangeRate() {
return this.parentdoc?.exchangeRate ?? 1;
}
get currency() {
return this.parentdoc?.currency ?? DEFAULT_CURRENCY;
}
constructor(schema: Schema, data: DocValueMap, fyo: Fyo) {
super(schema, data, fyo);
this._setGetCurrencies();
}
getCurrencies: CurrenciesMap = {};
_getCurrency() {
if (this.exchangeRate === 1) {
return this.fyo.singles.SystemSettings?.currency ?? DEFAULT_CURRENCY;
}
return this.currency;
}
_setGetCurrencies() {
const currencyFields = this.schema.fields.filter(
({ fieldtype }) => fieldtype === FieldTypeEnum.Currency
);
const getCurrency = this._getCurrency.bind(this);
for (const { fieldname } of currencyFields) {
this.getCurrencies[fieldname] ??= getCurrency;
}
}
}