[FIX] account: don't spam precision call for analytic widget
When a lot of components are trying to do the same `search_read`, they are spamming calls to the server when they could be batched instead. Instead of using `search_read`, we can also call `precision_get` which is `orm_cache`d To reproduce: * Main settings: activate/check "Analytic Accounting" * Menuitem: Accounting > Accounting > Journal Items You should see a lot of calls of `search_read` to `decimal.precision` closes odoo/odoo#103928 X-original-commit: 332a673b6b289761ae3c42d1bfa8effca475abf1 Signed-off-by: Quentin De Paoli <qdp@odoo.com> Signed-off-by: William André (wan) <wan@odoo.com>
This commit is contained in:
@@ -13,6 +13,10 @@ class AnalyticMixin(models.AbstractModel):
|
||||
compute="_compute_analytic_distribution", store=True, copy=True, readonly=False,
|
||||
precompute=True
|
||||
)
|
||||
analytic_precision = fields.Integer(
|
||||
store=False,
|
||||
default=lambda self: self.env['decimal.precision'].precision_get("Percentage Analytic"),
|
||||
)
|
||||
|
||||
def init(self):
|
||||
# Add a gin index for json search on the keys, on the models that actually have a table
|
||||
|
||||
+5
-8
@@ -79,12 +79,6 @@ export class AnalyticDistribution extends Component {
|
||||
if (this.editingRecord) {
|
||||
await this.fetchAllPlans(this.props);
|
||||
}
|
||||
const args = {
|
||||
domain: [["name", "like", "Percentage Analytic"]],
|
||||
fields: ["digits"],
|
||||
context: [],
|
||||
}
|
||||
this.decimal_precision = await this.orm.call("decimal.precision", "search_read", [], args);
|
||||
await this.formatData(this.props);
|
||||
}
|
||||
|
||||
@@ -565,8 +559,7 @@ export class AnalyticDistribution extends Component {
|
||||
}
|
||||
|
||||
formatPercentage(value) {
|
||||
return formatPercentage(value / 100, { digits: [false, this.decimal_precision[0].digits || 2] });
|
||||
|
||||
return formatPercentage(value / 100, { digits: [false, this.props.record.data.analytic_precision || 2] });
|
||||
}
|
||||
}
|
||||
AnalyticDistribution.template = "analytic.AnalyticDistribution";
|
||||
@@ -575,6 +568,10 @@ AnalyticDistribution.components = {
|
||||
AnalyticAutoComplete,
|
||||
TagsList,
|
||||
}
|
||||
|
||||
AnalyticDistribution.fieldDependencies = {
|
||||
analytic_precision: { type: 'integer' },
|
||||
}
|
||||
AnalyticDistribution.props = {
|
||||
...standardFieldProps,
|
||||
business_domain: { type: String, optional: true },
|
||||
|
||||
Reference in New Issue
Block a user