@@ -101,9 +101,9 @@ export class AnalyticDistribution extends Component {
101
101
async willStart ( ) {
102
102
if ( this . editingRecord ) {
103
103
// for performance in list views, plans are not retrieved until they are required.
104
- await this . fetchAllPlans ( ) ;
104
+ await this . fetchAllPlans ( this . props ) ;
105
105
}
106
- await this . jsonToData ( ) ;
106
+ await this . jsonToData ( this . props . record . data [ this . props . name ] ) ;
107
107
}
108
108
109
109
async willUpdateRecord ( record ) {
@@ -120,11 +120,11 @@ export class AnalyticDistribution extends Component {
120
120
const productChanged = ! shallowEqual ( this . lastProduct , currentProduct ) ;
121
121
if ( valueChanged || accountChanged || productChanged ) {
122
122
if ( ! this . props . force_applicability ) {
123
- await this . fetchAllPlans ( ) ;
123
+ await this . fetchAllPlans ( { record } ) ;
124
124
}
125
125
this . lastAccount = accountChanged && currentAccount || this . lastAccount ;
126
126
this . lastProduct = productChanged && currentProduct || this . lastProduct ;
127
- await this . jsonToData ( ) ;
127
+ await this . jsonToData ( record . data [ this . props . name ] ) ;
128
128
}
129
129
this . currentValue = record . data [ this . props . name ] ;
130
130
}
@@ -217,8 +217,7 @@ export class AnalyticDistribution extends Component {
217
217
} ) ) ;
218
218
}
219
219
220
- async jsonToData ( ) {
221
- const jsonFieldValue = this . props . record . data [ this . props . name ] ;
220
+ async jsonToData ( jsonFieldValue ) {
222
221
const analyticAccountIds = jsonFieldValue ? Object . keys ( jsonFieldValue ) . map ( ( key ) => key . split ( ',' ) ) . flat ( ) . map ( ( id ) => parseInt ( id ) ) : [ ] ;
223
222
const analyticAccountDict = analyticAccountIds . length ? await this . fetchAnalyticAccounts ( [ [ "id" , "in" , analyticAccountIds ] ] ) : [ ] ;
224
223
@@ -323,8 +322,7 @@ export class AnalyticDistribution extends Component {
323
322
}
324
323
325
324
// ORM
326
- fetchPlansArgs ( ) {
327
- const { record, name } = this . props ;
325
+ fetchPlansArgs ( { record } ) {
328
326
let args = { } ;
329
327
if ( this . props . business_domain_compute ) {
330
328
args [ 'business_domain' ] = evaluateExpr ( this . props . business_domain_compute , record . evalContext ) ;
@@ -341,7 +339,7 @@ export class AnalyticDistribution extends Component {
341
339
if ( this . props . force_applicability ) {
342
340
args [ 'applicability' ] = this . props . force_applicability ;
343
341
}
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 ) ) ;
345
343
if ( existing_account_ids . length ) {
346
344
args [ 'existing_account_ids' ] = existing_account_ids ;
347
345
}
@@ -351,8 +349,8 @@ export class AnalyticDistribution extends Component {
351
349
return args ;
352
350
}
353
351
354
- async fetchAllPlans ( ) {
355
- const argsPlan = this . fetchPlansArgs ( ) ;
352
+ async fetchAllPlans ( props ) {
353
+ const argsPlan = this . fetchPlansArgs ( props ) ;
356
354
this . allPlans = await this . orm . call ( "account.analytic.plan" , "get_relevant_plans" , [ ] , argsPlan ) ;
357
355
}
358
356
@@ -480,8 +478,8 @@ export class AnalyticDistribution extends Component {
480
478
481
479
async openAnalyticEditor ( ) {
482
480
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 ] ) ;
485
483
}
486
484
if ( ! this . state . formattedData . length ) {
487
485
await this . addLine ( ) ;
0 commit comments