2
0
mirror of https://github.com/frappe/books.git synced 2024-12-23 03:19:01 +00:00

fix: Set fiscal year start and end date correctly

This commit is contained in:
Faris Ansari 2019-12-20 12:15:50 +05:30
parent 6e2c5cdf96
commit 7fd5ce01d1

View File

@ -1,3 +1,4 @@
const { DateTime } = require('luxon');
const countryList = require('../../../fixtures/countryInfo.json');
module.exports = {
@ -64,13 +65,8 @@ module.exports = {
fieldtype: 'Date',
formula: doc => {
if (!doc.country) return;
let date = countryList[doc.country]['fiscal_year_start'].split('-');
var currentYear = new Date().getFullYear();
let currentMonth = date[0] - 1;
let currentDate = date[1];
return new Date(currentYear, currentMonth, currentDate)
.toISOString()
.substr(0, 10);
let fyStart = countryList[doc.country].fiscal_year_start;
return DateTime.fromFormat(fyStart, 'MM-dd').toISODate();
},
required: 1
},
@ -82,13 +78,10 @@ module.exports = {
fieldtype: 'Date',
formula: doc => {
if (!doc.country) return;
let date = countryList[doc.country]['fiscal_year_end'].split('-');
var currentYear = new Date().getFullYear() + 1;
let currentMonth = date[0] - 1;
let currentDate = date[1];
return new Date(currentYear, currentMonth, currentDate)
.toISOString()
.substr(0, 10);
let fyEnd = countryList[doc.country].fiscal_year_end;
return DateTime.fromFormat(fyEnd, 'MM-dd')
.plus({ year: 1 })
.toISODate();
},
required: 1
},