2
0
mirror of https://github.com/frappe/books.git synced 2024-09-19 11:09:01 +00:00

feat: pos settings validations

This commit is contained in:
akshayitzme 2023-09-14 12:57:03 +05:30 committed by akshayitzme
parent ffbce23f03
commit 81be57be32
4 changed files with 46 additions and 9 deletions

View File

@ -189,7 +189,6 @@ export default defineComponent({
async handleSubmit() {
try {
validateClosingAmounts(this.posShiftDoc as POSShift);
await this.posShiftDoc?.set('isShiftOpen', false);
await this.posShiftDoc?.sync();
await transferPOSCashAndWriteOff(fyo, this.posShiftDoc as POSShift);

View File

@ -190,6 +190,7 @@ import {
getItemQtyMap,
getTotalQuantity,
getTotalTaxedAmount,
validateIsPosSettingsSet,
validateShipment,
validateSinv,
} from 'src/utils/pos';
@ -268,6 +269,7 @@ export default defineComponent({
},
async activated() {
toggleSidebar(false);
validateIsPosSettingsSet(fyo);
this.setSinvDoc();
this.setDefaultCustomer();
await this.setItemQtyMap();

View File

@ -16,6 +16,7 @@ import {
import { ItemQtyMap, ItemSerialNumbers } from 'src/components/POS/types';
import { fyo } from 'src/initFyo';
import { safeParseFloat } from 'utils/index';
import { showToast } from './interactive';
export async function getItemQtyMap(): Promise<ItemQtyMap> {
const itemQtyMap: ItemQtyMap = {};
@ -141,6 +142,37 @@ export async function validateShipment(itemSerialNumbers: ItemSerialNumbers) {
}
}
export function validateIsPosSettingsSet(fyo: Fyo) {
try {
const inventory = fyo.singles.POSSettings?.inventory;
if (!inventory) {
throw new ValidationError(
t`POS Inventory is not set. Please set it on POS Settings`
);
}
const cashAccount = fyo.singles.POSSettings?.cashAccount;
if (!cashAccount) {
throw new ValidationError(
t`POS Counter Cash Account is not set. Please set it on POS Settings`
);
}
const writeOffAccount = fyo.singles.POSSettings?.writeOffAccount;
if (!writeOffAccount) {
throw new ValidationError(
t`POS Write Off Account is not set. Please set it on POS Settings`
);
}
} catch (error) {
showToast({
type: 'error',
message: t`${error as string}`,
duration: 'long',
});
}
}
export function getTotalTaxedAmount(sinvDoc: SalesInvoice): Money {
let totalTaxedAmount = fyo.pesa(0);
if (!sinvDoc.items?.length || !sinvDoc.taxes?.length) {
@ -154,17 +186,21 @@ export function getTotalTaxedAmount(sinvDoc: SalesInvoice): Money {
}
export function validateClosingAmounts(posShiftDoc: POSShift) {
if (!posShiftDoc) {
throw new ValidationError(`POS Shift Document not loaded. Please reload.`);
}
posShiftDoc.closingAmounts?.map((row) => {
if (row.closingAmount?.isNegative()) {
try {
if (!posShiftDoc) {
throw new ValidationError(
t`Closing ${row.paymentMethod as string} Amount can not be negative.`
`POS Shift Document not loaded. Please reload.`
);
}
});
posShiftDoc.closingAmounts?.map((row) => {
if (row.closingAmount?.isNegative()) {
throw new ValidationError(
t`Closing ${row.paymentMethod as string} Amount can not be negative.`
);
}
});
} catch (error) {}
}
export async function transferPOSCashAndWriteOff(