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

feat: pos shift models

This commit is contained in:
akshayitzme 2023-08-22 12:18:51 +05:30 committed by akshayitzme
parent b8518c6c7d
commit 9930a15e6e
8 changed files with 113 additions and 1 deletions

View File

@ -10,6 +10,7 @@ import type { Defaults } from 'models/baseModels/Defaults/Defaults';
import type { PrintSettings } from 'models/baseModels/PrintSettings/PrintSettings';
import type { InventorySettings } from 'models/inventory/InventorySettings';
import type { Misc } from 'models/baseModels/Misc';
import type { POSShift } from 'models/inventory/Point of Sale/POSShift';
/**
* The functions below are used for dynamic evaluation
@ -54,6 +55,7 @@ export interface SinglesMap {
SystemSettings?: SystemSettings;
AccountingSettings?: AccountingSettings;
InventorySettings?: InventorySettings;
POSShift?: POSShift;
PrintSettings?: PrintSettings;
Defaults?: Defaults;
Misc?: Misc;

View File

@ -1,3 +1,4 @@
import { DefaultCashDenominations } from 'models/inventory/Point of Sale/DefaultCashDenominations';
import { Doc } from 'fyo/model/doc';
import { FiltersMap, HiddenMap } from 'fyo/model/types';
import { ModelNameEnum } from 'models/types';
@ -35,6 +36,13 @@ export class Defaults extends Doc {
purchaseReceiptPrintTemplate?: string;
stockMovementPrintTemplate?: string;
// Point of Sale
posAdjustmentAccount?: string;
posCashDenominations?: DefaultCashDenominations[];
posCustomer?: string;
posInventory?: string;
posPrintTemplate?: string;
static commonFilters = {
// Auto Payments
salesPaymentAccount: () => ({ isGroup: false, accountType: 'Cash' }),
@ -82,6 +90,10 @@ export class Defaults extends Doc {
return () => !this.fyo.singles.AccountingSettings?.enableInventory;
}
getPointOfSaleHidden() {
return () => !this.fyo.singles.InventorySettings?.enablePointOfSale;
}
hidden: HiddenMap = {
stockMovementNumberSeries: this.getInventoryHidden(),
shipmentNumberSeries: this.getInventoryHidden(),
@ -91,6 +103,11 @@ export class Defaults extends Doc {
shipmentPrintTemplate: this.getInventoryHidden(),
purchaseReceiptPrintTemplate: this.getInventoryHidden(),
stockMovementPrintTemplate: this.getInventoryHidden(),
posAdjustmentAccount: this.getPointOfSaleHidden(),
posCashDenominations: this.getPointOfSaleHidden(),
posCustomer: this.getPointOfSaleHidden(),
posInventory: this.getPointOfSaleHidden(),
posPrintTemplate: this.getPointOfSaleHidden(),
};
}

View File

@ -33,6 +33,11 @@ import { ShipmentItem } from './inventory/ShipmentItem';
import { StockLedgerEntry } from './inventory/StockLedgerEntry';
import { StockMovement } from './inventory/StockMovement';
import { StockMovementItem } from './inventory/StockMovementItem';
import { ClosingAmounts } from './inventory/Point of Sale/ClosingAmounts';
import { ClosingCash } from './inventory/Point of Sale/ClosingCash';
import { OpeningAmounts } from './inventory/Point of Sale/OpeningAmounts';
import { OpeningCash } from './inventory/Point of Sale/OpeningCash';
import { POSShift } from './inventory/Point of Sale/POSShift';
export const models = {
Account,
@ -70,6 +75,12 @@ export const models = {
ShipmentItem,
PurchaseReceipt,
PurchaseReceiptItem,
// POS Models
ClosingAmounts,
ClosingCash,
OpeningAmounts,
OpeningCash,
POSShift,
} as ModelMap;
export async function getRegionalModels(

View File

@ -12,6 +12,7 @@ export class InventorySettings extends Doc {
enableSerialNumber?: boolean;
enableUomConversions?: boolean;
enableStockReturns?: boolean;
enablePointOfSale?: boolean;
static filters: FiltersMap = {
stockInHand: () => ({
@ -44,5 +45,8 @@ export class InventorySettings extends Doc {
enableStockReturns: () => {
return !!this.enableStockReturns;
},
enablePointOfSale: () => {
return !!this.fyo.singles.POSShift?.isShiftOpen;
},
};
}

View File

@ -0,0 +1,26 @@
import { Doc } from 'fyo/model/doc';
import { FormulaMap } from 'fyo/model/types';
import { Money } from 'pesa';
export class ClosingAmounts extends Doc {
openingAmount?: Money;
closingAmount?: Money;
expectedAmount?: Money;
differenceAmount?: Money;
formulas: FormulaMap = {
differenceAmount: {
formula: () => {
if (!this.closingAmount) {
return this.fyo.pesa(0);
}
if (!this.expectedAmount) {
return this.fyo.pesa(0);
}
return this.closingAmount.sub(this.expectedAmount);
},
},
};
}

View File

@ -0,0 +1,7 @@
import { Doc } from 'fyo/model/doc';
import { Money } from 'pesa';
export class OpeningAmounts extends Doc {
amount?: Money;
paymentMethod?: 'Cash' | 'Transfer';
}

View File

@ -0,0 +1,44 @@
import { ClosingAmounts } from './ClosingAmounts';
import { ClosingCash } from './ClosingCash';
import { Doc } from 'fyo/model/doc';
import { OpeningAmounts } from './OpeningAmounts';
import { OpeningCash } from './OpeningCash';
export class POSShift extends Doc {
isShiftOpen?: boolean;
openingDate?: Date;
closingDate?: Date;
openingAmounts?: OpeningAmounts[];
closingAmounts?: ClosingAmounts[];
openingCash?: OpeningCash[];
closingCash?: ClosingCash[];
get openingCashAmount() {
if (!this.openingCash) {
return this.fyo.pesa(0);
}
let openingAmount = this.fyo.pesa(0);
this.openingCash.map((row: OpeningCash) => {
const denomination = row.denomination ?? this.fyo.pesa(0);
const count = row.count ?? 0;
const amount = denomination.mul(count);
openingAmount = openingAmount.add(amount);
});
return openingAmount;
}
get openingTransferAmount() {
if (!this.openingAmounts) {
return this.fyo.pesa(0);
}
const transferAmountRow = this.openingAmounts.filter(
(row) => row.paymentMethod === 'Transfer'
)[0];
return transferAmountRow.amount ?? this.fyo.pesa(0);
}
}

View File

@ -45,7 +45,8 @@ export enum ModelNameEnum {
PurchaseReceiptItem = 'PurchaseReceiptItem',
Location = 'Location',
CustomForm = 'CustomForm',
CustomField = 'CustomField'
CustomField = 'CustomField',
POSShift = 'POSShift'
}
export type ModelName = keyof typeof ModelNameEnum;