mirror of
https://github.com/frappe/books.git
synced 2024-12-22 19:09:01 +00:00
Merge branch 'batch-wise-item' of https://github.com/wahni-green/books into batch-wise-item
This commit is contained in:
commit
1d188151e8
@ -11,6 +11,7 @@ import {
|
||||
ValidationMap,
|
||||
} from 'fyo/model/types';
|
||||
import { ValidationError } from 'fyo/utils/errors';
|
||||
import { ModelNameEnum } from 'models/types';
|
||||
import { Money } from 'pesa';
|
||||
import { AccountRootTypeEnum, AccountTypeEnum } from '../Account/types';
|
||||
|
||||
@ -75,6 +76,29 @@ export class Item extends Doc {
|
||||
throw new ValidationError(this.fyo.t`Rate can't be negative.`);
|
||||
}
|
||||
},
|
||||
hasBatchNumber: async (value: DocValue) => {
|
||||
const { hasBatchNumber } = await this.fyo.db.get(
|
||||
'Item',
|
||||
this.name!,
|
||||
'hasBatchNumber'
|
||||
);
|
||||
|
||||
if (hasBatchNumber && value !== hasBatchNumber) {
|
||||
const itemEntriesInSLE = await this.fyo.db.count(
|
||||
ModelNameEnum.StockLedgerEntry,
|
||||
{
|
||||
filters: { item: this.name! },
|
||||
}
|
||||
);
|
||||
|
||||
if (itemEntriesInSLE > 0) {
|
||||
throw new ValidationError(
|
||||
this.fyo.t`Cannot change value of Has Batch No as Item ${this
|
||||
.name!} already has transactions against it. `
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
static getActions(fyo: Fyo): Action[] {
|
||||
|
Loading…
Reference in New Issue
Block a user