property_type_id = fields.Many2one("estate.property.type", string="Property Type")
property_ids = fields.One2many("estate.property", "property_type_id", string="Properties")
您在工具提示中显示的图像中看到的带有两个零的数字(就像浮点数一样)是属性的计数。
如何去除小数点?
我发现odoo使用chart.js 2.9.3,但我不知道如何修改JS来进行我想要的更改。
我尝试扩展此代码以某种方式删除小数,但我做不到
我已经看到了 Google 前 4 页上的所有链接,我观看了大量与 Odoo、饼图和 Chart.js 相关的 YouTube 视频,我在 WhatsApp 和 Telegram 群组中寻求帮助,但一无所获。
odoo.define('web.PieChart', function (require) {
"use strict";
/**
* This widget render a Pie Chart. It is used in the dashboard view.
*/
var core = require('web.core');
var Domain = require('web.Domain');
var viewRegistry = require('web.view_registry');
var Widget = require('web.Widget');
var widgetRegistry = require('web.widget_registry');
const { loadLegacyViews } = require("@web/legacy/legacy_views");
var qweb = core.qweb;
var PieChart = Widget.extend({
className: 'o_pie_chart',
xmlDependencies: ['/web/static/src/legacy/xml/chart.xml'],
/**
* @override
* @param {Widget} parent
* @param {Object} record
* @param {Object} node node from arch
*/
init: function (parent, record, node) {
this._super.apply(this, arguments);
var modifiers = node.attrs.modifiers;
var domain = record.domain.concat(
Domain.prototype.stringToArray(modifiers.domain || '[]'));
var arch = qweb.render('web.PieChart', {
modifiers: modifiers,
title: node.attrs.title || modifiers.title || modifiers.measure,
});
var pieChartContext = JSON.parse(JSON.stringify(record.context));
delete pieChartContext.graph_mode;
delete pieChartContext.graph_measure;
delete pieChartContext.graph_groupbys;
this.subViewParams = {
modelName: record.model,
withButtons: false,
withControlPanel: false,
withSearchPanel: false,
isEmbedded: true,
useSampleModel: record.isSample,
mode: 'pie',
};
this.subViewParams.searchQuery = {
context: pieChartContext,
domain: domain,
groupBy: [],
timeRanges: record.timeRanges || {},
};
this.viewInfo = {
arch: arch,
fields: record.fields,
viewFields: record.fieldsInfo.dashboard,
};
},
/**
* Instantiates the pie chart view and starts the graph controller.
*
* @override
*/
willStart: async function () {
var self = this;
const _super = this._super.bind(this, ...arguments);
await loadLegacyViews({ rpc: this._rpc.bind(this) });
var def1 = _super();
var SubView = viewRegistry.get('graph');
var subView = new SubView(this.viewInfo, this.subViewParams);
var def2 = subView.getController(this).then(function (controller) {
self.controller = controller;
return self.controller.appendTo(document.createDocumentFragment());
});
return Promise.all([def1, def2]);
},
/**
* @override
*/
start: function () {
this.$el.append(this.controller.$el);
return this._super.apply(this, arguments);
},
/**
* Call `on_attach_callback` for each subview
*
* @override
*/
on_attach_callback: function () {
this.controller.on_attach_callback();
},
});
widgetRegistry.add('pie_chart', PieChart);
return PieChart;
});
您可以覆盖旧图形渲染器
_formatValue
函数以使用新的图形渲染器 formatValue
函数,该函数将自动删除尾随零
示例:
/* @odoo-module */
import { GraphRenderer } from "@web/views/graph/graph_renderer";
import { patch } from "@web/core/utils/patch";
const GraphView = require('web.GraphView');
const viewRegistry = require("web.view_registry");
const LegacyGraphRenderer = viewRegistry.map.graph.prototype.config.Renderer;
patch(LegacyGraphRenderer.prototype, 'formatValue', {
_formatValue(value, allIntegers = true) {
return GraphRenderer.prototype.formatValue(value, allIntegers);
}
});