@@ -45,10 +45,10 @@ def read_spreadsheet_initial_data(cr, like_pattern=""):
45
45
cr .execute (
46
46
"""
47
47
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
52
52
""" ,
53
53
[like_pattern ],
54
54
)
@@ -85,30 +85,41 @@ def _magic_spreadsheet_field(cr):
85
85
return cr .fetchone ()[0 ] and 'spreadsheet_binary_data' or 'data'
86
86
87
87
def apply_in_all_spreadsheets (cr , like_pattern , callback ):
88
- # _logger.info("upgrading initial data and revisions")
89
88
print ("like pattern : " , like_pattern )
90
89
b = False
91
90
# upgrade the initial data and all revisions based on it
92
91
for attachment_id , res_model , res_id , db_datas in read_spreadsheet_initial_data (cr , like_pattern ):
93
92
print ("attachment : " , attachment_id )
94
93
print ("datas: " , len (db_datas ))
95
94
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 , [])
103
97
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 ):
105
116
cr .execute (
106
117
"""
107
118
UPDATE spreadsheet_revision
108
119
SET commands=%s
109
120
WHERE id=%s
110
121
""" ,
111
- [json .dumps (revision ), revision_id ],
122
+ [json .dumps (revision ), rev_id ],
112
123
)
113
124
if b :
114
125
_logger .info ("upgrading initial data and revisions" )
@@ -132,8 +143,8 @@ def write_attachment(cr, attachment_id, data):
132
143
cr .execute (
133
144
"""
134
145
UPDATE ir_attachment
135
- SET db_datas=%s
136
- WHERE id=%s
146
+ SET db_datas=%s
147
+ WHERE id=%s
137
148
""" ,
138
149
[json .dumps (data ).encode (), attachment_id ]
139
150
)
@@ -144,22 +155,19 @@ def get_revisions(cr, res_model, res_id, like_pattern):
144
155
cr .execute (
145
156
"""
146
157
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
151
160
""" ,
152
- [like_pattern , res_model , res_id ],
161
+ ['%' + like_pattern + '%' ],
153
162
)
154
163
else :
155
164
cr .execute (
156
165
"""
157
166
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
161
169
""" ,
162
- [like_pattern , res_id ],
170
+ [like_pattern ],
163
171
)
164
172
return cr .fetchall ()
165
173
@@ -330,20 +338,24 @@ def remove_odoo_charts(spreadsheet: Spreadsheet, chart_ids: List[str], insert_cm
330
338
spreadsheet .delete_figures (* chart_ids )
331
339
332
340
def adapt_create_chart (cmd ):
341
+ # import ipdb;ipdb.set_trace()
342
+
333
343
chart = create_data_source_from_cmd (cmd )
334
344
if cmd ["definition" ]["type" ].startswith ("odoo_" ) and insert_cmd_predicate (chart ):
335
345
chart_ids .append (cmd ["id" ])
336
346
return Drop
337
347
338
348
def adapt_chart_cmd_with_id (cmd ):
349
+ # import ipdb;ipdb.set_trace()
350
+
339
351
if cmd ["id" ] in chart_ids :
340
352
return Drop
341
353
342
354
def adapt_global_filters (cmd ):
343
355
if cmd .get ("chart" ):
344
356
for chart_id in chart_ids :
345
357
cmd ["chart" ].pop (chart_id , None )
346
-
358
+ # import ipdb;ipdb.set_trace()
347
359
return (
348
360
CommandAdapter ("CREATE_CHART" , adapt_create_chart ),
349
361
CommandAdapter ("UPDATE_CHART" , adapt_chart_cmd_with_id ),
0 commit comments