mirror of
https://github.com/frappe/books.git
synced 2024-12-23 11:29:03 +00:00
patch: convert existing currency values to precision adjusted int str
This commit is contained in:
parent
4650b1eeda
commit
44a60a84dd
41
patches/0.0.4/convertCurrencyToStrings.js
Normal file
41
patches/0.0.4/convertCurrencyToStrings.js
Normal file
@ -0,0 +1,41 @@
|
||||
import frappe from 'frappejs';
|
||||
|
||||
function getTablesToConvert() {
|
||||
// Do not change loops to map, doesn't work for some reason.
|
||||
const toConvert = [];
|
||||
for (let key in frappe.models) {
|
||||
const model = frappe.models[key];
|
||||
|
||||
const fieldsToConvert = [];
|
||||
for (let i in model.fields) {
|
||||
const field = model.fields[i];
|
||||
|
||||
if (field.fieldtype === 'Currency') {
|
||||
fieldsToConvert.push(field.fieldname);
|
||||
}
|
||||
}
|
||||
|
||||
if (fieldsToConvert.length > 0 && !model.isSingle && !model.basedOn) {
|
||||
toConvert.push({ name: key, fields: fieldsToConvert });
|
||||
}
|
||||
}
|
||||
|
||||
return toConvert;
|
||||
}
|
||||
|
||||
export default async function execute() {
|
||||
const toConvert = getTablesToConvert();
|
||||
for (let { name, fields } of toConvert) {
|
||||
const rows = await frappe.db.knex(name);
|
||||
const convertedRows = rows.map((row) => {
|
||||
for (let field of fields) {
|
||||
if (row[field] === null) {
|
||||
continue;
|
||||
}
|
||||
row[field] = frappe.pesa(row[field]).store;
|
||||
}
|
||||
return row;
|
||||
});
|
||||
await frappe.db.prestigeTheTable(name, convertedRows);
|
||||
}
|
||||
}
|
@ -3,5 +3,10 @@
|
||||
"version": "0.0.3",
|
||||
"fileName": "makePaymentRefIdNullable",
|
||||
"beforeMigrate": true
|
||||
},
|
||||
{
|
||||
"version": "0.0.4",
|
||||
"fileName": "convertCurrencyToStrings",
|
||||
"beforeMigrate": true
|
||||
}
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user