Skip to content

Commit 4e9f542

Browse files
committed
[FIX] analytic: display correct analytic when using arrows
Steps to reproduce: - activate analytic - Create two assets with different analytic distribution - Open the first asset - Navigate to the second asset via the arrow Issue: The analytic account will not be displayed correctly Cause: In `jsonToData` the record used is the previous one. Solution: Use the record that will efectively be displayed opw-3698383 closes odoo#153681 Signed-off-by: Habib Ayob (ayh) <ayh@odoo.com>
1 parent a9ebd07 commit 4e9f542

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

addons/analytic/static/src/components/analytic_distribution/analytic_distribution.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ export class AnalyticDistribution extends Component {
101101
async willStart() {
102102
if (this.editingRecord) {
103103
// for performance in list views, plans are not retrieved until they are required.
104-
await this.fetchAllPlans();
104+
await this.fetchAllPlans(this.props);
105105
}
106-
await this.jsonToData();
106+
await this.jsonToData(this.props.record.data[this.props.name]);
107107
}
108108

109109
async willUpdateRecord(record) {
@@ -120,11 +120,11 @@ export class AnalyticDistribution extends Component {
120120
const productChanged = !shallowEqual(this.lastProduct, currentProduct);
121121
if (valueChanged || accountChanged || productChanged) {
122122
if (!this.props.force_applicability) {
123-
await this.fetchAllPlans();
123+
await this.fetchAllPlans({ record });
124124
}
125125
this.lastAccount = accountChanged && currentAccount || this.lastAccount;
126126
this.lastProduct = productChanged && currentProduct || this.lastProduct;
127-
await this.jsonToData();
127+
await this.jsonToData(record.data[this.props.name]);
128128
}
129129
this.currentValue = record.data[this.props.name];
130130
}
@@ -217,8 +217,7 @@ export class AnalyticDistribution extends Component {
217217
}));
218218
}
219219

220-
async jsonToData() {
221-
const jsonFieldValue = this.props.record.data[this.props.name];
220+
async jsonToData(jsonFieldValue) {
222221
const analyticAccountIds = jsonFieldValue ? Object.keys(jsonFieldValue).map((key) => key.split(',')).flat().map((id) => parseInt(id)) : [];
223222
const analyticAccountDict = analyticAccountIds.length ? await this.fetchAnalyticAccounts([["id", "in", analyticAccountIds]]) : [];
224223

@@ -323,8 +322,7 @@ export class AnalyticDistribution extends Component {
323322
}
324323

325324
// ORM
326-
fetchPlansArgs() {
327-
const { record, name } = this.props;
325+
fetchPlansArgs({ record }) {
328326
let args = {};
329327
if (this.props.business_domain_compute) {
330328
args['business_domain'] = evaluateExpr(this.props.business_domain_compute, record.evalContext);
@@ -341,7 +339,7 @@ export class AnalyticDistribution extends Component {
341339
if (this.props.force_applicability) {
342340
args['applicability'] = this.props.force_applicability;
343341
}
344-
const existing_account_ids = Object.keys(record.data[name]).map((k) => k.split(",")).flat().map((i) => parseInt(i));
342+
const existing_account_ids = Object.keys(record.data[this.props.name]).map((k) => k.split(",")).flat().map((i) => parseInt(i));
345343
if (existing_account_ids.length) {
346344
args['existing_account_ids'] = existing_account_ids;
347345
}
@@ -351,8 +349,8 @@ export class AnalyticDistribution extends Component {
351349
return args;
352350
}
353351

354-
async fetchAllPlans() {
355-
const argsPlan = this.fetchPlansArgs();
352+
async fetchAllPlans(props) {
353+
const argsPlan = this.fetchPlansArgs(props);
356354
this.allPlans = await this.orm.call("account.analytic.plan", "get_relevant_plans", [], argsPlan);
357355
}
358356

@@ -480,8 +478,8 @@ export class AnalyticDistribution extends Component {
480478

481479
async openAnalyticEditor() {
482480
if (!this.allPlans.length) {
483-
await this.fetchAllPlans();
484-
await this.jsonToData();
481+
await this.fetchAllPlans(this.props);
482+
await this.jsonToData(this.props.record.data[this.props.name]);
485483
}
486484
if (!this.state.formattedData.length) {
487485
await this.addLine();

0 commit comments

Comments
 (0)