BIG-125: prevent items entries from send amount computed attribute.

This commit is contained in:
a.bouhuolia
2021-09-28 18:37:10 +02:00
parent 96269ccafb
commit 0aca6d9af7
10 changed files with 225 additions and 100 deletions

View File

@@ -8,6 +8,7 @@ import {
transformToForm,
repeatValue,
ensureEntriesHasEmptyLine,
orderingLinesIndexes
} from 'utils';
const ERROR = {
@@ -104,3 +105,25 @@ export const accountsFieldShouldUpdate = (newProps, oldProps) => {
defaultFastFieldShouldUpdate(newProps, oldProps)
);
};
/**
* Filter expense entries that has no amount or expense account.
*/
export const filterNonZeroEntries = (categories) => {
return categories.filter(
(category) => category.amount && category.expense_account_id,
);
}
/**
* Transformes the form values to request body.
*/
export const transformFormValuesToRequest = (values) => {
const categories = filterNonZeroEntries(values.categories);
return {
...values,
categories: R.compose(orderingLinesIndexes)(categories),
};
};