diff options
| -rw-r--r-- | indoteknik_custom/models/dunning_run.py | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/indoteknik_custom/models/dunning_run.py b/indoteknik_custom/models/dunning_run.py index 341b206d..5a6aebac 100644 --- a/indoteknik_custom/models/dunning_run.py +++ b/indoteknik_custom/models/dunning_run.py @@ -96,14 +96,18 @@ class DunningRun(models.Model): ] invoices = self.env['account.move'].search(query) - # sort by last number in invoice name - try: - invoices = sorted( - invoices, - key=lambda x: int((x.name or '0').split('/')[-1]) - ) - except Exception as e: - _logger.error('Gagal sort invoice number: %s', e) + # sort full berdasarkan tahun, bulan, nomor + def invoice_key(x): + try: + parts = x.name.split('/') + tahun = int(parts[1]) + bulan = int(parts[2]) + nomor = int(parts[3]) + return (tahun, bulan, nomor) + except Exception: + return (0, 0, 0) + + invoices = sorted(invoices, key=invoice_key) count = 0 for invoice in invoices: |
