mirror of
https://github.com/frappe/books.git
synced 2024-11-10 07:40:55 +00:00
401a86eeeb
- fix isPesa impl
78 lines
1.8 KiB
TypeScript
78 lines
1.8 KiB
TypeScript
import { Doc } from 'fyo/model/doc';
|
|
import { FiltersMap, FormulaMap } from 'fyo/model/types';
|
|
import { ModelNameEnum } from 'models/types';
|
|
import { Money } from 'pesa';
|
|
import { PartyRoleEnum } from '../Party/types';
|
|
import { Payment } from '../Payment/Payment';
|
|
|
|
export class PaymentFor extends Doc {
|
|
parentdoc?: Payment | undefined;
|
|
referenceType?: ModelNameEnum.SalesInvoice | ModelNameEnum.PurchaseInvoice;
|
|
referenceName?: string;
|
|
amount?: Money;
|
|
|
|
formulas: FormulaMap = {
|
|
referenceType: {
|
|
formula: async () => {
|
|
if (this.referenceType) {
|
|
return;
|
|
}
|
|
|
|
const party = this.parentdoc!.party;
|
|
if (party === undefined) {
|
|
return ModelNameEnum.SalesInvoice;
|
|
}
|
|
|
|
const role = await this.fyo.getValue(
|
|
ModelNameEnum.Party,
|
|
party,
|
|
'role'
|
|
);
|
|
|
|
if (role === PartyRoleEnum.Supplier) {
|
|
return ModelNameEnum.PurchaseInvoice;
|
|
}
|
|
|
|
return ModelNameEnum.SalesInvoice;
|
|
},
|
|
},
|
|
amount: {
|
|
formula: async () => {
|
|
if (!this.referenceName) {
|
|
return this.fyo.pesa(0);
|
|
}
|
|
|
|
const outstandingAmount = (await this.fyo.getValue(
|
|
this.referenceType as string,
|
|
this.referenceName as string,
|
|
'outstandingAmount'
|
|
)) as Money;
|
|
|
|
if (outstandingAmount) {
|
|
return outstandingAmount;
|
|
}
|
|
|
|
return this.fyo.pesa(0);
|
|
},
|
|
dependsOn: ['referenceName'],
|
|
},
|
|
};
|
|
|
|
static filters: FiltersMap = {
|
|
referenceName: (doc) => {
|
|
const baseFilters = {
|
|
outstandingAmount: ['>', 0],
|
|
submitted: true,
|
|
cancelled: false,
|
|
};
|
|
|
|
const party = doc?.parentdoc?.party as undefined | string;
|
|
if (party === undefined) {
|
|
return baseFilters;
|
|
}
|
|
|
|
return { ...baseFilters, party };
|
|
},
|
|
};
|
|
}
|