[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:
william
2022-10-24 16:12:39 +02:00
parent 2551efa736
commit 080768a546
2 changed files with 9 additions and 8 deletions
+4
View File
@@ -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
@@ -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 },