diff options
| author | trisusilo48 <tri.susilo@altama.co.id> | 2025-01-13 11:24:08 +0700 |
|---|---|---|
| committer | trisusilo48 <tri.susilo@altama.co.id> | 2025-01-13 11:24:08 +0700 |
| commit | fcefddc96acc561ec13d52e734eaf04b041d4a0b (patch) | |
| tree | 5214a97eb25c3790cdd5b498278d924aac1f0336 /indoteknik_custom/models/account_move.py | |
| parent | bef3ba4c18d585bc0980942d91b5fcb4d44427e1 (diff) | |
update export xml by selected invoice
Diffstat (limited to 'indoteknik_custom/models/account_move.py')
| -rw-r--r-- | indoteknik_custom/models/account_move.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index 725b3c2d..42678847 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -325,3 +325,35 @@ class AccountMove(models.Model): # if rec.statement_line_id and not rec.statement_line_id.statement_id.is_edit and rec.statement_line_id.statement_id.state == 'confirm': # raise UserError('Bank Statement di Lock, Minta admin reconcile untuk unlock') # return res + + def validate_faktur_for_export(self): + invoices = self.filtered(lambda inv: not inv.is_efaktur_exported and + inv.state == 'posted' and + inv.move_type == 'out_invoice') + + invalid_invoices = self - invoices + if invalid_invoices: + invalid_ids = ", ".join(str(inv.id) for inv in invalid_invoices) + raise UserError(_( + "Faktur dengan ID berikut tidak valid untuk diekspor: {}.\n" + "Pastikan faktur dalam status 'posted', belum diekspor, dan merupakan 'out_invoice'.".format(invalid_ids) + )) + + return invoices + + def export_faktur_to_xml(self): + + valid_invoices = self.validate_faktur_for_export() + + # Panggil model coretax.faktur untuk menghasilkan XML + coretax_faktur = self.env['coretax.faktur'].create({}) + response = coretax_faktur.export_to_download(invoices=valid_invoices) + + current_time = datetime.utcnow() + # Tandai faktur sebagai sudah diekspor + valid_invoices.write({ + 'is_efaktur_exported': True, + 'date_efaktur_exported': current_time, # Set tanggal ekspor + }) + + return response |
