diff options
| author | Miqdad <ahmadmiqdad27@gmail.com> | 2025-07-10 15:12:56 +0700 |
|---|---|---|
| committer | Miqdad <ahmadmiqdad27@gmail.com> | 2025-07-10 15:12:56 +0700 |
| commit | b2c6b57b7c621379aea029d2c716282cc65db6e0 (patch) | |
| tree | 1fbc48c39b4ac1481e3e92d9737130fa5fd47b85 | |
| parent | 710c5100c5ba4f0a02210418e96a14b66ca03698 (diff) | |
<miqdad> sort dunning run based on invoice num
| -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: |
