13
13
14
14
from .o_spreadsheet import load
15
15
from .revisions import CommandAdapter , Drop
16
- from odoo .upgrade . util . misc import version_gte
16
+ from odoo .addons . base . maintenance . migrations import util
17
17
18
18
_logger = logging .getLogger (__name__ )
19
19
@@ -41,34 +41,37 @@ def read_spreadsheet_snapshots(cr, like_pattern=""):
41
41
42
42
43
43
def read_spreadsheet_initial_data (cr , like_pattern = "" ):
44
- cr .execute (
45
- """
46
- SELECT doc.id AS document_id, a.id AS attachment_id, a.db_datas
47
- FROM documents_document doc
48
- LEFT JOIN ir_attachment a ON a.id = doc.attachment_id
49
- WHERE doc.handler='spreadsheet'
50
- AND position(%s::bytea in db_datas) > 0
51
- """ ,
52
- [like_pattern ],
53
- )
54
- # TODO there are excel files in there!
55
- for document_id , attachment_id , db_datas in cr .fetchall ():
56
- if db_datas :
57
- yield attachment_id , "documents.document" , document_id , json .loads (db_datas .tobytes ())
58
- data_field = _magic_spreadsheet_field (cr ) #"spreadsheet_binary_data" if version_gte("saas~16.3") else "data"
59
- cr .execute (
60
- """
61
- SELECT id, res_model, res_id, db_datas
62
- FROM ir_attachment
63
- WHERE res_model = 'spreadsheet.dashboard'
64
- AND res_field = %s
65
- AND position(%s::bytea in db_datas) > 0
66
- """ ,
67
- [data_field , like_pattern ],
68
- )
69
- for attachment_id , res_model , res_id , db_datas in cr .fetchall ():
70
- if db_datas :
71
- yield attachment_id , res_model , res_id , json .loads (db_datas .tobytes ())
44
+ if util .table_exists (cr , "documents_document" ):
45
+ cr .execute (
46
+ """
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
52
+ """ ,
53
+ [like_pattern ],
54
+ )
55
+ # TODO there are excel files in there!
56
+ for document_id , attachment_id , db_datas in cr .fetchall ():
57
+ if db_datas :
58
+ yield attachment_id , "documents.document" , document_id , json .loads (db_datas .tobytes ())
59
+
60
+ if util .table_exists (cr , "spreadsheet_dashboard" ):
61
+ data_field = _magic_spreadsheet_field (cr ) #"spreadsheet_binary_data" if version_gte("saas~16.3") else "data"
62
+ cr .execute (
63
+ """
64
+ SELECT id, res_model, res_id, db_datas
65
+ FROM ir_attachment
66
+ WHERE res_model = 'spreadsheet.dashboard'
67
+ AND res_field = %s
68
+ AND position(%s::bytea in db_datas) > 0
69
+ """ ,
70
+ [data_field , like_pattern ],
71
+ )
72
+ for attachment_id , res_model , res_id , db_datas in cr .fetchall ():
73
+ if db_datas :
74
+ yield attachment_id , res_model , res_id , json .loads (db_datas .tobytes ())
72
75
73
76
def _magic_spreadsheet_field (cr ):
74
77
cr .execute (
@@ -88,11 +91,11 @@ def apply_in_all_spreadsheets(cr, like_pattern, callback):
88
91
# upgrade the initial data and all revisions based on it
89
92
for attachment_id , res_model , res_id , db_datas in read_spreadsheet_initial_data (cr , like_pattern ):
90
93
print ("attachment : " , attachment_id )
91
-
94
+ print ( "datas: " , len ( db_datas ))
92
95
b = True
93
96
revisions_data = []
94
97
revisions_ids = []
95
- ## FIXME batch the calls
98
+ ## FIXME TODORAR batch the calls
96
99
for revision_id , commands in get_revisions (cr , res_model , res_id , like_pattern ):
97
100
revisions_data .append (json .loads (commands ))
98
101
revisions_ids .append (revision_id )
@@ -137,7 +140,7 @@ def write_attachment(cr, attachment_id, data):
137
140
138
141
139
142
def get_revisions (cr , res_model , res_id , like_pattern ):
140
- if version_gte ("16.0" ):
143
+ if util . version_gte ("16.0" ):
141
144
cr .execute (
142
145
"""
143
146
SELECT id, commands
@@ -163,7 +166,6 @@ def get_revisions(cr, res_model, res_id, like_pattern):
163
166
def upgrade_data (cr , upgrade_callback ):
164
167
for attachment_id , _res_model , _res_id , data in read_spreadsheet_attachments (cr ):
165
168
upgraded_data = upgrade_callback (load (data ))
166
- # import ipdb;ipdb.set_trace()
167
169
cr .execute (
168
170
"""
169
171
UPDATE ir_attachment
0 commit comments