Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Verify if a shipment is being returned during the return process. #1078

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions models/baseModels/Invoice/Invoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -979,6 +980,17 @@ export abstract class Invoice extends Transactional {
return null;
}

let linkedEntries;

if (this.returnAgainst) {
const sinvDoc = (await this.fyo.doc.getDoc(
ModelNameEnum.SalesInvoice,
this.returnAgainst
)) as SalesInvoice;

linkedEntries = await getLinkedEntries(sinvDoc);
}

const schemaName = this.stockTransferSchemaName;

const defaults = (this.fyo.singles.Defaults as Defaults) ?? {};
Expand All @@ -998,6 +1010,7 @@ export abstract class Invoice extends Transactional {
terms,
numberSeries,
backReference: this.name,
returnAgainst: linkedEntries ? linkedEntries.Shipment![0] : '',
};

let location = this.autoStockTransferLocation;
Expand Down