diff --git a/models/baseModels/Payment/Payment.ts b/models/baseModels/Payment/Payment.ts index ba21dd7a..13096257 100644 --- a/models/baseModels/Payment/Payment.ts +++ b/models/baseModels/Payment/Payment.ts @@ -36,6 +36,7 @@ export class Payment extends Transactional { amount?: Money; writeoff?: Money; paymentType?: PaymentType; + referenceType?: ModelNameEnum.SalesInvoice | ModelNameEnum.PurchaseInvoice; for?: PaymentFor[]; _accountsMap?: AccountTypeMap; @@ -529,6 +530,14 @@ export class Payment extends Transactional { formula: () => this.amount!.sub(this.writeoff!), dependsOn: ['amount', 'writeoff', 'for'], }, + referenceType: { + formula: () => { + if (this.referenceType) { + return; + } + return this.for![0].referenceType; + }, + }, }; validations: ValidationMap = { diff --git a/models/helpers.ts b/models/helpers.ts index 89f78a03..c6f7b6ca 100644 --- a/models/helpers.ts +++ b/models/helpers.ts @@ -98,11 +98,13 @@ export function getMakePaymentAction(fyo: Fyo): Action { condition: (doc: Doc) => doc.isSubmitted && !(doc.outstandingAmount as Money).isZero(), action: async (doc, router) => { + const schemaName = doc.schema.name; const payment = (doc as Invoice).getPayment(); if (!payment) { return; } + await payment?.set('referenceType', schemaName); const currentRoute = router.currentRoute.value.fullPath; payment.once('afterSync', async () => { await payment.submit(); diff --git a/schemas/app/Payment.json b/schemas/app/Payment.json index 71afc80a..9e1de96a 100644 --- a/schemas/app/Payment.json +++ b/schemas/app/Payment.json @@ -155,6 +155,24 @@ "label": "Attachment", "fieldtype": "Attachment", "section": "References" + }, + { + "fieldname": "referenceType", + "label": "Type", + "placeholder": "Type", + "fieldtype": "Select", + "options": [ + { + "value": "SalesInvoice", + "label": "Sales" + }, + { + "value": "PurchaseInvoice", + "label": "Purchase" + } + ], + "hidden": true, + "required": true } ], "quickEditFields": [ diff --git a/src/utils/filters.ts b/src/utils/filters.ts index 96b521d7..9ae083f5 100644 --- a/src/utils/filters.ts +++ b/src/utils/filters.ts @@ -1,9 +1,15 @@ +import { ModelNameEnum } from 'models/types'; + export const routeFilters = { SalesItems: { for: ['in', ['Sales', 'Both']] }, PurchaseItems: { for: ['in', ['Purchases', 'Both']] }, Items: { for: 'Both' }, - PurchasePayments: { paymentType: 'Pay' }, - SalesPayments: { paymentType: 'Receive' }, + PurchasePayments: { + referenceType: ModelNameEnum.PurchaseInvoice, + }, + SalesPayments: { + referenceType: ModelNameEnum.SalesInvoice, + }, Suppliers: { role: ['in', ['Supplier', 'Both']] }, Customers: { role: ['in', ['Customer', 'Both']] }, Party: { role: 'Both' },