diff --git a/models/baseModels/PurchaseInvoice/PurchaseInvoice.ts b/models/baseModels/PurchaseInvoice/PurchaseInvoice.ts index bb0002d43..38f447c9b 100644 --- a/models/baseModels/PurchaseInvoice/PurchaseInvoice.ts +++ b/models/baseModels/PurchaseInvoice/PurchaseInvoice.ts @@ -47,7 +47,7 @@ export class PurchaseInvoice extends Invoice { getTransactionStatusColumn(), 'party', 'date', - 'grandTotal', + 'baseGrandTotal', 'outstandingAmount', ], }; diff --git a/models/baseModels/SalesInvoice/SalesInvoice.ts b/models/baseModels/SalesInvoice/SalesInvoice.ts index 103cab440..5fd7b0d05 100644 --- a/models/baseModels/SalesInvoice/SalesInvoice.ts +++ b/models/baseModels/SalesInvoice/SalesInvoice.ts @@ -47,7 +47,7 @@ export class SalesInvoice extends Invoice { getTransactionStatusColumn(), 'party', 'date', - 'grandTotal', + 'baseGrandTotal', 'outstandingAmount', ], }; diff --git a/models/baseModels/TaxSummary/TaxSummary.ts b/models/baseModels/TaxSummary/TaxSummary.ts index 7a4fbd062..bb9438e49 100644 --- a/models/baseModels/TaxSummary/TaxSummary.ts +++ b/models/baseModels/TaxSummary/TaxSummary.ts @@ -1,8 +1,48 @@ +import { Fyo } from 'fyo'; +import { DocValueMap } from 'fyo/core/types'; import { Doc } from 'fyo/model/doc'; +import { CurrenciesMap } from 'fyo/model/types'; +import { DEFAULT_CURRENCY } from 'fyo/utils/consts'; import { Money } from 'pesa'; +import { FieldTypeEnum, Schema } from 'schemas/types'; +import { Invoice } from '../Invoice/Invoice'; export class TaxSummary extends Doc { account?: string; rate?: number; amount?: Money; + 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; + } + } } diff --git a/schemas/app/Invoice.json b/schemas/app/Invoice.json index 98891ca3e..6e281fbbf 100644 --- a/schemas/app/Invoice.json +++ b/schemas/app/Invoice.json @@ -69,7 +69,7 @@ }, { "fieldname": "baseGrandTotal", - "label": "Grand Total (Company Currency)", + "label": "Base Grand Total", "fieldtype": "Currency", "readOnly": true },