mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 12:20:31 +00:00
fix: allocate landed cost on inventory items.
This commit is contained in:
@@ -1,5 +1,14 @@
|
||||
import { sumBy, round } from 'lodash';
|
||||
import * as R from 'ramda';
|
||||
import { defaultFastFieldShouldUpdate } from 'utils';
|
||||
|
||||
/**
|
||||
* Retrieve the landed cost transaction by the given id.
|
||||
*/
|
||||
export function getCostTransactionById(id, transactions) {
|
||||
return transactions.find((trans) => trans.id === id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve transaction entries of the given transaction id.
|
||||
*/
|
||||
@@ -8,6 +17,10 @@ export function getEntriesByTransactionId(transactions, id) {
|
||||
return transaction ? transaction.entries : [];
|
||||
}
|
||||
|
||||
export function getTransactionEntryById(transaction, transactionEntryId) {
|
||||
return transaction.entries.find((entry) => entry.id === transactionEntryId);
|
||||
}
|
||||
|
||||
export function allocateCostToEntries(total, allocateType, entries) {
|
||||
return R.compose(
|
||||
R.when(
|
||||
@@ -60,3 +73,18 @@ export function allocateCostByQuantity(total, entries) {
|
||||
cost: round(entry.percentageOfQuantity * total, 2),
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Detarmines the transactions selet field when should update.
|
||||
*/
|
||||
export function transactionsSelectShouldUpdate(newProps, oldProps) {
|
||||
return (
|
||||
newProps.transactions !== oldProps.transactions ||
|
||||
defaultFastFieldShouldUpdate(newProps, oldProps)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
export function resetAllocatedCostEntries(entries) {
|
||||
return entries.map((entry) => ({ ...entry, cost: 0 }));
|
||||
}
|
||||
Reference in New Issue
Block a user