From ad07746245afb8066b273f22231cbe85a311ffe6 Mon Sep 17 00:00:00 2001 From: AbleKSaju <126228406+AbleKSaju@users.noreply.github.com> Date: Tue, 7 Jan 2025 12:34:39 +0530 Subject: [PATCH] fix: Verify if a shipment is being returned during the return process. --- models/baseModels/Invoice/Invoice.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/models/baseModels/Invoice/Invoice.ts b/models/baseModels/Invoice/Invoice.ts index dd7be0b10..c35a09b28 100644 --- a/models/baseModels/Invoice/Invoice.ts +++ b/models/baseModels/Invoice/Invoice.ts @@ -49,6 +49,7 @@ import { AppliedCouponCodes } from '../AppliedCouponCodes/AppliedCouponCodes'; import { CouponCode } from '../CouponCode/CouponCode'; import { SalesInvoice } from '../SalesInvoice/SalesInvoice'; import { SalesInvoiceItem } from '../SalesInvoiceItem/SalesInvoiceItem'; +import { getLinkedEntries } from 'src/utils/doc'; import { PricingRuleItem } from '../PricingRuleItem/PricingRuleItem'; export type TaxDetail = { @@ -979,6 +980,17 @@ export abstract class Invoice extends Transactional { return null; } + let linkedEntries; + + if (this.returnAgainst) { + const someDOC = (await this.fyo.doc.getDoc( + ModelNameEnum.SalesInvoice, + this.returnAgainst + )) as SalesInvoice; + + linkedEntries = await getLinkedEntries(someDOC); + } + const schemaName = this.stockTransferSchemaName; const defaults = (this.fyo.singles.Defaults as Defaults) ?? {}; @@ -998,6 +1010,7 @@ export abstract class Invoice extends Transactional { terms, numberSeries, backReference: this.name, + returnAgainst: linkedEntries ? linkedEntries.Shipment![0] : '', }; let location = this.autoStockTransferLocation;