2
0
mirror of https://github.com/frappe/books.git synced 2025-01-03 07:12:21 +00:00

incr: update accounts

- rename account fields on item
- change valuation method in stock ledger
This commit is contained in:
18alantom 2022-11-21 15:27:59 +05:30
parent 46d84a38fc
commit f9a95a7c9b
4 changed files with 29 additions and 9 deletions

View File

@ -8,13 +8,14 @@ import {
HiddenMap, HiddenMap,
ListViewSettings, ListViewSettings,
ReadOnlyMap, ReadOnlyMap,
ValidationMap ValidationMap,
} from 'fyo/model/types'; } from 'fyo/model/types';
import { ValidationError } from 'fyo/utils/errors'; import { ValidationError } from 'fyo/utils/errors';
import { Money } from 'pesa'; import { Money } from 'pesa';
import { AccountRootTypeEnum, AccountTypeEnum } from '../Account/types'; import { AccountRootTypeEnum, AccountTypeEnum } from '../Account/types';
export class Item extends Doc { export class Item extends Doc {
trackItem?: boolean;
itemType?: 'Product' | 'Service'; itemType?: 'Product' | 'Service';
formulas: FormulaMap = { formulas: FormulaMap = {
@ -32,6 +33,11 @@ export class Item extends Doc {
}, },
expenseAccount: { expenseAccount: {
formula: async () => { formula: async () => {
if (this.trackItem) {
return this.fyo.singles.InventorySettings
?.stockReceivedButNotBilled as string;
}
const cogs = await this.fyo.db.getAllRaw('Account', { const cogs = await this.fyo.db.getAllRaw('Account', {
filters: { filters: {
accountType: AccountTypeEnum['Cost of Goods Sold'], accountType: AccountTypeEnum['Cost of Goods Sold'],
@ -44,7 +50,7 @@ export class Item extends Doc {
return cogs[0].name as string; return cogs[0].name as string;
} }
}, },
dependsOn: ['itemType'], dependsOn: ['itemType', 'trackItem'],
}, },
}; };
@ -53,9 +59,11 @@ export class Item extends Doc {
isGroup: false, isGroup: false,
rootType: AccountRootTypeEnum.Income, rootType: AccountRootTypeEnum.Income,
}), }),
expenseAccount: () => ({ expenseAccount: (doc) => ({
isGroup: false, isGroup: false,
rootType: AccountRootTypeEnum.Expense, rootType: doc.trackItem
? AccountRootTypeEnum.Liability
: AccountRootTypeEnum.Expense,
}), }),
}; };

View File

@ -2,6 +2,7 @@ import { Fyo, t } from 'fyo';
import { Action } from 'fyo/model/types'; import { Action } from 'fyo/model/types';
import { cloneDeep } from 'lodash'; import { cloneDeep } from 'lodash';
import { DateTime } from 'luxon'; import { DateTime } from 'luxon';
import { ValuationMethod } from 'models/inventory/types';
import { ModelNameEnum } from 'models/types'; import { ModelNameEnum } from 'models/types';
import getCommonExportActions from 'reports/commonExporter'; import getCommonExportActions from 'reports/commonExporter';
import { Report } from 'reports/Report'; import { Report } from 'reports/Report';
@ -76,8 +77,13 @@ export class StockLedger extends Report {
} }
async _setRawData() { async _setRawData() {
const valuationMethod =
(this.fyo.singles.InventorySettings?.valuationMethod as
| ValuationMethod
| undefined) ?? ValuationMethod.FIFO;
const rawSLEs = await getRawStockLedgerEntries(this.fyo); const rawSLEs = await getRawStockLedgerEntries(this.fyo);
this._rawData = getStockLedgerEntries(rawSLEs); this._rawData = getStockLedgerEntries(rawSLEs, valuationMethod);
} }
_getFilteredRawData(rawData: ComputedStockLedgerEntry[]) { _getFilteredRawData(rawData: ComputedStockLedgerEntry[]) {

View File

@ -1,5 +1,6 @@
import { Fyo } from 'fyo'; import { Fyo } from 'fyo';
import { StockQueue } from 'models/inventory/stockQueue'; import { StockQueue } from 'models/inventory/stockQueue';
import { ValuationMethod } from 'models/inventory/types';
import { ModelNameEnum } from 'models/types'; import { ModelNameEnum } from 'models/types';
import { safeParseFloat, safeParseInt } from 'utils/index'; import { safeParseFloat, safeParseInt } from 'utils/index';
import { ComputedStockLedgerEntry, RawStockLedgerEntry } from './types'; import { ComputedStockLedgerEntry, RawStockLedgerEntry } from './types';
@ -24,7 +25,8 @@ export async function getRawStockLedgerEntries(fyo: Fyo) {
} }
export function getStockLedgerEntries( export function getStockLedgerEntries(
rawSLEs: RawStockLedgerEntry[] rawSLEs: RawStockLedgerEntry[],
valuationMethod: ValuationMethod
): ComputedStockLedgerEntry[] { ): ComputedStockLedgerEntry[] {
type Item = string; type Item = string;
type Location = string; type Location = string;
@ -60,7 +62,11 @@ export function getStockLedgerEntries(
} }
const balanceQuantity = q.quantity; const balanceQuantity = q.quantity;
const valuationRate = q.fifo; let valuationRate = q.fifo;
if (valuationMethod === ValuationMethod.MovingAverage) {
valuationRate = q.movingAverage;
}
const balanceValue = q.value; const balanceValue = q.value;
const valueChange = balanceValue - initialValue; const valueChange = balanceValue - initialValue;

View File

@ -71,7 +71,7 @@
}, },
{ {
"fieldname": "incomeAccount", "fieldname": "incomeAccount",
"label": "Income", "label": "Sales Acc.",
"fieldtype": "Link", "fieldtype": "Link",
"target": "Account", "target": "Account",
"placeholder": "Income", "placeholder": "Income",
@ -80,7 +80,7 @@
}, },
{ {
"fieldname": "expenseAccount", "fieldname": "expenseAccount",
"label": "Expense", "label": "Purchase Acc.",
"fieldtype": "Link", "fieldtype": "Link",
"target": "Account", "target": "Account",
"placeholder": "Expense", "placeholder": "Expense",