From c7781579662dbf2b66dcaff5d1b3737e9e32c3c5 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Thu, 10 Jul 2025 14:08:38 +0700 Subject: sort dunning run based on invoice num --- indoteknik_custom/models/dunning_run.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models/dunning_run.py') diff --git a/indoteknik_custom/models/dunning_run.py b/indoteknik_custom/models/dunning_run.py index bb53fc0c..682c7b0b 100644 --- a/indoteknik_custom/models/dunning_run.py +++ b/indoteknik_custom/models/dunning_run.py @@ -1,3 +1,4 @@ +from Tools.scripts.dutree import store from odoo import models, api, fields from odoo.exceptions import AccessError, UserError, ValidationError from datetime import timedelta @@ -123,8 +124,9 @@ class DunningRunLine(models.Model): _name = 'dunning.run.line' _description = 'Dunning Run Line' # _order = 'dunning_id, id' - _order = 'invoice_id desc, id' + _order = 'invoice_number asc, id' + invoice_number = fields.Char('Invoice Number', related='invoice_id.name', store=True) dunning_id = fields.Many2one('dunning.run', string='Dunning Ref', required=True, ondelete='cascade', index=True, copy=False) partner_id = fields.Many2one('res.partner', string='Customer') invoice_id = fields.Many2one('account.move', string='Invoice') -- cgit v1.2.3 From d5a9aa70794de3604a1db9fdcb5f6952afa4a52b Mon Sep 17 00:00:00 2001 From: Miqdad Date: Thu, 10 Jul 2025 14:12:52 +0700 Subject: sort dunning run based on invoice num --- indoteknik_custom/models/dunning_run.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models/dunning_run.py') diff --git a/indoteknik_custom/models/dunning_run.py b/indoteknik_custom/models/dunning_run.py index 682c7b0b..fdc730de 100644 --- a/indoteknik_custom/models/dunning_run.py +++ b/indoteknik_custom/models/dunning_run.py @@ -126,7 +126,7 @@ class DunningRunLine(models.Model): # _order = 'dunning_id, id' _order = 'invoice_number asc, id' - invoice_number = fields.Char('Invoice Number', related='invoice_id.name', store=True) + invoice_number = fields.Char('Invoice Number', related='invoice_id.name') dunning_id = fields.Many2one('dunning.run', string='Dunning Ref', required=True, ondelete='cascade', index=True, copy=False) partner_id = fields.Many2one('res.partner', string='Customer') invoice_id = fields.Many2one('account.move', string='Invoice') -- cgit v1.2.3 From 6ab4b390aec6ae68e7c3a43fae6bfd730ce54230 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Thu, 10 Jul 2025 14:18:37 +0700 Subject: sort dunning run based on invoice num --- indoteknik_custom/models/dunning_run.py | 1 - 1 file changed, 1 deletion(-) (limited to 'indoteknik_custom/models/dunning_run.py') diff --git a/indoteknik_custom/models/dunning_run.py b/indoteknik_custom/models/dunning_run.py index fdc730de..d7178cb4 100644 --- a/indoteknik_custom/models/dunning_run.py +++ b/indoteknik_custom/models/dunning_run.py @@ -1,4 +1,3 @@ -from Tools.scripts.dutree import store from odoo import models, api, fields from odoo.exceptions import AccessError, UserError, ValidationError from datetime import timedelta -- cgit v1.2.3 From 710c5100c5ba4f0a02210418e96a14b66ca03698 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Thu, 10 Jul 2025 14:56:54 +0700 Subject: sort dunning run based on invoice num --- indoteknik_custom/models/dunning_run.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models/dunning_run.py') 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([{ -- cgit v1.2.3 From b2c6b57b7c621379aea029d2c716282cc65db6e0 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Thu, 10 Jul 2025 15:12:56 +0700 Subject: sort dunning run based on invoice num --- indoteknik_custom/models/dunning_run.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'indoteknik_custom/models/dunning_run.py') 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: -- cgit v1.2.3