fix error in gitignore
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
from celery import shared_task
|
||||
from django.utils import timezone
|
||||
|
||||
from apps.integrations.odoo.services import OdooInvoiceService
|
||||
from apps.invoicing.models import Invoice
|
||||
|
||||
|
||||
@shared_task(bind=True, max_retries=5, default_retry_delay=60)
|
||||
def sync_invoice_to_odoo(self, invoice_id):
|
||||
"""Synchronize an invoice to Odoo with automatic retry (idempotent)."""
|
||||
try:
|
||||
invoice = Invoice.objects.get(pk=invoice_id)
|
||||
except Invoice.DoesNotExist:
|
||||
return
|
||||
if invoice.sync_state == Invoice.SyncState.SYNCHRONIZED:
|
||||
return # already synchronized; retries must be idempotent
|
||||
|
||||
invoice.sync_state = Invoice.SyncState.PROCESSING
|
||||
invoice.save(update_fields=["sync_state"])
|
||||
try:
|
||||
result = OdooInvoiceService().sync_invoice(invoice)
|
||||
invoice.odoo_invoice_id = result.get("id", "")
|
||||
invoice.sync_state = Invoice.SyncState.SYNCHRONIZED
|
||||
invoice.synced_at = timezone.now()
|
||||
invoice.save(update_fields=["odoo_invoice_id", "sync_state", "synced_at"])
|
||||
except Exception as exc:
|
||||
invoice.sync_state = Invoice.SyncState.RETRYING
|
||||
invoice.last_error = str(exc)
|
||||
invoice.save(update_fields=["sync_state", "last_error"])
|
||||
raise self.retry(exc=exc)
|
||||
Reference in New Issue
Block a user