@@ -45,10 +45,10 @@ def read_spreadsheet_initial_data(cr, like_pattern=""):
4545 cr .execute (
4646 """
4747 SELECT doc.id AS document_id, a.id AS attachment_id, a.db_datas
48- FROM documents_document doc
49- LEFT JOIN ir_attachment a ON a.id = doc.attachment_id
50- WHERE doc.handler='spreadsheet'
51- AND position(%s::bytea in db_datas) > 0
48+ FROM documents_document doc
49+ LEFT JOIN ir_attachment a ON a.id = doc.attachment_id
50+ WHERE doc.handler='spreadsheet'
51+ AND position(%s::bytea in db_datas) > 0
5252 """ ,
5353 [like_pattern ],
5454 )
@@ -85,30 +85,41 @@ def _magic_spreadsheet_field(cr):
8585 return cr .fetchone ()[0 ] and 'spreadsheet_binary_data' or 'data'
8686
8787def apply_in_all_spreadsheets (cr , like_pattern , callback ):
88- # _logger.info("upgrading initial data and revisions")
8988 print ("like pattern : " , like_pattern )
9089 b = False
9190 # upgrade the initial data and all revisions based on it
9291 for attachment_id , res_model , res_id , db_datas in read_spreadsheet_initial_data (cr , like_pattern ):
9392 print ("attachment : " , attachment_id )
9493 print ("datas: " , len (db_datas ))
9594 b = True
96- revisions_data = []
97- revisions_ids = []
98- ## FIXME TODORAR batch the calls
99- for revision_id , commands in get_revisions (cr , res_model , res_id , like_pattern ):
100- revisions_data .append (json .loads (commands ))
101- revisions_ids .append (revision_id )
102- data , revisions = callback (db_datas , revisions_data )
95+
96+ data , _ = callback (db_datas , [])
10397 write_attachment (cr , attachment_id , data )
104- for revision_id , revision in zip (revisions_ids , revisions ):
98+
99+ ## FIXME TODORAR batch the calls
100+ ## FIXME we have to pass in the revisions regardless of the base data stuff
101+ # upgrade revisions
102+ # regardless of res_model res_id
103+ revisions_data = []
104+ revisions_ids = []
105+
106+ # if like_pattern == "tax_audit":
107+ # import ipdb;ipdb.set_trace()
108+ for revision_id , commands in get_revisions (cr , "res_model" , "res_id" , like_pattern ):
109+ revisions_data .append (json .loads (commands ))
110+ revisions_ids .append (revision_id )
111+ data , revisions = callback ({}, revisions_data )
112+ # write_attachment(cr, attachment_id, data)
113+ print ("wooooooooooooooooot\n " * 20 )
114+ print (revisions )
115+ for rev_id , revision in zip (revisions_ids , revisions ):
105116 cr .execute (
106117 """
107118 UPDATE spreadsheet_revision
108119 SET commands=%s
109120 WHERE id=%s
110121 """ ,
111- [json .dumps (revision ), revision_id ],
122+ [json .dumps (revision ), rev_id ],
112123 )
113124 if b :
114125 _logger .info ("upgrading initial data and revisions" )
@@ -132,8 +143,8 @@ def write_attachment(cr, attachment_id, data):
132143 cr .execute (
133144 """
134145 UPDATE ir_attachment
135- SET db_datas=%s
136- WHERE id=%s
146+ SET db_datas=%s
147+ WHERE id=%s
137148 """ ,
138149 [json .dumps (data ).encode (), attachment_id ]
139150 )
@@ -144,22 +155,19 @@ def get_revisions(cr, res_model, res_id, like_pattern):
144155 cr .execute (
145156 """
146157 SELECT id, commands
147- FROM spreadsheet_revision
148- WHERE commands LIKE %s
149- AND res_model=%s
150- AND res_id=%s
158+ FROM spreadsheet_revision
159+ WHERE commands LIKE %s
151160 """ ,
152- [like_pattern , res_model , res_id ],
161+ ['%' + like_pattern + '%' ],
153162 )
154163 else :
155164 cr .execute (
156165 """
157166 SELECT id, commands
158- FROM spreadsheet_revision
159- WHERE commands LIKE %s
160- AND document_id=%s
167+ FROM spreadsheet_revision
168+ WHERE commands LIKE %s
161169 """ ,
162- [like_pattern , res_id ],
170+ [like_pattern ],
163171 )
164172 return cr .fetchall ()
165173
@@ -330,20 +338,24 @@ def remove_odoo_charts(spreadsheet: Spreadsheet, chart_ids: List[str], insert_cm
330338 spreadsheet .delete_figures (* chart_ids )
331339
332340 def adapt_create_chart (cmd ):
341+ # import ipdb;ipdb.set_trace()
342+
333343 chart = create_data_source_from_cmd (cmd )
334344 if cmd ["definition" ]["type" ].startswith ("odoo_" ) and insert_cmd_predicate (chart ):
335345 chart_ids .append (cmd ["id" ])
336346 return Drop
337347
338348 def adapt_chart_cmd_with_id (cmd ):
349+ # import ipdb;ipdb.set_trace()
350+
339351 if cmd ["id" ] in chart_ids :
340352 return Drop
341353
342354 def adapt_global_filters (cmd ):
343355 if cmd .get ("chart" ):
344356 for chart_id in chart_ids :
345357 cmd ["chart" ].pop (chart_id , None )
346-
358+ # import ipdb;ipdb.set_trace()
347359 return (
348360 CommandAdapter ("CREATE_CHART" , adapt_create_chart ),
349361 CommandAdapter ("UPDATE_CHART" , adapt_chart_cmd_with_id ),
0 commit comments