@@ -169,33 +169,34 @@ def _l10n_tr_nilvera_post_series(self, endpoint, client):
169169 )
170170
171171 def _l10n_tr_nilvera_get_submitted_document_status (self ):
172- with _get_nilvera_client (self .env .company ) as client :
173- for invoice in self :
174- invoice_channel = invoice .partner_id .l10n_tr_nilvera_customer_status
175- document_category = invoice ._l10n_tr_get_document_category (invoice_channel )
176- if not document_category or not invoice_channel :
177- continue
178-
179- response = client .request (
180- "GET" ,
181- f"/{ invoice_channel } /{ quote (document_category )} /{ invoice .l10n_tr_nilvera_uuid } /Status" ,
182- )
183-
184- nilvera_status = response .get ('InvoiceStatus' , {}).get ('Code' ) or response .get ('StatusCode' )
185- if nilvera_status in dict (invoice ._fields ['l10n_tr_nilvera_send_status' ].selection ):
186- invoice .l10n_tr_nilvera_send_status = nilvera_status
187- if nilvera_status == 'error' :
188- invoice .message_post (
189- body = Markup (
190- "%s<br/>%s - %s<br/>"
191- ) % (
192- _ ("The invoice couldn't be sent to the recipient." ),
193- response .get ('InvoiceStatus' , {}).get ('Description' ) or response .get ('StatusDetail' ),
194- response .get ('InvoiceStatus' , {}).get ('DetailDescription' ) or response .get ('ReportStatus' ),
172+ for company , invoices in self .grouped ("company_id" ).items ():
173+ with _get_nilvera_client (company ) as client :
174+ for invoice in invoices :
175+ invoice_channel = invoice .partner_id .l10n_tr_nilvera_customer_status
176+ document_category = invoice ._l10n_tr_get_document_category (invoice_channel )
177+ if not document_category or not invoice_channel :
178+ continue
179+
180+ response = client .request (
181+ "GET" ,
182+ f"/{ invoice_channel } /{ quote (document_category )} /{ invoice .l10n_tr_nilvera_uuid } /Status" ,
183+ )
184+
185+ nilvera_status = response .get ('InvoiceStatus' , {}).get ('Code' ) or response .get ('StatusCode' )
186+ if nilvera_status in dict (invoice ._fields ['l10n_tr_nilvera_send_status' ].selection ):
187+ invoice .l10n_tr_nilvera_send_status = nilvera_status
188+ if nilvera_status == 'error' :
189+ invoice .message_post (
190+ body = Markup (
191+ "%s<br/>%s - %s<br/>"
192+ ) % (
193+ _ ("The invoice couldn't be sent to the recipient." ),
194+ response .get ('InvoiceStatus' , {}).get ('Description' ) or response .get ('StatusDetail' ),
195+ response .get ('InvoiceStatus' , {}).get ('DetailDescription' ) or response .get ('ReportStatus' ),
196+ )
195197 )
196- )
197- else :
198- invoice .message_post (body = _ ("The invoice status couldn't be retrieved from Nilvera." ))
198+ else :
199+ invoice .message_post (body = _ ("The invoice status couldn't be retrieved from Nilvera." ))
199200
200201 def _l10n_tr_nilvera_get_documents (self , invoice_channel = "einvoice" , document_category = "Purchase" , journal_type = "in_invoice" ):
201202 with _get_nilvera_client (self .env .company ) as client :
0 commit comments