mirror of
https://github.com/frappe/books.git
synced 2026-08-24 10:04:45 -05:00
incr: wire up stock movement
- prevent erroneous setting of track item - fix table UI
This commit is contained in:
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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 }),
|
||||
};
|
||||
|
||||
@@ -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 }),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -16,10 +16,9 @@
|
||||
"label": "Item",
|
||||
"fieldtype": "Link",
|
||||
"target": "Item",
|
||||
"required": true
|
||||
"required": true,
|
||||
"readOnly": true
|
||||
}
|
||||
],
|
||||
"quickEditFields": [
|
||||
"item"
|
||||
]
|
||||
"quickEditFields": ["item"]
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
},
|
||||
{
|
||||
"fieldname": "date",
|
||||
"label": "Posting Date",
|
||||
"label": "Date",
|
||||
"fieldtype": "Datetime",
|
||||
"required": true
|
||||
},
|
||||
|
||||
@@ -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));
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user