mirror of
https://github.com/frappe/books.git
synced 2024-12-23 03:19:01 +00:00
fix: init pesa with display too
This commit is contained in:
parent
23189aaf93
commit
e1f1ffd202
43
index.js
43
index.js
@ -1,7 +1,10 @@
|
||||
const Observable = require('./utils/observable');
|
||||
const utils = require('./utils');
|
||||
const { getMoneyMaker } = require('pesa');
|
||||
const { DEFAULT_INTERNAL_PRECISION } = require('./utils/consts');
|
||||
const {
|
||||
DEFAULT_INTERNAL_PRECISION,
|
||||
DEFAULT_DISPLAY_PRECISION,
|
||||
} = require('./utils/consts');
|
||||
|
||||
module.exports = {
|
||||
initializeAndRegister(customModels = {}, force = false) {
|
||||
@ -20,27 +23,25 @@ module.exports = {
|
||||
let values;
|
||||
try {
|
||||
// error thrown if migration hasn't taken place
|
||||
values = await frappe.db.getSingleValues({
|
||||
fieldname: 'internalPrecision',
|
||||
parent: 'SystemSettings',
|
||||
});
|
||||
values = await frappe.db.getSingleValues(
|
||||
{
|
||||
fieldname: 'internalPrecision',
|
||||
parent: 'SystemSettings',
|
||||
},
|
||||
{
|
||||
fieldname: 'displayPrecision',
|
||||
parent: 'SystemSettings',
|
||||
}
|
||||
);
|
||||
} catch {
|
||||
values = [];
|
||||
}
|
||||
|
||||
let { internalPrecision: precision } = values.reduce(
|
||||
(acc, { fieldname, value }) => {
|
||||
let { internalPrecision: precision, displayPrecision: display } =
|
||||
values.reduce((acc, { fieldname, value }) => {
|
||||
acc[fieldname] = value;
|
||||
return acc;
|
||||
},
|
||||
{}
|
||||
);
|
||||
|
||||
if (typeof precision === 'undefined') {
|
||||
precision = this.getMeta('SystemSettings').fields.find(
|
||||
(f) => f.fieldname === 'internalPrecision'
|
||||
)?.default;
|
||||
}
|
||||
}, {});
|
||||
|
||||
if (typeof precision === 'undefined') {
|
||||
precision = DEFAULT_INTERNAL_PRECISION;
|
||||
@ -50,7 +51,15 @@ module.exports = {
|
||||
precision = parseInt(precision);
|
||||
}
|
||||
|
||||
this.pesa = getMoneyMaker({ currency, precision });
|
||||
if (typeof display === 'undefined') {
|
||||
display = DEFAULT_DISPLAY_PRECISION;
|
||||
}
|
||||
|
||||
if (typeof display === 'string') {
|
||||
display = parseInt(display);
|
||||
}
|
||||
|
||||
this.pesa = getMoneyMaker({ currency, precision, display });
|
||||
},
|
||||
|
||||
init(force) {
|
||||
|
@ -1,5 +1,9 @@
|
||||
const { DateTime } = require('luxon');
|
||||
const { _ } = require('frappejs/utils');
|
||||
const {
|
||||
DEFAULT_DISPLAY_PRECISION,
|
||||
DEFAULT_INTERNAL_PRECISION,
|
||||
} = require('../../../utils/consts');
|
||||
|
||||
let dateFormatOptions = (() => {
|
||||
let formats = [
|
||||
@ -43,7 +47,7 @@ module.exports = {
|
||||
fieldname: 'displayPrecision',
|
||||
label: 'Display Precision',
|
||||
fieldtype: 'Int',
|
||||
default: 2,
|
||||
default: DEFAULT_DISPLAY_PRECISION,
|
||||
required: 1,
|
||||
minValue: 0,
|
||||
maxValue: 9,
|
||||
@ -61,7 +65,8 @@ module.exports = {
|
||||
fieldname: 'internalPrecision',
|
||||
label: 'Internal Precision',
|
||||
fieldtype: 'Int',
|
||||
default: 11,
|
||||
minValue: 0,
|
||||
default: DEFAULT_INTERNAL_PRECISION,
|
||||
description: _(
|
||||
'Sets the internal precision used for monetary calculations. Above 6 should be sufficient for most currencies.'
|
||||
),
|
||||
|
@ -1 +1,2 @@
|
||||
export const DEFAULT_INTERNAL_PRECISION = 11;
|
||||
export const DEFAULT_DISPLAY_PRECISION = 2;
|
||||
|
Loading…
Reference in New Issue
Block a user