3
3
import { Component , onWillStart , useState , useSubEnv } from "@odoo/owl" ;
4
4
import { useBus , useService } from "@web/core/utils/hooks" ;
5
5
import { DatePicker } from "@web/core/datepicker/datepicker" ;
6
- import { Domain } from "@web/core/domain" ;
7
6
import { FilterMenu } from "@web/search/filter_menu/filter_menu" ;
7
+ import { MisReportSearchModel } from "@mis_builder/components/search_model.esm" ;
8
8
import { SearchBar } from "@web/search/search_bar/search_bar" ;
9
- import { SearchModel } from "@web/search/search_model" ;
10
9
import { parseDate } from "@web/core/l10n/dates" ;
11
10
import { registry } from "@web/core/registry" ;
12
11
import { standardFieldProps } from "@web/views/fields/standard_field_props" ;
@@ -23,7 +22,7 @@ export class MisReportWidget extends Component {
23
22
mis_report_data : { header : [ ] , body : [ ] } ,
24
23
pivot_date : null ,
25
24
} ) ;
26
- this . searchModel = new SearchModel ( this . env , {
25
+ this . searchModel = new MisReportSearchModel ( this . env , {
27
26
user : this . user ,
28
27
orm : this . orm ,
29
28
view : this . view ,
@@ -63,6 +62,7 @@ export class MisReportWidget extends Component {
63
62
await this . searchModel . load ( {
64
63
resModel : this . source_aml_model_name ,
65
64
searchViewId : this . widget_search_view_id ,
65
+ analyticAccountId : this . analyticAccountId ,
66
66
} ) ;
67
67
}
68
68
@@ -111,12 +111,10 @@ export class MisReportWidget extends Component {
111
111
112
112
get context ( ) {
113
113
let ctx = this . props . record . context ;
114
- this . setMisAnalyticDomainContextKey ( ctx ) ;
115
114
if ( this . showSearchBar && this . searchModel . searchDomain ) {
116
- ctx [ this . misAnalyticDomainContextKey ] = Domain . and ( [
117
- ctx [ this . misAnalyticDomainContextKey ] ,
118
- new Domain ( this . searchModel . searchDomain ) ,
119
- ] ) . toList ( ) ;
115
+ ctx [ this . misAnalyticDomainContextKey ] = this . searchModel . searchDomain ;
116
+ } else {
117
+ this . _setMisAnalyticDomainContextKey ( ctx ) ;
120
118
}
121
119
if ( this . showPivotDate && this . state . pivot_date ) {
122
120
ctx = {
@@ -147,34 +145,47 @@ export class MisReportWidget extends Component {
147
145
) ;
148
146
}
149
147
150
- setMisAnalyticDomainContextKey ( context ) {
148
+ get analyticAccountId ( ) {
149
+ let analyticAccountId = this . _getAnalyticAccountIdFromData ( ) ;
151
150
if (
152
- this . props . analytic_account_id_field &&
153
- ! ( this . misAnalyticDomainContextKey in context )
151
+ ! analyticAccountId &&
152
+ this . props . record . context &&
153
+ this . props . record . context . mis_analytic_domain
154
154
) {
155
- let analyticAccountId = false ;
156
- const analyticAccountIdFieldType =
157
- this . props . record . fields [ this . props . analytic_account_id_field ] . type ;
158
- switch ( analyticAccountIdFieldType ) {
159
- case "many2one" :
160
- analyticAccountId =
161
- this . props . record . data [ this . props . analytic_account_id_field ] [ 0 ] ;
162
- break ;
163
- case "integer" :
164
- analyticAccountId =
165
- this . props . record . data [ this . props . analytic_account_id_field ] ;
166
- break ;
167
- default :
168
- throw new Error (
169
- `` `Unsupported field type for analytic_account_id: ${ analyticAccountIdFieldType } ` ``
170
- ) ;
171
- }
172
- if ( analyticAccountId ) {
173
- context [ this . misAnalyticDomainContextKey ] = [
174
- [ "analytic_account_id" , "=" , analyticAccountId ] ,
175
- ] ;
176
- }
155
+ analyticAccountId = this . props . record . context . mis_analytic_domain [ 0 ] [ 2 ] ;
177
156
}
157
+ return analyticAccountId ;
158
+ }
159
+
160
+ _getAnalyticAccountIdFromData ( ) {
161
+ if (
162
+ ! this . props . analyticAccountIdField ||
163
+ ! ( this . props . analyticAccountIdField in this . props . record . fields )
164
+ ) {
165
+ return false ;
166
+ }
167
+ const analyticAccountIdFieldType =
168
+ this . props . record . fields [ this . props . analyticAccountIdField ] . type ;
169
+ switch ( analyticAccountIdFieldType ) {
170
+ case "many2one" :
171
+ return this . props . record . data [ this . props . analyticAccountIdField ] [ 0 ] ;
172
+ case "integer" :
173
+ return this . props . record . data [ this . props . analyticAccountIdField ] ;
174
+ default :
175
+ throw new Error (
176
+ `` `Unsupported field type for analytic_account_id: ${ analyticAccountIdFieldType } ` ``
177
+ ) ;
178
+ }
179
+ }
180
+
181
+ _setMisAnalyticDomainContextKey ( context ) {
182
+ const analyticAccountId = this . _getAnalyticAccountIdFromData ( ) ;
183
+ if ( ! analyticAccountId ) {
184
+ return ;
185
+ }
186
+ context [ this . misAnalyticDomainContextKey ] = [
187
+ [ "analytic_account_id" , "=" , analyticAccountId ] ,
188
+ ] ;
178
189
}
179
190
180
191
async printPdf ( ) {
0 commit comments