1010from odoo import fields , models
1111from odoo .exceptions import UserError
1212from odoo .fields import Domain
13+ from odoo .tools import html_escape
1314
1415_logger = logging .getLogger (__name__ )
1516
@@ -27,6 +28,7 @@ def action_import(self):
2728 zip_binary = base64 .b64decode (self .l10n_it_edi_attachment )
2829 zip_io = io .BytesIO (zip_binary )
2930 moves = self .env ["account.move" ]
31+ skipped_files = []
3032
3133 with zipfile .ZipFile (zip_io , "r" ) as zip_ref :
3234 for member in zip_ref .infolist ():
@@ -72,6 +74,7 @@ def action_import(self):
7274
7375 if not files_data :
7476 _logger .info (f"Skipping { filename } , not an XML/P7M file" )
77+ skipped_files .append (filename )
7578 attachment .unlink ()
7679 continue
7780
@@ -105,12 +108,33 @@ def action_import(self):
105108 )
106109
107110 moves |= records
108-
109- return {
110- "view_type" : "form" ,
111+ action = {
111112 "name" : self .env ._ ("E-invoices" ),
112- "view_mode" : "list,form" ,
113- "res_model" : "account.move" ,
114113 "type" : "ir.actions.act_window" ,
114+ "res_model" : "account.move" ,
115+ "view_mode" : "list,form" ,
116+ "views" : [[False , "list" ], [False , "form" ]],
115117 "domain" : Domain ("id" , "in" , moves .ids ),
116118 }
119+ if skipped_files :
120+ skipped_list_html = "" .join (
121+ f"<li>{ html_escape (f )} </li>" for f in skipped_files
122+ )
123+ skipped_info_html = (
124+ self .env ._ (
125+ "The following files were skipped (not valid XML/P7M):<ul>%s</ul>"
126+ )
127+ % skipped_list_html
128+ )
129+ # Create activity for the current user
130+ self .env ["mail.activity" ].create (
131+ {
132+ "activity_type_id" : self .env .ref ("mail.mail_activity_data_todo" ).id ,
133+ "note" : skipped_info_html ,
134+ "summary" : self .env ._ ("Partial import: skipped files" ),
135+ "user_id" : self .env .uid ,
136+ "res_id" : self .env .user .partner_id .id ,
137+ "res_model_id" : self .env ["ir.model" ]._get_id ("res.partner" ),
138+ }
139+ )
140+ return action
0 commit comments