summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2025-07-10 08:18:09 +0000
committerIT Fixcomart <it@fixcomart.co.id>2025-07-10 08:18:09 +0000
commitced1cf1a4733bc713f899d50d1e365f36c9fad56 (patch)
treec8d8cc7732bb37346f94f6ada084317debc7a842
parent0a66ca2c69581100f5a0800152a6d80a07351d6c (diff)
parentb2c6b57b7c621379aea029d2c716282cc65db6e0 (diff)
Merged in sort_dunning_run (pull request #353)
<miqdad> sort dunning run based on invoice num
-rw-r--r--indoteknik_custom/models/dunning_run.py20
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: