2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 07:40:55 +00:00

fix: don't set precision on df, should be global

This commit is contained in:
18alantom 2021-12-23 16:56:47 +05:30
parent 8bf257c685
commit 23189aaf93
4 changed files with 6 additions and 12 deletions

View File

@ -1,6 +1,7 @@
const Observable = require('./utils/observable');
const utils = require('./utils');
const { getMoneyMaker } = require('pesa');
const { DEFAULT_INTERNAL_PRECISION } = require('./utils/consts');
module.exports = {
initializeAndRegister(customModels = {}, force = false) {
@ -42,7 +43,7 @@ module.exports = {
}
if (typeof precision === 'undefined') {
precision = 11;
precision = DEFAULT_INTERNAL_PRECISION;
}
if (typeof precision.value === 'string') {

View File

@ -2,6 +2,7 @@ const frappe = require('frappejs');
const Observable = require('frappejs/utils/observable');
const naming = require('./naming');
const { round } = require('frappejs/utils/numberFormat');
const { DEFAULT_INTERNAL_PRECISION } = require('../utils/consts');
module.exports = class BaseDocument extends Observable {
constructor(data) {
@ -673,10 +674,8 @@ module.exports = class BaseDocument extends Observable {
if (typeof df === 'string') {
df = this.meta.getField(df);
}
let systemPrecision = frappe.SystemSettings.internalPrecision;
let defaultPrecision = systemPrecision != null ? systemPrecision : 2;
let precision =
df && df.precision != null ? df.precision : defaultPrecision;
const precision =
frappe.SystemSettings.internalPrecision ?? DEFAULT_INTERNAL_PRECISION;
return round(value, precision);
}

View File

@ -48,13 +48,6 @@ module.exports = class BaseMeta extends BaseDocument {
df.required = 1;
}
// attach default precision to Float and Currency
if (['Float', 'Currency'].includes(df.fieldtype)) {
let defaultPrecision = frappe.SystemSettings
? frappe.SystemSettings.internalPrecision
: 2;
df.precision = df.precision || defaultPrecision;
}
return df;
});
}

1
utils/consts.js Normal file
View File

@ -0,0 +1 @@
export const DEFAULT_INTERNAL_PRECISION = 11;