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:
parent
46d84a38fc
commit
f9a95a7c9b
@ -8,13 +8,14 @@ import {
|
||||
HiddenMap,
|
||||
ListViewSettings,
|
||||
ReadOnlyMap,
|
||||
ValidationMap
|
||||
ValidationMap,
|
||||
} from 'fyo/model/types';
|
||||
import { ValidationError } from 'fyo/utils/errors';
|
||||
import { Money } from 'pesa';
|
||||
import { AccountRootTypeEnum, AccountTypeEnum } from '../Account/types';
|
||||
|
||||
export class Item extends Doc {
|
||||
trackItem?: boolean;
|
||||
itemType?: 'Product' | 'Service';
|
||||
|
||||
formulas: FormulaMap = {
|
||||
@ -32,6 +33,11 @@ export class Item extends Doc {
|
||||
},
|
||||
expenseAccount: {
|
||||
formula: async () => {
|
||||
if (this.trackItem) {
|
||||
return this.fyo.singles.InventorySettings
|
||||
?.stockReceivedButNotBilled as string;
|
||||
}
|
||||
|
||||
const cogs = await this.fyo.db.getAllRaw('Account', {
|
||||
filters: {
|
||||
accountType: AccountTypeEnum['Cost of Goods Sold'],
|
||||
@ -44,7 +50,7 @@ export class Item extends Doc {
|
||||
return cogs[0].name as string;
|
||||
}
|
||||
},
|
||||
dependsOn: ['itemType'],
|
||||
dependsOn: ['itemType', 'trackItem'],
|
||||
},
|
||||
};
|
||||
|
||||
@ -53,9 +59,11 @@ export class Item extends Doc {
|
||||
isGroup: false,
|
||||
rootType: AccountRootTypeEnum.Income,
|
||||
}),
|
||||
expenseAccount: () => ({
|
||||
expenseAccount: (doc) => ({
|
||||
isGroup: false,
|
||||
rootType: AccountRootTypeEnum.Expense,
|
||||
rootType: doc.trackItem
|
||||
? AccountRootTypeEnum.Liability
|
||||
: AccountRootTypeEnum.Expense,
|
||||
}),
|
||||
};
|
||||
|
||||
|
@ -2,6 +2,7 @@ import { Fyo, t } from 'fyo';
|
||||
import { Action } from 'fyo/model/types';
|
||||
import { cloneDeep } from 'lodash';
|
||||
import { DateTime } from 'luxon';
|
||||
import { ValuationMethod } from 'models/inventory/types';
|
||||
import { ModelNameEnum } from 'models/types';
|
||||
import getCommonExportActions from 'reports/commonExporter';
|
||||
import { Report } from 'reports/Report';
|
||||
@ -76,8 +77,13 @@ export class StockLedger extends Report {
|
||||
}
|
||||
|
||||
async _setRawData() {
|
||||
const valuationMethod =
|
||||
(this.fyo.singles.InventorySettings?.valuationMethod as
|
||||
| ValuationMethod
|
||||
| undefined) ?? ValuationMethod.FIFO;
|
||||
|
||||
const rawSLEs = await getRawStockLedgerEntries(this.fyo);
|
||||
this._rawData = getStockLedgerEntries(rawSLEs);
|
||||
this._rawData = getStockLedgerEntries(rawSLEs, valuationMethod);
|
||||
}
|
||||
|
||||
_getFilteredRawData(rawData: ComputedStockLedgerEntry[]) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { Fyo } from 'fyo';
|
||||
import { StockQueue } from 'models/inventory/stockQueue';
|
||||
import { ValuationMethod } from 'models/inventory/types';
|
||||
import { ModelNameEnum } from 'models/types';
|
||||
import { safeParseFloat, safeParseInt } from 'utils/index';
|
||||
import { ComputedStockLedgerEntry, RawStockLedgerEntry } from './types';
|
||||
@ -24,7 +25,8 @@ export async function getRawStockLedgerEntries(fyo: Fyo) {
|
||||
}
|
||||
|
||||
export function getStockLedgerEntries(
|
||||
rawSLEs: RawStockLedgerEntry[]
|
||||
rawSLEs: RawStockLedgerEntry[],
|
||||
valuationMethod: ValuationMethod
|
||||
): ComputedStockLedgerEntry[] {
|
||||
type Item = string;
|
||||
type Location = string;
|
||||
@ -60,7 +62,11 @@ export function getStockLedgerEntries(
|
||||
}
|
||||
|
||||
const balanceQuantity = q.quantity;
|
||||
const valuationRate = q.fifo;
|
||||
let valuationRate = q.fifo;
|
||||
if (valuationMethod === ValuationMethod.MovingAverage) {
|
||||
valuationRate = q.movingAverage;
|
||||
}
|
||||
|
||||
const balanceValue = q.value;
|
||||
const valueChange = balanceValue - initialValue;
|
||||
|
||||
|
@ -71,7 +71,7 @@
|
||||
},
|
||||
{
|
||||
"fieldname": "incomeAccount",
|
||||
"label": "Income",
|
||||
"label": "Sales Acc.",
|
||||
"fieldtype": "Link",
|
||||
"target": "Account",
|
||||
"placeholder": "Income",
|
||||
@ -80,7 +80,7 @@
|
||||
},
|
||||
{
|
||||
"fieldname": "expenseAccount",
|
||||
"label": "Expense",
|
||||
"label": "Purchase Acc.",
|
||||
"fieldtype": "Link",
|
||||
"target": "Account",
|
||||
"placeholder": "Expense",
|
||||
|
Loading…
Reference in New Issue
Block a user