mirror of
https://github.com/frappe/books.git
synced 2025-01-03 15:17:30 +00:00
incr: validate if batch no set
This commit is contained in:
parent
869cdebed7
commit
7ae697849e
@ -11,6 +11,7 @@ import {
|
||||
import { DEFAULT_CURRENCY } from 'fyo/utils/consts';
|
||||
import { ValidationError } from 'fyo/utils/errors';
|
||||
import { addItem, getExchangeRate, getNumberSeries } from 'models/helpers';
|
||||
import { validateBatchNumber } from 'models/inventory/helpers';
|
||||
import { InventorySettings } from 'models/inventory/InventorySettings';
|
||||
import { StockTransfer } from 'models/inventory/StockTransfer';
|
||||
import { Transactional } from 'models/Transactional/Transactional';
|
||||
|
@ -93,7 +93,7 @@ export class Item extends Doc {
|
||||
|
||||
if (itemEntriesInSLE > 0) {
|
||||
throw new ValidationError(
|
||||
this.fyo.t`Cannot change value of Has Batch No as Item ${this
|
||||
this.fyo.t`Cannot change value of Has Batch Number as Item ${this
|
||||
.name!} already has transactions against it. `
|
||||
);
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import {
|
||||
import { LedgerPosting } from 'models/Transactional/LedgerPosting';
|
||||
import { ModelNameEnum } from 'models/types';
|
||||
import { Money } from 'pesa';
|
||||
import { validateBatchNumber } from './helpers';
|
||||
import { StockMovementItem } from './StockMovementItem';
|
||||
import { Transfer } from './Transfer';
|
||||
import { MovementType } from './types';
|
||||
@ -49,6 +50,11 @@ export class StockMovement extends Transfer {
|
||||
|
||||
async validate() {
|
||||
await super.validate();
|
||||
this.validateManufacture();
|
||||
await validateBatchNumber(this);
|
||||
}
|
||||
|
||||
validateManufacture() {
|
||||
if (this.movementType !== MovementType.Manufacture) {
|
||||
return;
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import { addItem, getLedgerLinkAction, getNumberSeries } from 'models/helpers';
|
||||
import { LedgerPosting } from 'models/Transactional/LedgerPosting';
|
||||
import { ModelNameEnum } from 'models/types';
|
||||
import { Money } from 'pesa';
|
||||
import { validateBatchNumber } from './helpers';
|
||||
import { StockTransferItem } from './StockTransferItem';
|
||||
import { Transfer } from './Transfer';
|
||||
|
||||
@ -151,6 +152,11 @@ export abstract class StockTransfer extends Transfer {
|
||||
}
|
||||
}
|
||||
|
||||
override async validate(): Promise<void> {
|
||||
await super.validate();
|
||||
await validateBatchNumber(this);
|
||||
}
|
||||
|
||||
static getActions(fyo: Fyo): Action[] {
|
||||
return [getLedgerLinkAction(fyo, false), getLedgerLinkAction(fyo, true)];
|
||||
}
|
||||
|
@ -1 +1,40 @@
|
||||
import { ValidationError } from 'fyo/utils/errors';
|
||||
import { Invoice } from 'models/baseModels/Invoice/Invoice';
|
||||
import { InvoiceItem } from 'models/baseModels/InvoiceItem/InvoiceItem';
|
||||
import { ModelNameEnum } from 'models/types';
|
||||
import { StockMovement } from './StockMovement';
|
||||
import { StockMovementItem } from './StockMovementItem';
|
||||
import { StockTransfer } from './StockTransfer';
|
||||
import { StockTransferItem } from './StockTransferItem';
|
||||
|
||||
export async function validateBatchNumber(
|
||||
doc: StockMovement | StockTransfer | Invoice
|
||||
) {
|
||||
for (const row of doc.items ?? []) {
|
||||
await validateItemRowBatchNumber(row);
|
||||
}
|
||||
}
|
||||
|
||||
async function validateItemRowBatchNumber(
|
||||
doc: StockMovementItem | StockTransferItem | InvoiceItem
|
||||
) {
|
||||
const item = doc.item;
|
||||
const batchNumber = doc.batchNumber;
|
||||
if (!item || batchNumber) {
|
||||
return;
|
||||
}
|
||||
|
||||
const hasBatchNumber = await doc.fyo.getValue(
|
||||
ModelNameEnum.Item,
|
||||
item,
|
||||
'hasBatchNumber'
|
||||
);
|
||||
|
||||
if (hasBatchNumber && batchNumber) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw new ValidationError(
|
||||
[`Batch Number not set.`, `Item ${item} is a batched item`].join(' ')
|
||||
);
|
||||
}
|
||||
|
@ -133,7 +133,7 @@
|
||||
},
|
||||
{
|
||||
"fieldname": "hasBatchNumber",
|
||||
"label": "Has Batch No",
|
||||
"label": "Has Batch Number",
|
||||
"fieldtype": "Check",
|
||||
"default": false,
|
||||
"section": "Inventory"
|
||||
|
Loading…
Reference in New Issue
Block a user