Skip to content

Commit e1919b9

Browse files
committed
[FIX] l10n_tr_nilvera_einvoice: group out moves by company on sync
The sync process previously used the wrong company when synchronizing invoices. This fix groups invoices by their respective companies and performs the sync for each company individually. task-5207338 closes odoo#235029 X-original-commit: 1d28969 Signed-off-by: Wala Gauthier (gawa) <gawa@odoo.com> Signed-off-by: Khumam Alzagim (alkh) <alkh@odoo.com>
1 parent 1e66efa commit e1919b9

File tree

2 files changed

+30
-34
lines changed

2 files changed

+30
-34
lines changed

addons/l10n_tr_nilvera_einvoice/models/account_journal.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,10 @@ def button_fetch_in_einvoices(self):
3030
self.env['account.move']._cron_nilvera_get_new_einvoice_purchase_documents()
3131

3232
def button_refresh_out_einvoices_status(self):
33-
# EXTENDS 'account'
34-
"""Gets the status from Nilvera for all processing invoices in
35-
this journal and fetches E-Invoice, & E-Archive invoices from nilvera
33+
""" Extends account to get the status from Nilvera for all processing invoices in
34+
all journals and fetches E-Invoice, & E-Archive invoices from nilvera
3635
"""
3736
super().button_refresh_out_einvoices_status()
38-
invoices_to_update = self.env['account.move'].search([
39-
('journal_id', '=', self.id),
40-
('l10n_tr_nilvera_send_status', 'in', ['waiting', 'sent']),
41-
])
42-
invoices_to_update._l10n_tr_nilvera_get_submitted_document_status()
37+
self.env['account.move']._cron_nilvera_get_invoice_status()
4338
self.env['account.move']._cron_nilvera_get_new_einvoice_sale_documents()
4439
self.env['account.move']._cron_nilvera_get_new_earchive_sale_documents()

addons/l10n_tr_nilvera_einvoice/models/account_move.py

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)