incr: wire up stock movement

- prevent erroneous setting of track item
- fix table UI
This commit is contained in:
18alantom
2022-11-07 13:28:35 +05:30
parent 2c0540bfd5
commit a8b5884929
6 changed files with 88 additions and 21 deletions
+9 -1
View File
@@ -7,6 +7,7 @@ import {
FormulaMap,
HiddenMap,
ListViewSettings,
ReadOnlyMap,
ValidationMap
} from 'fyo/model/types';
import { ValidationError } from 'fyo/utils/errors';
@@ -104,6 +105,13 @@ export class Item extends Doc {
}
hidden: HiddenMap = {
trackItem: () => this.itemType !== 'Product',
trackItem: () =>
this.itemType !== 'Product' || (this.inserted && !this.trackItem),
};
readOnly: ReadOnlyMap = {
unit: () => this.inserted,
itemType: () => this.inserted,
trackItem: () => this.inserted,
};
}
+19 -2
View File
@@ -1,5 +1,10 @@
import { Doc } from 'fyo/model/doc';
import { DefaultMap, FiltersMap, ListViewSettings } from 'fyo/model/types';
import {
DefaultMap,
FiltersMap,
FormulaMap,
ListViewSettings
} from 'fyo/model/types';
import { ModelNameEnum } from 'models/types';
import { Money } from 'pesa';
import { StockMovementItem } from './StockMovementItem';
@@ -10,9 +15,21 @@ export class StockMovement extends Doc {
date?: Date;
numberSeries?: string;
movementType?: MovementType;
items?: StockMovementItem;
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 }),
};
+42 -1
View File
@@ -1,7 +1,14 @@
import { Doc } from 'fyo/model/doc';
import { FilterFunction, FiltersMap } from 'fyo/model/types';
import {
FilterFunction,
FiltersMap,
FormulaMap,
RequiredMap
} from 'fyo/model/types';
import { ModelNameEnum } from 'models/types';
import { Money } from 'pesa';
import { QueryFilter } from 'utils/db/types';
import { StockMovement } from './StockMovement';
const locationFilter: FilterFunction = (doc: Doc) => {
const item = doc.item;
@@ -20,10 +27,44 @@ export class StockMovementItem extends Doc {
quantity?: number;
rate?: Money;
amount?: Money;
parentdoc?: StockMovement;
static filters: FiltersMap = {
item: () => ({ trackItem: true }),
toLocation: locationFilter,
fromLocation: locationFilter,
};
formulas: FormulaMap = {
rate: {
formula: async () => {
console.log('called', this.item);
if (!this.item) {
return this.rate;
}
return await this.fyo.getValue(ModelNameEnum.Item, this.item, 'rate');
},
dependsOn: ['item'],
},
amount: {
formula: () => this.rate!.mul(this.quantity!),
dependsOn: ['item', 'rate', 'quantity'],
},
};
required: RequiredMap = {
fromLocation: () =>
this.parentdoc?.movementType === 'MaterialIssue' ||
this.parentdoc?.movementType === 'MaterialTransfer',
toLocation: () =>
this.parentdoc?.movementType === 'MaterialReceipt' ||
this.parentdoc?.movementType === 'MaterialTransfer',
};
static createFilters: FiltersMap = {
item: () => ({ trackItem: true, itemType: 'Product' }),
fromLocation: (doc: Doc) => ({ item: (doc.item ?? '') as string }),
toLocation: (doc: Doc) => ({ item: (doc.item ?? '') as string }),
};
}
+3 -4
View File
@@ -16,10 +16,9 @@
"label": "Item",
"fieldtype": "Link",
"target": "Item",
"required": true
"required": true,
"readOnly": true
}
],
"quickEditFields": [
"item"
]
"quickEditFields": ["item"]
}
+1 -1
View File
@@ -15,7 +15,7 @@
},
{
"fieldname": "date",
"label": "Posting Date",
"label": "Date",
"fieldtype": "Datetime",
"required": true
},
+14 -12
View File
@@ -61,17 +61,20 @@
<div class="flex items-center pl-1">
<feather-icon name="plus" class="w-4 h-4 text-gray-500" />
</div>
<div class="flex justify-between px-2">
{{ t`Add Row` }}
</div>
<div v-for="i in ratio.slice(3).length" :key="i"></div>
<div
class="text-right px-2"
v-if="
value && maxRowsBeforeOverflow && value.length > maxRowsBeforeOverflow
"
>
{{ t`${value.length} rows` }}
<div class="flex justify-between px-2" :style="`grid-column: 2 / ${ratio.length + 1}`">
<p>
{{ t`Add Row` }}
</p>
<p
class="text-right px-2"
v-if="
value &&
maxRowsBeforeOverflow &&
value.length > maxRowsBeforeOverflow
"
>
{{ t`${value.length} rows` }}
</p>
</div>
</Row>
</div>
@@ -185,7 +188,6 @@ export default {
},
tableFields() {
const fields = fyo.schemaMap[this.df.target].tableFields ?? [];
console.log(this.df, fields);
return fields.map((fieldname) => fyo.getField(this.df.target, fieldname));
},
},