2022-11-21 06:35:05 +00:00
|
|
|
import { Fyo } from 'fyo';
|
2022-10-06 08:50:13 +00:00
|
|
|
import {
|
2022-11-21 06:35:05 +00:00
|
|
|
Action,
|
2022-10-06 08:50:13 +00:00
|
|
|
DefaultMap,
|
|
|
|
FiltersMap,
|
|
|
|
FormulaMap,
|
2022-11-21 06:35:05 +00:00
|
|
|
ListViewSettings
|
2022-10-06 08:50:13 +00:00
|
|
|
} from 'fyo/model/types';
|
2022-11-21 06:35:05 +00:00
|
|
|
import { getDocStatusListColumn, getLedgerLinkAction } from 'models/helpers';
|
2022-11-18 17:31:50 +00:00
|
|
|
import { LedgerPosting } from 'models/Transactional/LedgerPosting';
|
2022-10-05 14:37:17 +00:00
|
|
|
import { ModelNameEnum } from 'models/types';
|
|
|
|
import { Money } from 'pesa';
|
|
|
|
import { StockMovementItem } from './StockMovementItem';
|
2022-11-18 17:31:50 +00:00
|
|
|
import { Transfer } from './Transfer';
|
2022-10-05 14:37:17 +00:00
|
|
|
import { MovementType } from './types';
|
|
|
|
|
2022-11-18 17:31:50 +00:00
|
|
|
export class StockMovement extends Transfer {
|
2022-10-05 14:37:17 +00:00
|
|
|
name?: string;
|
|
|
|
date?: Date;
|
|
|
|
numberSeries?: string;
|
|
|
|
movementType?: MovementType;
|
2022-10-06 08:50:13 +00:00
|
|
|
items?: StockMovementItem[];
|
2022-10-05 14:37:17 +00:00
|
|
|
amount?: Money;
|
|
|
|
|
2022-11-18 17:31:50 +00:00
|
|
|
override get isTransactional(): boolean {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
override async getPosting(): Promise<LedgerPosting | null> {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-10-06 08:50:13 +00:00
|
|
|
formulas: FormulaMap = {
|
|
|
|
amount: {
|
|
|
|
formula: () => {
|
|
|
|
return this.items?.reduce(
|
|
|
|
(acc, item) => acc.add(item.amount ?? 0),
|
|
|
|
this.fyo.pesa(0)
|
|
|
|
);
|
|
|
|
},
|
|
|
|
dependsOn: ['items'],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-10-05 14:37:17 +00:00
|
|
|
static filters: FiltersMap = {
|
|
|
|
numberSeries: () => ({ referenceType: ModelNameEnum.StockMovement }),
|
|
|
|
};
|
|
|
|
|
|
|
|
static defaults: DefaultMap = {
|
|
|
|
date: () => new Date(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static getListViewSettings(): ListViewSettings {
|
2022-11-16 08:35:38 +00:00
|
|
|
return {
|
|
|
|
columns: ['name', getDocStatusListColumn(), 'date', 'movementType'],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-11-02 14:56:37 +00:00
|
|
|
_getTransferDetails() {
|
|
|
|
return (this.items ?? []).map((row) => ({
|
|
|
|
item: row.item!,
|
|
|
|
rate: row.rate!,
|
|
|
|
quantity: row.quantity!,
|
|
|
|
fromLocation: row.fromLocation,
|
|
|
|
toLocation: row.toLocation,
|
|
|
|
}));
|
2022-10-29 06:15:23 +00:00
|
|
|
}
|
2022-11-21 06:35:05 +00:00
|
|
|
|
|
|
|
static getActions(fyo: Fyo): Action[] {
|
|
|
|
return [getLedgerLinkAction(fyo, true)];
|
|
|
|
}
|
2022-10-05 14:37:17 +00:00
|
|
|
}
|