1313
1414from .o_spreadsheet import load
1515from .revisions import CommandAdapter , Drop
16- from odoo .upgrade . util . misc import version_gte
16+ from odoo .addons . base . maintenance . migrations import util
1717
1818_logger = logging .getLogger (__name__ )
1919
@@ -41,34 +41,37 @@ def read_spreadsheet_snapshots(cr, like_pattern=""):
4141
4242
4343def 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 ())
7275
7376def _magic_spreadsheet_field (cr ):
7477 cr .execute (
@@ -88,11 +91,11 @@ def apply_in_all_spreadsheets(cr, like_pattern, callback):
8891 # upgrade the initial data and all revisions based on it
8992 for attachment_id , res_model , res_id , db_datas in read_spreadsheet_initial_data (cr , like_pattern ):
9093 print ("attachment : " , attachment_id )
91-
94+ print ( "datas: " , len ( db_datas ))
9295 b = True
9396 revisions_data = []
9497 revisions_ids = []
95- ## FIXME batch the calls
98+ ## FIXME TODORAR batch the calls
9699 for revision_id , commands in get_revisions (cr , res_model , res_id , like_pattern ):
97100 revisions_data .append (json .loads (commands ))
98101 revisions_ids .append (revision_id )
@@ -137,7 +140,7 @@ def write_attachment(cr, attachment_id, data):
137140
138141
139142def get_revisions (cr , res_model , res_id , like_pattern ):
140- if version_gte ("16.0" ):
143+ if util . version_gte ("16.0" ):
141144 cr .execute (
142145 """
143146 SELECT id, commands
@@ -163,7 +166,6 @@ def get_revisions(cr, res_model, res_id, like_pattern):
163166def upgrade_data (cr , upgrade_callback ):
164167 for attachment_id , _res_model , _res_id , data in read_spreadsheet_attachments (cr ):
165168 upgraded_data = upgrade_callback (load (data ))
166- # import ipdb;ipdb.set_trace()
167169 cr .execute (
168170 """
169171 UPDATE ir_attachment
0 commit comments