Skip to content

Commit

Permalink
Merge pull request #478 from City-of-Helsinki/MVJ-7-fix-add-subventio…
Browse files Browse the repository at this point in the history
…ns-for-rent-adjustments

Fix adding subventions for newly added rent adjustments
  • Loading branch information
NC-jsAhonen authored May 6, 2024
2 parents c5ed6b2 + 5e67ae1 commit d97e5b6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
16 changes: 13 additions & 3 deletions src/leases/components/leaseSections/rent/RentAdjustmentEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
getDecisionById,
hasSubventionDataChanged,
hasSubventionValues,
isSubventionTypeSpecified,
} from '$src/leases/helpers';
import {getUiDataLeaseKey} from '$src/uiData/helpers';
import {
Expand Down Expand Up @@ -270,6 +271,7 @@ class RentAdjustmentsEdit extends PureComponent<Props> {
change,
field,
fullAmount,
subventionType,
managementSubventions,
temporarySubventions,
subventionBasePercent,
Expand All @@ -278,7 +280,15 @@ class RentAdjustmentsEdit extends PureComponent<Props> {

let newFullAmount = fullAmount

if (hasSubventionValues(managementSubventions, temporarySubventions, subventionBasePercent, subventionGraduatedPercent)) {
if (
isSubventionTypeSpecified(subventionType)
&& hasSubventionValues(
managementSubventions,
temporarySubventions,
subventionBasePercent,
subventionGraduatedPercent
)
) {
newFullAmount = this.calculateTotalSubventionPercent()
}

Expand Down Expand Up @@ -306,8 +316,8 @@ class RentAdjustmentsEdit extends PureComponent<Props> {
handleAddSubventions = () => {
const {change, field} = this.props;

// To make the subvention form visible: null => ""
change(formName, `${field}.subvention_type`, "");
// To make the subvention form visible: null => "unspecified"
change(formName, `${field}.subvention_type`, "unspecified");
}

handleRemoveSubventions = () => {
Expand Down
19 changes: 15 additions & 4 deletions src/leases/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -1549,12 +1549,23 @@ export const calculateSubventionDiscountTotal = (initialYearRent: number, manage
return Number(initialYearRent);
};

/**
* Check if subvention type is specified.
* The "unspecified" value is needed for rendering the subvention-related fields.
* @param {?string} subventionType
* @return {boolean}
*/
export const isSubventionTypeSpecified = (subventionType: ?string): boolean => {
return !!subventionType && subventionType !== "unspecified";
};

/**
* Check if subventions have values for calculation
* @param {number} initialYearRent
* @param {Object[]} managementSubventions
* @param {number} currentAmountPerArea
* @return {number}
* @param {?Array<Object>} managementSubventions
* @param {?Array<Object>} temporarySubventions
* @param {?string} subventionBasePercent
* @param {?string} subventionGraduatedPercent
* @return {boolean}
*/
export const hasSubventionValues = (managementSubventions: ?Array<Object>, temporarySubventions: ?Array<Object>, subventionBasePercent: ?string, subventionGraduatedPercent: ?string): boolean => {
let msWithValues = managementSubventions.filter((subvention) => !!subvention.subvention_amount)
Expand Down

0 comments on commit d97e5b6

Please sign in to comment.