2022-10-05 14:37:17 +00:00
|
|
|
import { Doc } from 'fyo/model/doc';
|
2022-10-06 08:50:13 +00:00
|
|
|
import {
|
|
|
|
DefaultMap,
|
|
|
|
FiltersMap,
|
|
|
|
FormulaMap,
|
|
|
|
ListViewSettings
|
|
|
|
} from 'fyo/model/types';
|
2022-10-05 14:37:17 +00:00
|
|
|
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;
|
2022-10-06 08:50:13 +00:00
|
|
|
items?: StockMovementItem[];
|
2022-10-05 14:37:17 +00:00
|
|
|
amount?: Money;
|
|
|
|
|
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 {
|
|
|
|
return { columns: ['name', 'date', 'movementType'] };
|
|
|
|
}
|
|
|
|
}
|