mirror of
https://github.com/frappe/books.git
synced 2024-11-09 23:30:56 +00:00
incr: add basic stock ledger (w.i.p)
This commit is contained in:
parent
2bc0ce2237
commit
e1123ecc3a
@ -2,6 +2,7 @@ import { BalanceSheet } from './BalanceSheet/BalanceSheet';
|
||||
import { GeneralLedger } from './GeneralLedger/GeneralLedger';
|
||||
import { GSTR1 } from './GoodsAndServiceTax/GSTR1';
|
||||
import { GSTR2 } from './GoodsAndServiceTax/GSTR2';
|
||||
import { StockLedger } from './inventory/StockLedger';
|
||||
import { ProfitAndLoss } from './ProfitAndLoss/ProfitAndLoss';
|
||||
import { Report } from './Report';
|
||||
import { TrialBalance } from './TrialBalance/TrialBalance';
|
||||
@ -13,4 +14,5 @@ export const reports = {
|
||||
TrialBalance,
|
||||
GSTR1,
|
||||
GSTR2,
|
||||
StockLedger,
|
||||
} as Record<string, typeof Report>;
|
||||
|
75
reports/inventory/StockLedger.ts
Normal file
75
reports/inventory/StockLedger.ts
Normal file
@ -0,0 +1,75 @@
|
||||
import { t } from 'fyo';
|
||||
import { RawValueMap } from 'fyo/core/types';
|
||||
import { Action } from 'fyo/model/types';
|
||||
import { ModelNameEnum } from 'models/types';
|
||||
import getCommonExportActions from 'reports/commonExporter';
|
||||
import { Report } from 'reports/Report';
|
||||
import { ColumnField, ReportCell, ReportData, ReportRow } from 'reports/types';
|
||||
import { Field, RawValue } from 'schemas/types';
|
||||
import { isNumeric } from 'src/utils';
|
||||
|
||||
export class StockLedger extends Report {
|
||||
static title = t`Stock Ledger`;
|
||||
static reportName = 'stock-ledger';
|
||||
|
||||
loading: boolean = false;
|
||||
async setReportData(
|
||||
filter?: string | undefined,
|
||||
force?: boolean | undefined
|
||||
): Promise<void> {
|
||||
this.loading = true;
|
||||
this.reportData = await this._getReportData();
|
||||
this.loading = false;
|
||||
}
|
||||
|
||||
async _getReportData(): Promise<ReportData> {
|
||||
const columns = this.getColumns();
|
||||
const fieldnames = columns.map(({ fieldname }) => fieldname);
|
||||
const rawData = await this.fyo.db.getAllRaw(
|
||||
ModelNameEnum.StockLedgerEntry,
|
||||
{
|
||||
fields: fieldnames,
|
||||
}
|
||||
);
|
||||
|
||||
return this.convertRawDataToReportData(rawData, columns);
|
||||
}
|
||||
|
||||
convertRawDataToReportData(
|
||||
rawData: RawValueMap[],
|
||||
fields: Field[]
|
||||
): ReportData {
|
||||
const reportData: ReportData = [];
|
||||
for (const row of rawData) {
|
||||
reportData.push(this.convertRawDataRowToReportRow(row, fields));
|
||||
}
|
||||
return reportData;
|
||||
}
|
||||
|
||||
convertRawDataRowToReportRow(row: RawValueMap, fields: Field[]): ReportRow {
|
||||
const cells: ReportCell[] = [];
|
||||
for (const { fieldname, fieldtype } of fields) {
|
||||
const rawValue = row[fieldname] as RawValue;
|
||||
const value = this.fyo.format(rawValue, fieldtype);
|
||||
const align = isNumeric(fieldtype) ? 'right' : 'left';
|
||||
|
||||
cells.push({ rawValue, value, align });
|
||||
}
|
||||
|
||||
return { cells };
|
||||
}
|
||||
|
||||
getColumns(): ColumnField[] {
|
||||
return (
|
||||
this.fyo.schemaMap[ModelNameEnum.StockLedgerEntry]?.fields ?? []
|
||||
).filter((f) => !f.meta);
|
||||
}
|
||||
|
||||
getFilters(): Field[] | Promise<Field[]> {
|
||||
return [];
|
||||
}
|
||||
|
||||
getActions(): Action[] {
|
||||
return getCommonExportActions(this);
|
||||
}
|
||||
}
|
@ -127,7 +127,7 @@ function addNameField(schemaMap: SchemaMap) {
|
||||
continue;
|
||||
}
|
||||
|
||||
schema.fields.push(NAME_FIELD as Field);
|
||||
schema.fields.unshift(NAME_FIELD as Field);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,10 @@
|
||||
</PageHeader>
|
||||
|
||||
<!-- Filters -->
|
||||
<div v-if="report" class="grid grid-cols-5 gap-4 p-4 border-b">
|
||||
<div
|
||||
v-if="report && report.filters.length"
|
||||
class="grid grid-cols-5 gap-4 p-4 border-b"
|
||||
>
|
||||
<FormControl
|
||||
v-for="field in report.filters"
|
||||
:border="true"
|
||||
|
@ -87,6 +87,47 @@ async function getInventorySidebar(): Promise<SidebarRoot[]> {
|
||||
];
|
||||
}
|
||||
|
||||
async function getReportSidebar() {
|
||||
const reports = {
|
||||
label: t`Reports`,
|
||||
name: 'reports',
|
||||
icon: 'reports',
|
||||
route: '/report/GeneralLedger',
|
||||
items: [
|
||||
{
|
||||
label: t`General Ledger`,
|
||||
name: 'general-ledger',
|
||||
route: '/report/GeneralLedger',
|
||||
},
|
||||
{
|
||||
label: t`Profit And Loss`,
|
||||
name: 'profit-and-loss',
|
||||
route: '/report/ProfitAndLoss',
|
||||
},
|
||||
{
|
||||
label: t`Balance Sheet`,
|
||||
name: 'balance-sheet',
|
||||
route: '/report/BalanceSheet',
|
||||
},
|
||||
{
|
||||
label: t`Trial Balance`,
|
||||
name: 'trial-balance',
|
||||
route: '/report/TrialBalance',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
if (await getIsInventoryEnabled(fyo)) {
|
||||
reports.items.push({
|
||||
label: t`Stock Ledger`,
|
||||
name: 'stock-ledger',
|
||||
route: '/report/StockLedger',
|
||||
});
|
||||
}
|
||||
|
||||
return reports;
|
||||
}
|
||||
|
||||
async function getCompleteSidebar(): Promise<SidebarConfig> {
|
||||
return [
|
||||
{
|
||||
@ -194,34 +235,7 @@ async function getCompleteSidebar(): Promise<SidebarConfig> {
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: t`Reports`,
|
||||
name: 'reports',
|
||||
icon: 'reports',
|
||||
route: '/report/GeneralLedger',
|
||||
items: [
|
||||
{
|
||||
label: t`General Ledger`,
|
||||
name: 'general-ledger',
|
||||
route: '/report/GeneralLedger',
|
||||
},
|
||||
{
|
||||
label: t`Profit And Loss`,
|
||||
name: 'profit-and-loss',
|
||||
route: '/report/ProfitAndLoss',
|
||||
},
|
||||
{
|
||||
label: t`Balance Sheet`,
|
||||
name: 'balance-sheet',
|
||||
route: '/report/BalanceSheet',
|
||||
},
|
||||
{
|
||||
label: t`Trial Balance`,
|
||||
name: 'trial-balance',
|
||||
route: '/report/TrialBalance',
|
||||
},
|
||||
],
|
||||
},
|
||||
await getReportSidebar(),
|
||||
await getInventorySidebar(),
|
||||
await getRegionalSidebar(),
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user