Skip to content

Commit

Permalink
IA-2456 ethiopian calendar financial yearly nov
Browse files Browse the repository at this point in the history
  • Loading branch information
mestachs committed Jan 21, 2025
1 parent f44bcf1 commit 95f2985
Show file tree
Hide file tree
Showing 10 changed files with 222 additions and 11 deletions.
1 change: 1 addition & 0 deletions hat/assets/js/apps/Iaso/domains/forms/types/forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ type PeriodType =
| 'QUARTER_NOV'
| 'SIX_MONTH'
| 'YEAR'
| 'FINANCIAL_NOV'
| null;

type ChangeRequestModeType = 'CR_MODE_NONE' | 'CR_MODE_IF_REFERENCE_FORM';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
QUARTERS_NOV_RANGE,
SEMESTERS,
SEMESTERS_RANGE,
PERIOD_TYPE_FINANCIAL_NOV,
} from '../constants';
import MESSAGES from '../messages';

Expand Down Expand Up @@ -192,7 +193,7 @@ const PeriodPicker: FunctionComponent<Props> = ({
) && (
<Grid
item
sm={periodType === PERIOD_TYPE_YEAR ? 12 : 6}
sm={(periodType === PERIOD_TYPE_YEAR || periodType === PERIOD_TYPE_FINANCIAL_NOV )? 12 : 6}
>
<InputComponent
keyValue="year"
Expand Down
3 changes: 3 additions & 0 deletions hat/assets/js/apps/Iaso/domains/periods/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const PERIOD_TYPE_YEAR = 'YEAR';
export const PERIOD_TYPE_SIX_MONTH = 'SIX_MONTH';
export const PERIOD_TYPE_QUARTER = 'QUARTER';
export const PERIOD_TYPE_QUARTER_NOV = 'QUARTER_NOV'
export const PERIOD_TYPE_FINANCIAL_NOV = 'FINANCIAL_NOV'
export const PERIOD_TYPE_MONTH = 'MONTH';
export const PERIOD_TYPE_PLACEHOLDER = 'EMPTY';
export const NO_PERIOD = 'NO_PERIOD';
Expand All @@ -15,6 +16,7 @@ export const PERIOD_TYPES = [
PERIOD_TYPE_QUARTER_NOV,
PERIOD_TYPE_SIX_MONTH,
PERIOD_TYPE_YEAR,
PERIOD_TYPE_FINANCIAL_NOV
];

export const periodTypeOptions = [
Expand All @@ -23,6 +25,7 @@ export const periodTypeOptions = [
PERIOD_TYPE_QUARTER,
PERIOD_TYPE_QUARTER_NOV,
PERIOD_TYPE_YEAR,
PERIOD_TYPE_FINANCIAL_NOV,
].map(periodType => ({
value: periodType,
label: MESSAGES[periodType.toLowerCase()],
Expand Down
4 changes: 4 additions & 0 deletions hat/assets/js/apps/Iaso/domains/periods/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const MESSAGES = defineMessages({
id: 'iaso.label.quarter_nov',
defaultMessage: 'Quarter November',
},
financial_nov: {
id: 'iaso.label.financial_nov',
defaultMessage: 'Financial Yearly Nov',
},
month: {
id: 'iaso.label.month',
defaultMessage: 'Month',
Expand Down
67 changes: 67 additions & 0 deletions hat/assets/js/apps/Iaso/domains/periods/models.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Period } from './models';
import {
PERIOD_TYPE_DAY,
PERIOD_TYPE_FINANCIAL_NOV,
PERIOD_TYPE_MONTH,
PERIOD_TYPE_QUARTER,
PERIOD_TYPE_QUARTER_NOV,
Expand Down Expand Up @@ -400,6 +401,72 @@ describe('Periods model', () => {
});
});


describe('financial nov string', () => {
before(() => {
periodString = '2018Nov';
period = new Period(periodString);
expectedPeriod = {
periodType: PERIOD_TYPE_FINANCIAL_NOV,
month: 10,
day: 1,
quarter: 2,
semester: 2,
year: 2018,
periodString,
};
});
it('should create a quarterly period object', () => {
expect(period).to.eql(expectedPeriod);
});
it('asPeriodType should create a quarterly period object', () => {
expect(period.asPeriodType(PERIOD_TYPE_FINANCIAL_NOV)).to.eql(
expectedPeriod,
);
});
it('monthRange should return correct month range', () => {
expect(period.monthRange).to.eql([11,12,1,2,3,4,5,6,7,8,9,10]);
});
it('toCode should return correct code', () => {
expect(period.toCode()).to.eql('2018Nov');
});
it('next should return next year string', () => {
expect(period.next(periodString)).to.eql(`2019Nov`);
});
it('pervious should return previous year string', () => {
expect(period.previous(periodString)).to.eql("2017Nov");
});
it('next should return next year quarter string', () => {
expect(period.next("2020NovQ4")).to.eql(`2021NovQ1`);
});
it('nextPeriods should return next 2 years', () => {
expect(period.nextPeriods(2)).to.eql(['2019Nov', '2020Nov']);
});
it('previousPeriods should return previous 2 years', () => {
expect(period.previousPeriods(2)).to.eql(['2016Nov', '2017Nov']);
});
it('getPeriodType should correct period type', () => {
expect(Period.getPeriodType('2017Nov')).to.eql(PERIOD_TYPE_FINANCIAL_NOV);
});
describe('isBefore', () => {
it('should return true', () => {
expect(Period.isBefore('2017Nov', '2018Nov')).to.eql(true);
});
it('should return false', () => {
expect(Period.isBefore('2018Nov', '2017Nov')).to.eql(false);
});
});
describe('isAfter', () => {
it('should return true', () => {
expect(Period.isAfter('2018Nov', '2017Nov')).to.eql(true);
});
it('should return false', () => {
expect(Period.isAfter('2017Nov', '2017Nov')).to.eql(false);
});
});
});


describe('sixmonthly string', () => {
before(() => {
periodString = '2020S1';
Expand Down
54 changes: 52 additions & 2 deletions hat/assets/js/apps/Iaso/domains/periods/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
PERIOD_TYPE_QUARTER_NOV,
PERIOD_TYPE_SIX_MONTH,
PERIOD_TYPE_YEAR,
PERIOD_TYPE_FINANCIAL_NOV,
} from './constants';

export type PeriodObject = {
Expand Down Expand Up @@ -80,6 +81,9 @@ export class Period {
case PERIOD_TYPE_YEAR:
periodTypeString = `${this.year}`;
break;
case PERIOD_TYPE_FINANCIAL_NOV:
periodTypeString = `${this.year}Nov`;
break;
default:
throw new Error(`Invalid period type ${periodType}`);
}
Expand All @@ -99,6 +103,8 @@ export class Period {
return _.range(this.month - 2, this.month + 1);
case PERIOD_TYPE_SIX_MONTH:
return _.range(this.month - 5, this.month + 1);
case PERIOD_TYPE_FINANCIAL_NOV:
return [11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
default:
return _.range(this.month - 11, this.month + 1);
}
Expand Down Expand Up @@ -129,6 +135,8 @@ export class Period {
return `NovQ${this.quarter}/${this.year}`;
case PERIOD_TYPE_SIX_MONTH:
return `S${this.semester}/${this.year}`;
case PERIOD_TYPE_FINANCIAL_NOV:
return `${this.year}Nov`;
default:
return `${this.year}`;
}
Expand All @@ -141,6 +149,12 @@ export class Period {
Period.parseQuarterNovString(periodString),
];
}
if (periodString.includes('Nov')) {
return [
PERIOD_TYPE_FINANCIAL_NOV,
Period.parseFinancialNovString(periodString),
];
}
if (periodString.includes('Q')) {
return [
PERIOD_TYPE_QUARTER,
Expand Down Expand Up @@ -170,6 +184,9 @@ export class Period {
if (periodString.includes('NovQ') && periodString.length === 9) {
return PERIOD_TYPE_QUARTER_NOV;
}
if (periodString.includes('Nov') && periodString.length === 7) {
return PERIOD_TYPE_FINANCIAL_NOV;
}
if (periodString.includes('Q') && periodString.length === 6) {
return PERIOD_TYPE_QUARTER;
}
Expand Down Expand Up @@ -263,6 +280,16 @@ export class Period {
day: 31,
};
}
static parseFinancialNovString(yearString: string): PeriodObject {
const year = Number(yearString.slice(0, 4));
return {
month: 10,
quarter: 1,
semester: 2,
year,
day: 31,
};
}

static padMonth(n: number): string | number {
return n < 10 ? `0${n}` : n;
Expand Down Expand Up @@ -323,7 +350,10 @@ export class Period {
if (p1.periodType === PERIOD_TYPE_SIX_MONTH) {
return p1.semester <= p2.semester;
}
if (p1.periodType === PERIOD_TYPE_YEAR) {
if (
p1.periodType === PERIOD_TYPE_YEAR ||
p1.periodType === PERIOD_TYPE_FINANCIAL_NOV
) {
return true;
}
}
Expand Down Expand Up @@ -385,7 +415,10 @@ export class Period {
if (p1.periodType === PERIOD_TYPE_SIX_MONTH) {
return p1.semester >= p2.semester;
}
if (p1.periodType === PERIOD_TYPE_YEAR) {
if (
p1.periodType === PERIOD_TYPE_YEAR ||
p1.periodType === PERIOD_TYPE_FINANCIAL_NOV
) {
return true;
}
}
Expand Down Expand Up @@ -461,6 +494,11 @@ export class Period {
}
return `${year}NovQ${quarter}`;
}
nextFinancialNov(period: string): string {
let year = parseInt(period.slice(0, 4), 0);
year += 1;
return `${year}Nov`;
}

nextSixMonth(period: string): string {
let year = parseInt(period.slice(0, 4), 0);
Expand Down Expand Up @@ -498,6 +536,12 @@ export class Period {
return `${year}NovQ${quarter}`;
}

previousFinancialNov(period: string): string {
let year = parseInt(period.slice(0, 4), 0);
year -= 1;
return `${year}Nov`;
}

previousSixMonth(period: string): string {
let year = parseInt(period.slice(0, 4), 0);
let sixMonth = parseInt(period.slice(5, 6), 0);
Expand All @@ -514,6 +558,9 @@ export class Period {
if (period.includes('NovQ')) {
return this.nextQuarterNov(period);
}
if (period.includes('Nov')) {
return this.nextFinancialNov(period);
}
if (period.includes('Q')) {
return this.nextQuarter(period);
}
Expand All @@ -537,6 +584,9 @@ export class Period {
if (period.includes('NovQ')) {
return this.previousQuarterNov(period);
}
if (period.includes('Nov')) {
return this.previousFinancialNov(period);
}
if (period.includes('Q')) {
return this.previousQuarter(period);
}
Expand Down
4 changes: 4 additions & 0 deletions hat/assets/js/apps/Iaso/domains/periods/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
PERIOD_TYPE_QUARTER,
PERIOD_TYPE_QUARTER_NOV,
PERIOD_TYPE_SIX_MONTH,
PERIOD_TYPE_FINANCIAL_NOV,
QUARTERS,
QUARTERS_NOV,
SEMESTERS,
Expand Down Expand Up @@ -91,6 +92,9 @@ export const getPeriodPickerString = (periodType, period, value) => {
return '';
}
switch (periodType) {
case PERIOD_TYPE_FINANCIAL_NOV: {
return period.year ? `${period.year}Nov` : null;
}
case PERIOD_TYPE_DAY: {
return value;
}
Expand Down
1 change: 1 addition & 0 deletions iaso/models/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class Form(SoftDeletableModel):
(periods.PERIOD_TYPE_QUARTER_NOV, _("Quarter Nov")),
(periods.PERIOD_TYPE_SIX_MONTH, _("Six-month")),
(periods.PERIOD_TYPE_YEAR, _("Year")),
(periods.PERIOD_TYPE_FINANCIAL_NOV, _("Financial Nov")),
)

CHANGE_REQUEST_MODE = (
Expand Down
Loading

0 comments on commit 95f2985

Please sign in to comment.