diff options
| author | Miqdad <ahmadmiqdad27@gmail.com> | 2025-07-10 14:56:54 +0700 |
|---|---|---|
| committer | Miqdad <ahmadmiqdad27@gmail.com> | 2025-07-10 14:56:54 +0700 |
| commit | 710c5100c5ba4f0a02210418e96a14b66ca03698 (patch) | |
| tree | 8b793a2117dc44e544de8714a68d236875f5cc00 | |
| parent | 6ab4b390aec6ae68e7c3a43fae6bfd730ce54230 (diff) | |
<miqdad> sort dunning run based on invoice num
| -rw-r--r-- | indoteknik_custom/models/dunning_run.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/indoteknik_custom/models/dunning_run.py b/indoteknik_custom/models/dunning_run.py index d7178cb4..341b206d 100644 --- a/indoteknik_custom/models/dunning_run.py +++ b/indoteknik_custom/models/dunning_run.py @@ -92,10 +92,19 @@ class DunningRun(models.Model): ('move_type', '=', 'out_invoice'), ('state', '=', 'posted'), ('partner_id', '=', partner.id), - # ('amount_residual_signed', '>', 0), ('date_kirim_tukar_faktur', '=', False), ] - invoices = self.env['account.move'].search(query, order='invoice_date') + 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) + count = 0 for invoice in invoices: self.env['dunning.run.line'].create([{ |
