2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 07:40:55 +00:00
books/models/inventory/StockMovement.ts
18alantom a8b5884929 incr: wire up stock movement
- prevent erroneous setting of track item
- fix table UI
2022-11-07 13:28:35 +05:30

45 lines
1021 B
TypeScript

import { Doc } from 'fyo/model/doc';
import {
DefaultMap,
FiltersMap,
FormulaMap,
ListViewSettings
} from 'fyo/model/types';
import { ModelNameEnum } from 'models/types';
import { Money } from 'pesa';
import { StockMovementItem } from './StockMovementItem';
import { MovementType } from './types';
export class StockMovement extends Doc {
name?: string;
date?: Date;
numberSeries?: string;
movementType?: MovementType;
items?: StockMovementItem[];
amount?: Money;
formulas: FormulaMap = {
amount: {
formula: () => {
return this.items?.reduce(
(acc, item) => acc.add(item.amount ?? 0),
this.fyo.pesa(0)
);
},
dependsOn: ['items'],
},
};
static filters: FiltersMap = {
numberSeries: () => ({ referenceType: ModelNameEnum.StockMovement }),
};
static defaults: DefaultMap = {
date: () => new Date(),
};
static getListViewSettings(): ListViewSettings {
return { columns: ['name', 'date', 'movementType'] };
}
}