33import { Component , onWillStart , useState , useSubEnv } from "@odoo/owl" ;
44import { useBus , useService } from "@web/core/utils/hooks" ;
55import { DatePicker } from "@web/core/datepicker/datepicker" ;
6- import { Domain } from "@web/core/domain" ;
76import { FilterMenu } from "@web/search/filter_menu/filter_menu" ;
7+ import { MisReportSearchModel } from "@mis_builder/components/search_model.esm" ;
88import { SearchBar } from "@web/search/search_bar/search_bar" ;
9- import { SearchModel } from "@web/search/search_model" ;
109import { parseDate } from "@web/core/l10n/dates" ;
1110import { registry } from "@web/core/registry" ;
1211import { standardFieldProps } from "@web/views/fields/standard_field_props" ;
@@ -23,7 +22,7 @@ export class MisReportWidget extends Component {
2322 mis_report_data : { header : [ ] , body : [ ] } ,
2423 pivot_date : null ,
2524 } ) ;
26- this . searchModel = new SearchModel ( this . env , {
25+ this . searchModel = new MisReportSearchModel ( this . env , {
2726 user : this . user ,
2827 orm : this . orm ,
2928 view : this . view ,
@@ -63,6 +62,7 @@ export class MisReportWidget extends Component {
6362 await this . searchModel . load ( {
6463 resModel : this . source_aml_model_name ,
6564 searchViewId : this . widget_search_view_id ,
65+ analyticAccountId : this . analyticAccountId ,
6666 } ) ;
6767 }
6868
@@ -111,12 +111,10 @@ export class MisReportWidget extends Component {
111111
112112 get context ( ) {
113113 let ctx = this . props . record . context ;
114- this . setMisAnalyticDomainContextKey ( ctx ) ;
115114 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 ) ;
120118 }
121119 if ( this . showPivotDate && this . state . pivot_date ) {
122120 ctx = {
@@ -147,34 +145,47 @@ export class MisReportWidget extends Component {
147145 ) ;
148146 }
149147
150- setMisAnalyticDomainContextKey ( context ) {
148+ get analyticAccountId ( ) {
149+ let analyticAccountId = this . _getAnalyticAccountIdFromData ( ) ;
151150 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
154154 ) {
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 ] ;
177156 }
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+ ] ;
178189 }
179190
180191 async printPdf ( ) {
0 commit comments