mirror of
https://github.com/frappe/books.git
synced 2024-12-22 10:58:59 +00:00
feat: pos shift models
This commit is contained in:
parent
b8518c6c7d
commit
9930a15e6e
@ -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;
|
||||
|
@ -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(),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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(
|
||||
|
@ -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;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
26
models/inventory/Point of Sale/ClosingAmounts.ts
Normal file
26
models/inventory/Point of Sale/ClosingAmounts.ts
Normal 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);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
7
models/inventory/Point of Sale/OpeningAmounts.ts
Normal file
7
models/inventory/Point of Sale/OpeningAmounts.ts
Normal 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';
|
||||
}
|
44
models/inventory/Point of Sale/POSShift.ts
Normal file
44
models/inventory/Point of Sale/POSShift.ts
Normal 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);
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user