Skip to content

Commit

Permalink
incr: update tax summmary
Browse files Browse the repository at this point in the history
  • Loading branch information
18alantom committed Oct 3, 2022
1 parent cd09d31 commit 6ee1365
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
2 changes: 1 addition & 1 deletion models/baseModels/PurchaseInvoice/PurchaseInvoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class PurchaseInvoice extends Invoice {
getTransactionStatusColumn(),
'party',
'date',
'grandTotal',
'baseGrandTotal',
'outstandingAmount',
],
};
Expand Down
2 changes: 1 addition & 1 deletion models/baseModels/SalesInvoice/SalesInvoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class SalesInvoice extends Invoice {
getTransactionStatusColumn(),
'party',
'date',
'grandTotal',
'baseGrandTotal',
'outstandingAmount',
],
};
Expand Down
40 changes: 40 additions & 0 deletions models/baseModels/TaxSummary/TaxSummary.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
2 changes: 1 addition & 1 deletion schemas/app/Invoice.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
},
{
"fieldname": "baseGrandTotal",
"label": "Grand Total (Company Currency)",
"label": "Base Grand Total",
"fieldtype": "Currency",
"readOnly": true
},
Expand Down

0 comments on commit 6ee1365

Please sign in to comment.