Skip to content

Commit

Permalink
Merge pull request #518 from bigcapitalhq/BIG-213
Browse files Browse the repository at this point in the history
fix: Tax rate not saving on creating a new invoice
  • Loading branch information
abouolia authored Jun 24, 2024
2 parents 5dde7f5 + e783cfe commit 3e437a0
Showing 1 changed file with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ export const defaultInvoice = {
attachments: [],
};

// Invoice entry request schema.
export const defaultReqInvoiceEntry = {
index: 0,
item_id: '',
rate: '',
discount: '',
quantity: '',
description: '',
tax_rate_id: '',
};

/**
* Transform invoice to initial values in edit mode.
*/
Expand Down Expand Up @@ -175,13 +186,27 @@ export const ITEMS_FILTER_ROLES_QUERY = JSON.stringify([
},
]);

/**
* Transformes bill entries to submit request.
*/
const transformEntriesToRequest = (entries) => {
return R.compose(
R.map(R.compose(R.curry(transformToForm)(R.__, defaultReqInvoiceEntry))),
filterNonZeroEntries,
)(entries);
};

/**
* Filters the givne non-zero entries.
*/
const filterNonZeroEntries = (entries) => {
return entries.filter((item) => item.item_id && item.quantity);
};

/**
* Transformes the form values to request body values.
*/
export function transformValueToRequest(values) {
const entries = values.entries.filter(
(item) => item.item_id && item.quantity,
);
return {
...omit(values, [
'invoice_no',
Expand All @@ -194,9 +219,7 @@ export function transformValueToRequest(values) {
invoice_no: values.invoice_no,
}),
is_inclusive_tax: values.inclusive_exclusive_tax === TaxType.Inclusive,
entries: entries.map((entry) => ({
...omit(entry, ['amount', 'tax_amount', 'tax_rate']),
})),
entries: transformEntriesToRequest(values.entries),
delivered: false,
attachments: transformAttachmentsToRequest(values),
};
Expand Down

0 comments on commit 3e437a0

Please sign in to comment.