mirror of
https://github.com/frappe/books.git
synced 2024-11-10 07:40:55 +00:00
fix: balance quantity not updating after submit
This commit is contained in:
parent
d3bc03a14c
commit
5f595501f5
@ -34,7 +34,7 @@
|
||||
px-2
|
||||
w-full
|
||||
"
|
||||
@click="handleChange(row)"
|
||||
@click="handleChange(row as POSItem)"
|
||||
>
|
||||
<FormControl
|
||||
v-for="df in tableFields"
|
||||
@ -57,17 +57,23 @@ import { fyo } from 'src/initFyo';
|
||||
import { defineComponent } from 'vue';
|
||||
import { ModelNameEnum } from 'models/types';
|
||||
import { Field } from 'schemas/types';
|
||||
import { DocValueMap } from 'fyo/core/types';
|
||||
import { ItemQtyMap } from './types';
|
||||
import { Item } from 'models/baseModels/Item/Item';
|
||||
import { POSItem } from './types';
|
||||
import { Money } from 'pesa';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ItemsTable',
|
||||
components: { FormControl, Row },
|
||||
emits: ['addItem', 'updateValues'],
|
||||
setup() {
|
||||
return {
|
||||
itemQtyMap: inject('itemQtyMap') as ItemQtyMap,
|
||||
};
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
items: [] as DocValueMap[],
|
||||
itemQtyMap: inject('itemQtyMap') as ItemQtyMap,
|
||||
items: [] as POSItem[],
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
@ -78,59 +84,76 @@ export default defineComponent({
|
||||
return [
|
||||
{
|
||||
fieldname: 'item',
|
||||
fieldtype: 'Link',
|
||||
fieldtype: 'Data',
|
||||
label: 'Item',
|
||||
placeholder: 'Item',
|
||||
required: true,
|
||||
schemaName: 'Item',
|
||||
readOnly: true,
|
||||
},
|
||||
{
|
||||
fieldname: 'rate',
|
||||
label: 'Rate',
|
||||
placeholder: 'Rate',
|
||||
fieldtype: 'Currency',
|
||||
required: true,
|
||||
readOnly: true,
|
||||
},
|
||||
{
|
||||
fieldname: 'availableQty',
|
||||
label: 'Available Qty',
|
||||
placeholder: 'Available Qty',
|
||||
fieldtype: 'Float',
|
||||
required: true,
|
||||
readOnly: true,
|
||||
},
|
||||
{
|
||||
fieldname: 'unit',
|
||||
label: 'Unit',
|
||||
placeholder: 'Unit',
|
||||
fieldtype: 'Link',
|
||||
required: true,
|
||||
schemaName: 'UOM',
|
||||
fieldtype: 'Data',
|
||||
target: 'UOM',
|
||||
readOnly: true,
|
||||
},
|
||||
];
|
||||
] as Field[];
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
itemQtyMap: {
|
||||
async handler() {
|
||||
this.setItems();
|
||||
},
|
||||
deep: true,
|
||||
},
|
||||
},
|
||||
async activated() {
|
||||
await this.getItems();
|
||||
await this.setItems();
|
||||
},
|
||||
methods: {
|
||||
async getItems() {
|
||||
this.items = [];
|
||||
const query = await fyo.db.getAll(ModelNameEnum.Item, { fields: [] });
|
||||
for (const row of query) {
|
||||
async setItems() {
|
||||
const items = (await fyo.db.getAll(ModelNameEnum.Item, {
|
||||
fields: [],
|
||||
})) as Item[];
|
||||
|
||||
this.items = [] as POSItem[];
|
||||
for (const item of items) {
|
||||
let availableQty = 0;
|
||||
|
||||
if (this.itemQtyMap[row.name as string]) {
|
||||
availableQty = this.itemQtyMap[row.name as string].availableQty;
|
||||
if (!!this.itemQtyMap[item.name as string]) {
|
||||
availableQty = this.itemQtyMap[item.name as string].availableQty;
|
||||
}
|
||||
|
||||
if (!item.name) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.items.push({
|
||||
item: row.name,
|
||||
availableQty,
|
||||
...row,
|
||||
item: item.name,
|
||||
rate: item.rate as Money,
|
||||
unit: item.unit as string,
|
||||
hasBatch: !!item.hasBatch,
|
||||
hasSerialNumber: !!item.hasSerialNumber,
|
||||
});
|
||||
}
|
||||
},
|
||||
handleChange(value: DocValueMap) {
|
||||
handleChange(value: POSItem) {
|
||||
this.$emit('addItem', value);
|
||||
this.$emit('updateValues');
|
||||
},
|
||||
|
@ -8,8 +8,7 @@
|
||||
<Link
|
||||
:df="{
|
||||
fieldname: 'item',
|
||||
fieldtype: 'Link',
|
||||
target: 'Item',
|
||||
fieldtype: 'Data',
|
||||
label: 'item',
|
||||
}"
|
||||
size="small"
|
||||
@ -33,8 +32,7 @@
|
||||
<Link
|
||||
:df="{
|
||||
fieldname: 'unit',
|
||||
fieldtype: 'Link',
|
||||
target: 'UOM',
|
||||
fieldtype: 'Data',
|
||||
label: 'Unit',
|
||||
}"
|
||||
size="small"
|
||||
@ -248,12 +246,12 @@ import Float from '../Controls/Float.vue';
|
||||
import Int from '../Controls/Int.vue';
|
||||
import Link from '../Controls/Link.vue';
|
||||
import Text from '../Controls/Text.vue';
|
||||
import { defineComponent } from 'vue';
|
||||
import { fyo } from 'src/initFyo';
|
||||
import { inject } from 'vue';
|
||||
import { DiscountType } from './types';
|
||||
import { Money } from 'pesa';
|
||||
import { fyo } from 'src/initFyo';
|
||||
import { defineComponent } from 'vue';
|
||||
import { SalesInvoiceItem } from 'models/baseModels/SalesInvoiceItem/SalesInvoiceItem';
|
||||
import { Money } from 'pesa';
|
||||
import { DiscountType } from './types';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'SelectedItemRow',
|
||||
|
@ -1,3 +1,5 @@
|
||||
import { Money } from "pesa";
|
||||
|
||||
export type ItemQtyMap = {
|
||||
[item: string]: { availableQty: number;[batch: string]: number };
|
||||
}
|
||||
@ -7,3 +9,12 @@ export type ItemSerialNumbers = { [item: string]: string };
|
||||
export type DiscountType = "percent" | "amount";
|
||||
|
||||
export type ModalName = 'ShiftOpen' | 'ShiftClose' | 'Payment'
|
||||
|
||||
export interface POSItem {
|
||||
item: string,
|
||||
rate: Money,
|
||||
availableQty: number,
|
||||
unit: string,
|
||||
hasBatch: boolean,
|
||||
hasSerialNumber: boolean,
|
||||
}
|
Loading…
Reference in New Issue
Block a user