mirror of
https://github.com/frappe/books.git
synced 2024-11-08 23:00:56 +00:00
fix: validation: cant cancel doc if return is made
This commit is contained in:
parent
3349f1af10
commit
312f78ff73
@ -51,7 +51,6 @@ export class AccountingSettings extends Doc {
|
|||||||
override hidden: HiddenMap = {
|
override hidden: HiddenMap = {
|
||||||
discountAccount: () => !this.enableDiscounting,
|
discountAccount: () => !this.enableDiscounting,
|
||||||
gstin: () => this.fyo.singles.SystemSettings?.countryCode !== 'in',
|
gstin: () => this.fyo.singles.SystemSettings?.countryCode !== 'in',
|
||||||
enableStockReturns: () => !this.enableInventory,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
async change(ch: ChangeArg) {
|
async change(ch: ChangeArg) {
|
||||||
|
@ -206,6 +206,11 @@ export abstract class StockTransfer extends Transfer {
|
|||||||
await this._updateItemsReturned();
|
await this._updateItemsReturned();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async beforeCancel(): Promise<void> {
|
||||||
|
await super.beforeCancel();
|
||||||
|
await this._validateHasReturnDocs();
|
||||||
|
}
|
||||||
|
|
||||||
async afterCancel(): Promise<void> {
|
async afterCancel(): Promise<void> {
|
||||||
await super.afterCancel();
|
await super.afterCancel();
|
||||||
await updateSerialNumbers(this, true, this.isReturn);
|
await updateSerialNumbers(this, true, this.isReturn);
|
||||||
@ -268,8 +273,8 @@ export abstract class StockTransfer extends Transfer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _updateItemsReturned() {
|
async _updateItemsReturned() {
|
||||||
if (!this.isSubmitted || !this.returnAgainst) {
|
if (this.isSyncing || !this.returnAgainst) {
|
||||||
return null;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const linkedReference = await this.loadAndGetLink('returnAgainst');
|
const linkedReference = await this.loadAndGetLink('returnAgainst');
|
||||||
@ -281,11 +286,33 @@ export abstract class StockTransfer extends Transfer {
|
|||||||
this.schemaName,
|
this.schemaName,
|
||||||
linkedReference.name
|
linkedReference.name
|
||||||
);
|
);
|
||||||
const isReturned = !!referenceDoc;
|
|
||||||
|
|
||||||
|
const isReturned = this.isSubmitted;
|
||||||
await referenceDoc.setAndSync({ isReturned });
|
await referenceDoc.setAndSync({ isReturned });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async _validateHasReturnDocs() {
|
||||||
|
if (!this.name) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const returnDocs = await this.fyo.db.getAll(this.schemaName, {
|
||||||
|
filters: { returnAgainst: this.name },
|
||||||
|
});
|
||||||
|
|
||||||
|
const hasReturnDocs = !!returnDocs.length;
|
||||||
|
if (!hasReturnDocs) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const returnDocNames = returnDocs.map((doc) => doc.name).join(', ');
|
||||||
|
const label = this.fyo.schemaMap[this.schemaName]?.label ?? this.schemaName;
|
||||||
|
|
||||||
|
throw new ValidationError(
|
||||||
|
t`Cannot cancel ${this.schema.label} ${this.name} because of the following ${label}: ${returnDocNames}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
_getTransferMap() {
|
_getTransferMap() {
|
||||||
return (this.items ?? []).reduce((acc, item) => {
|
return (this.items ?? []).reduce((acc, item) => {
|
||||||
if (!item.item) {
|
if (!item.item) {
|
||||||
|
Loading…
Reference in New Issue
Block a user