Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: pos shift opening and closing #1069

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions fyo/model/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import type { PrintSettings } from 'models/baseModels/PrintSettings/PrintSetting
import type { InventorySettings } from 'models/inventory/InventorySettings';
import type { Misc } from 'models/baseModels/Misc';
import type { POSSettings } from 'models/inventory/Point of Sale/POSSettings';
import type { POSShift } from 'models/inventory/Point of Sale/POSShift';
import type { POSOpeningShift } from 'models/inventory/Point of Sale/POSOpeningShift';
import type { POSClosingShift } from 'models/inventory/Point of Sale/POSClosingShift';

/**
* The functions below are used for dynamic evaluation
Expand Down Expand Up @@ -57,7 +58,8 @@ export interface SinglesMap {
AccountingSettings?: AccountingSettings;
InventorySettings?: InventorySettings;
POSSettings?: POSSettings;
POSShift?: POSShift;
POSOpeningShift?: POSOpeningShift;
POSClosingShift?: POSClosingShift;
PrintSettings?: PrintSettings;
Defaults?: Defaults;
Misc?: Misc;
Expand Down
6 changes: 4 additions & 2 deletions models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ 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 { POSSettings } from './inventory/Point of Sale/POSSettings';
import { POSShift } from './inventory/Point of Sale/POSShift';
import { POSOpeningShift } from './inventory/Point of Sale/POSOpeningShift';
import { POSClosingShift } from './inventory/Point of Sale/POSClosingShift';

export const models = {
Account,
Expand Down Expand Up @@ -102,7 +103,8 @@ export const models = {
OpeningAmounts,
OpeningCash,
POSSettings,
POSShift,
POSOpeningShift,
POSClosingShift,
} as ModelMap;

export async function getRegionalModels(
Expand Down
2 changes: 1 addition & 1 deletion models/inventory/InventorySettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class InventorySettings extends Doc {
return !!this.enableStockReturns;
},
enablePointOfSale: () => {
return !!this.fyo.singles.POSShift?.isShiftOpen;
return !!this.fyo.singles.POSSettings?.isShiftOpen;
},
};
}
33 changes: 33 additions & 0 deletions models/inventory/Point of Sale/POSClosingShift.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { ListViewSettings } from 'fyo/model/types';
import { ClosingAmounts } from './ClosingAmounts';
import { ClosingCash } from './ClosingCash';
import { Doc } from 'fyo/model/doc';

export class POSClosingShift extends Doc {
closingAmounts?: ClosingAmounts[];
closingCash?: ClosingCash[];
closingDate?: Date;

get closingCashAmount() {
if (!this.closingCash) {
return this.fyo.pesa(0);
}

let closingAmount = this.fyo.pesa(0);

this.closingCash.map((row: ClosingCash) => {
const denomination = row.denomination ?? this.fyo.pesa(0);
const count = row.count ?? 0;

const amount = denomination.mul(count);
closingAmount = closingAmount.add(amount);
});
return closingAmount;
}

static getListViewSettings(): ListViewSettings {
return {
columns: ['name', 'closingDate'],
};
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import { ClosingAmounts } from './ClosingAmounts';
import { ClosingCash } from './ClosingCash';
import { Doc } from 'fyo/model/doc';
import { OpeningAmounts } from './OpeningAmounts';
import { OpeningCash } from './OpeningCash';
import { ListViewSettings } from 'fyo/model/types';

export class POSShift extends Doc {
closingAmounts?: ClosingAmounts[];
closingCash?: ClosingCash[];
closingDate?: Date;
isShiftOpen?: boolean;
export class POSOpeningShift extends Doc {
openingAmounts?: OpeningAmounts[];
openingCash?: OpeningCash[];
openingDate?: Date;
Expand All @@ -30,23 +25,6 @@ export class POSShift extends Doc {
return openingAmount;
}

get closingCashAmount() {
if (!this.closingCash) {
return this.fyo.pesa(0);
}

let closingAmount = this.fyo.pesa(0);

this.closingCash.map((row: ClosingCash) => {
const denomination = row.denomination ?? this.fyo.pesa(0);
const count = row.count ?? 0;

const amount = denomination.mul(count);
closingAmount = closingAmount.add(amount);
});
return closingAmount;
}

get openingTransferAmount() {
if (!this.openingAmounts) {
return this.fyo.pesa(0);
Expand All @@ -58,4 +36,10 @@ export class POSShift extends Doc {

return transferAmountRow.amount ?? this.fyo.pesa(0);
}

static getListViewSettings(): ListViewSettings {
return {
columns: ['name', 'openingDate'],
};
}
}
1 change: 1 addition & 0 deletions models/inventory/Point of Sale/POSSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from 'models/baseModels/Account/types';

export class POSSettings extends Doc {
isShiftOpen?: boolean;
inventory?: string;
cashAccount?: string;
writeOffAccount?: string;
Expand Down
7 changes: 6 additions & 1 deletion models/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ export enum ModelNameEnum {
CustomForm = 'CustomForm',
CustomField = 'CustomField',
POSSettings = 'POSSettings',
POSShift = 'POSShift'
POSOpeningShift = 'POSOpeningShift',
POSClosingShift = 'POSClosingShift',

ERPNextSyncSettings= 'ERPNextSyncSettings',
ERPNextSyncQueue = 'ERPNextSyncQueue',
FetchFromERPNextQueue = 'FetchFromERPNextQueue',
}

export type ModelName = keyof typeof ModelNameEnum;
24 changes: 24 additions & 0 deletions schemas/app/inventory/Point of Sale/POSClosingShift.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "POSClosingShift",
"label": "POS Closing Shift",
"naming": "random",
"fields": [
{
"fieldname": "closingDate",
"label": "Closing Date",
"fieldtype": "Datetime"
},
{
"fieldname": "closingCash",
"fieldtype": "Table",
"label": "Closing Cash",
"target": "ClosingCash"
},
{
"fieldname": "closingAmounts",
"fieldtype": "Table",
"label": "Closing Amounts",
"target": "ClosingAmounts"
}
]
}
24 changes: 24 additions & 0 deletions schemas/app/inventory/Point of Sale/POSOpeningShift.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "POSOpeningShift",
"label": "POS Opening Shift",
"naming": "random",
"fields": [
{
"fieldname": "openingDate",
"label": "Opening Date",
"fieldtype": "Datetime"
},
{
"fieldname": "openingCash",
"fieldtype": "Table",
"label": "Opening Cash",
"target": "OpeningCash"
},
{
"fieldname": "openingAmounts",
"fieldtype": "Table",
"label": "Opening Amounts",
"target": "OpeningAmounts"
}
]
}
7 changes: 7 additions & 0 deletions schemas/app/inventory/Point of Sale/POSSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
"isSingle": true,
"isChild": false,
"fields": [
{
"fieldname": "isShiftOpen",
"label": "Is POS Shift Open",
"fieldtype": "Check",
"default": false,
"hidden": false
},
{
"fieldname": "inventory",
"label": "Inventory",
Expand Down
43 changes: 0 additions & 43 deletions schemas/app/inventory/Point of Sale/POSShift.json

This file was deleted.

6 changes: 4 additions & 2 deletions schemas/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ import DefaultCashDenominations from './app/inventory/Point of Sale/DefaultCashD
import OpeningAmounts from './app/inventory/Point of Sale/OpeningAmounts.json';
import OpeningCash from './app/inventory/Point of Sale/OpeningCash.json';
import POSSettings from './app/inventory/Point of Sale/POSSettings.json';
import POSShift from './app/inventory/Point of Sale/POSShift.json';
import POSOpeningShift from './app/inventory/Point of Sale/POSOpeningShift.json';
import POSClosingShift from './app/inventory/Point of Sale/POSClosingShift.json';
import POSShiftAmounts from './app/inventory/Point of Sale/POSShiftAmounts.json';
import { Schema, SchemaStub } from './types';

Expand Down Expand Up @@ -170,6 +171,7 @@ export const appSchemas: Schema[] | SchemaStub[] = [
OpeningAmounts as Schema,
OpeningCash as Schema,
POSSettings as Schema,
POSShift as Schema,
POSOpeningShift as Schema,
POSClosingShift as Schema,
POSShiftAmounts as Schema,
];
Loading