feat: refs #8361 add hasToDownloadRate field to currency model and update exchange rate logic
gitea/salix/pipeline/pr-dev This commit looks good
Details
gitea/salix/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
parent
dbd8d816c0
commit
44765b5a64
|
@ -158,13 +158,13 @@ INSERT INTO `account`.`mailForward`(`account`, `forwardTo`)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
INSERT INTO `vn`.`currency`(`id`, `code`, `name`, `ratio`)
|
INSERT INTO `vn`.`currency`(`id`, `code`, `name`, `ratio`, `hasToDownloadRate`)
|
||||||
VALUES
|
VALUES
|
||||||
(1, 'EUR', 'Euro', 1),
|
(1, 'EUR', 'Euro', 1, FALSE),
|
||||||
(2, 'USD', 'Dollar USA', 1.4),
|
(2, 'USD', 'Dollar USA', 1.4, TRUE),
|
||||||
(3, 'GBP', 'Libra', 1),
|
(3, 'GBP', 'Libra', 1, TRUE),
|
||||||
(4, 'JPY', 'Yen Japones', 1),
|
(4, 'JPY', 'Yen Japones', 1, FALSE),
|
||||||
(5, 'CNY', 'Yuan Chino', 1.2);
|
(5, 'CNY', 'Yuan Chino', 1.2, TRUE);
|
||||||
|
|
||||||
INSERT INTO `vn`.`country`(`id`, `name`, `isUeeMember`, `code`, `currencyFk`, `ibanLength`, `continentFk`, `hasDailyInvoice`, `CEE`)
|
INSERT INTO `vn`.`country`(`id`, `name`, `isUeeMember`, `code`, `currencyFk`, `ibanLength`, `continentFk`, `hasDailyInvoice`, `CEE`)
|
||||||
VALUES
|
VALUES
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE `vn`.`currency`
|
||||||
|
ADD COLUMN `hasToDownloadRate` TINYINT(1) NOT NULL DEFAULT 0 comment 'Si se guarda el tipo de cambio diariamente en referenceRate';
|
|
@ -0,0 +1,3 @@
|
||||||
|
UPDATE `vn`.`currency`
|
||||||
|
SET `hasToDownloadRate` = TRUE
|
||||||
|
WHERE `code` IN ('USD', 'CNY', 'GBP');
|
|
@ -36,6 +36,7 @@ module.exports = Self => {
|
||||||
if (!cubes || cubes.length === 0)
|
if (!cubes || cubes.length === 0)
|
||||||
throw new UserError('No cubes found. Exiting the method.');
|
throw new UserError('No cubes found. Exiting the method.');
|
||||||
|
|
||||||
|
const currencies = await models.Currency.find({where: {hasToDownloadRate: true}}, myOptions);
|
||||||
const maxDateRecord = await models.ReferenceRate.findOne({order: 'dated DESC'}, myOptions);
|
const maxDateRecord = await models.ReferenceRate.findOne({order: 'dated DESC'}, myOptions);
|
||||||
const maxDate = maxDateRecord?.dated ? new Date(maxDateRecord.dated) : null;
|
const maxDate = maxDateRecord?.dated ? new Date(maxDateRecord.dated) : null;
|
||||||
let lastProcessedDate = maxDate;
|
let lastProcessedDate = maxDate;
|
||||||
|
@ -51,32 +52,20 @@ module.exports = Self => {
|
||||||
|
|
||||||
if (!maxDate || xmlDateWithoutTime > maxDate) {
|
if (!maxDate || xmlDateWithoutTime > maxDate) {
|
||||||
if (lastProcessedDate && xmlDateWithoutTime > lastProcessedDate) {
|
if (lastProcessedDate && xmlDateWithoutTime > lastProcessedDate) {
|
||||||
for (const code of ['USD', 'CNY', 'GBP']) {
|
for (const currency of currencies) {
|
||||||
const currency = await models.Currency.findOne(
|
|
||||||
{where: {code}},
|
|
||||||
myOptions
|
|
||||||
);
|
|
||||||
if (!currency)
|
|
||||||
throw new UserError(`Currency not found for code: ${code}`);
|
|
||||||
|
|
||||||
await fillMissingDates(
|
await fillMissingDates(
|
||||||
models, currency, lastProcessedDate, xmlDateWithoutTime, myOptions
|
models, currency, lastProcessedDate, xmlDateWithoutTime, myOptions
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const rateCube of Array.from(cube.childNodes)) {
|
for (const rateCube of Array.from(cube.childNodes)) {
|
||||||
if (rateCube.nodeType === doc.ELEMENT_NODE) {
|
if (rateCube.nodeType === doc.ELEMENT_NODE) {
|
||||||
const currencyCode = rateCube.getAttribute('currency');
|
const currencyCode = rateCube.getAttribute('currency');
|
||||||
const rate = rateCube.getAttribute('rate');
|
const rate = rateCube.getAttribute('rate');
|
||||||
if (['USD', 'CNY', 'GBP'].includes(currencyCode)) {
|
const currency = currencies.find(c => c.code === currencyCode);
|
||||||
const currency = await models.Currency.findOne(
|
if (currency) {
|
||||||
{where: {code: currencyCode}},
|
|
||||||
myOptions
|
|
||||||
);
|
|
||||||
if (!currency)
|
|
||||||
throw new UserError(`Currency not found for code: ${currencyCode}`);
|
|
||||||
|
|
||||||
const existingRate = await models.ReferenceRate.findOne({
|
const existingRate = await models.ReferenceRate.findOne({
|
||||||
where: {currencyFk: currency.id, dated: xmlDateWithoutTime}
|
where: {currencyFk: currency.id, dated: xmlDateWithoutTime}
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
|
@ -20,6 +20,9 @@
|
||||||
},
|
},
|
||||||
"ratio": {
|
"ratio": {
|
||||||
"type": "number"
|
"type": "number"
|
||||||
|
},
|
||||||
|
"hasToDownloadRate": {
|
||||||
|
"type": "boolean"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"acls": [
|
"acls": [
|
||||||
|
|
Loading…
Reference in New Issue