@@ -8,11 +8,59 @@ import {useService} from "@web/core/utils/hooks";
88class CustomExportDataDialog extends ExportDataDialog {
99 setup ( ) {
1010 super . setup ( ) ;
11- this . props . root . resModel = this . props . resModel ;
12- console . log ( this . props . root ) ;
13- console . log ( this . props . root . resModel , this . props . resModel ) ;
11+ this . title = this . env . _t ( "Select Data for Indexing" ) ;
12+ this . props . root . resModel = this . props . context . resModel ;
13+ if ( this . props . context . exporter_id ) {
14+ this . state . templateId = this . props . context . exporter_id [ 0 ] ;
15+ }
16+ }
17+ async onUpdateExportTemplate ( ) {
18+ const oldRec = await this . orm . read (
19+ "ir.exports" ,
20+ [ this . state . templateId ] ,
21+ [ "name" , "export_fields" ]
22+ ) ;
23+ let oldLines = [ ] ;
24+ if (
25+ oldRec . length &&
26+ oldRec [ 0 ] . export_fields &&
27+ oldRec [ 0 ] . export_fields . length
28+ ) {
29+ oldLines = await this . orm . read ( "ir.exports.line" , oldRec [ 0 ] . export_fields , [
30+ "name" ,
31+ ] ) ;
32+ }
33+ // Get list of field names from exportList and existing lines
34+ const newFieldNames = this . state . exportList . map ( ( field ) => field . id ) ;
35+ const oldFieldMap = Object . fromEntries (
36+ oldLines . map ( ( line ) => [ line . name , line . id ] )
37+ ) ;
38+ // Prepare commands
39+ const fieldCommands = [ ] ;
40+ // Keep or create
41+ for ( const field of this . state . exportList ) {
42+ if ( oldFieldMap [ field . id ] ) {
43+ // Link existing line
44+ fieldCommands . push ( [ 4 , oldFieldMap [ field . id ] ] ) ;
45+ } else {
46+ // New line to create
47+ fieldCommands . push ( [ 0 , 0 , { name : field . id } ] ) ;
48+ }
49+ }
50+ // Unlink deleted fields
51+ for ( const oldLine of oldLines ) {
52+ if ( ! newFieldNames . includes ( oldLine . name ) ) {
53+ fieldCommands . push ( [ 3 , oldLine . id ] ) ; // Unlink and delete
54+ }
55+ }
56+ // Write back to ir.exports
57+ await this . orm . write ( "ir.exports" , [ this . state . templateId ] , {
58+ export_fields : fieldCommands ,
59+ } ) ;
60+ this . state . isEditingTemplate = false ;
1461 }
1562}
63+ CustomExportDataDialog . template = "typesense_ir_exports.CustomExportDataDialog" ;
1664
1765class IrExportWidget extends Many2OneField {
1866 setup ( ) {
@@ -34,12 +82,15 @@ class IrExportWidget extends Many2OneField {
3482 }
3583 async onExportData ( ) {
3684 const dialogProps = {
37- context : this . props . record . context ,
85+ context : {
86+ ...this . props . record . context ,
87+ resModel : this . props . record . data . model_name ,
88+ exporter_id : this . props . record . data . exporter_id ,
89+ } ,
3890 defaultExportList : [ ] ,
3991 download : this . downloadExport . bind ( this ) ,
4092 getExportedFields : this . getExportedFields . bind ( this ) ,
4193 root : this . props . record . model . root ,
42- resModel : this . props . record . data . model_name ,
4394 } ;
4495 this . dialogService . add ( CustomExportDataDialog , dialogProps ) ;
4596 }
0 commit comments