fix: allocate landed cost on inventory items.

This commit is contained in:
a.bouhuolia
2021-12-04 16:32:37 +02:00
parent 008faaece6
commit d3c5131020
15 changed files with 277 additions and 77 deletions

View File

@@ -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 }));
}