diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2025-06-12 16:18:32 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2025-06-12 16:18:32 +0700 |
| commit | 6616f73259c9e146449af3f2579263b42270bf8b (patch) | |
| tree | 0dfebb75f458c738f63593313b0e19e917e85860 /indoteknik_custom/models/invoice_reklas.py | |
| parent | b6f63fcf96355bc11f9843a9f661cea0a458475e (diff) | |
Revert "<hafid> commit"
This reverts commit 95cef4d4d3936f8a612dadf00e83f9cddcccc0dc, reversing
changes made to 626e93d3a0bfad2bc87002d9e0a7ae860ea9baba.
Diffstat (limited to 'indoteknik_custom/models/invoice_reklas.py')
| -rw-r--r-- | indoteknik_custom/models/invoice_reklas.py | 112 |
1 files changed, 23 insertions, 89 deletions
diff --git a/indoteknik_custom/models/invoice_reklas.py b/indoteknik_custom/models/invoice_reklas.py index 5145e098..d10d4c31 100644 --- a/indoteknik_custom/models/invoice_reklas.py +++ b/indoteknik_custom/models/invoice_reklas.py @@ -11,7 +11,7 @@ _logger = logging.getLogger(__name__) class InvoiceReklas(models.TransientModel): _name = 'invoice.reklas' _description = "digunakan untuk reklas Uang Muka Penjualan" - reklas_id = fields.Many2one('account.move', string='Nomor CAB', domain="[('move_type','=','entry')]") + reklas_id = fields.Many2one('account.move', string='Nomor CAB') pay_amt = fields.Float(string='Yang dibayarkan') reklas_type = fields.Selection([ ('penjualan', 'Penjualan'), @@ -20,105 +20,42 @@ class InvoiceReklas(models.TransientModel): @api.onchange('reklas_type') def _onchange_reklas_type(self): - active_ids = self._context.get('active_ids', []) - if not active_ids: - return - - move = self.env['account.move'].browse(active_ids[0]) - cab = False - - # Deteksi dari mana asal CAB - if move.move_type == 'entry': - cab = move - elif move.move_type == 'in_invoice': - if move.reklas_misc_id: - cab = move.reklas_misc_id - elif move.purchase_order_id and move.purchase_order_id.move_id: - cab = move.purchase_order_id.move_id - - # Isi field Nomor CAB jika ditemukan - if cab: - self.reklas_id = cab.id - - # Nilai yang dibayarkan harus tetap ambil dari invoice/bill - self.pay_amt = move.amount_total - - - @api.model - def default_get(self, fields): - res = super().default_get(fields) - active_ids = self._context.get('active_ids', []) - if active_ids: - move = self.env['account.move'].browse(active_ids[0]) - cab = False - - if move.move_type == 'entry': - cab = move - elif move.move_type == 'in_invoice': - if move.reklas_misc_id: - cab = move.reklas_misc_id - elif move.purchase_order_id and move.purchase_order_id.move_id: - cab = move.purchase_order_id.move_id - - if cab: - res['reklas_id'] = cab.id - - res['pay_amt'] = move.amount_total - return res - - - # @api.onchange('reklas_type') - # def _onchange_reklas_type(self): - # if self.reklas_type == 'penjualan': - # invoices = self.env['account.move'].browse(self._context.get('active_ids', [])) - # self.pay_amt = invoices.amount_total + if self.reklas_type == 'penjualan': + invoices = self.env['account.move'].browse(self._context.get('active_ids', [])) + self.pay_amt = invoices.amount_total def create_reklas(self): if not self.reklas_type: raise UserError('Reklas Tipe harus diisi') if not self.reklas_id: raise UserError('Nomor CAB harus diisi') - invoices = self.env['account.move'].browse(self._context.get('active_ids', [])) current_time = datetime.now() - for invoice in invoices: - # Ambil nama PO jika ada - po_name = invoice.purchase_order_id.name if invoice.purchase_order_id else '' - - # Susun nama referensi dengan aman - ref_name = 'REKLAS {} UANG MUKA {} {}{} {}'.format( - self.reklas_id.name or '', - 'PENJUALAN' if self.reklas_type == 'penjualan' else 'PEMBELIAN', - invoice.name or '', - f" - {po_name}" if po_name else '', - invoice.partner_id.name or '' - ) - - # Header jurnal reklas - parameters_header = { - 'ref': ref_name, - 'date': current_time, - 'journal_id': 13 - } + if self.reklas_type == 'penjualan': + ref_name = 'REKLAS '+self.reklas_id.name+" UANG MUKA PENJUALAN "+invoice.name+" "+invoice.partner_id.name + else: + ref_name = 'REKLAS '+self.reklas_id.name+" UANG MUKA PEMBELIAN "+invoice.name+" "+invoice.partner_id.name + if self.reklas_type == 'penjualan': + parameters_header = { + 'ref': ref_name, + 'date': current_time, + 'journal_id': 13 + } + else: + parameters_header = { + 'ref': ref_name, + 'date': current_time, + 'journal_id': 13 + } account_move = request.env['account.move'].create([parameters_header]) _logger.info('Success Reklas with %s' % account_move.name) - # ✅ Set Bill asal sebagai source document - account_move.bill_id = invoice.id - - # Tambahkan info asal invoice ke jurnal (opsional) - account_move.invoice_origin = invoice.name - - # Simpan hubungan balik ke invoice - invoice.reklas_misc_id = account_move.id - - # Buat line debit dan kredit if self.reklas_type == 'penjualan': parameter_debit = { 'move_id': account_move.id, - 'account_id': 668, # penerimaan belum alokasi + 'account_id': 668, # penerimaan belum alokasi 'partner_id': invoice.partner_id.id, 'currency_id': 12, 'debit': self.pay_amt, @@ -134,7 +71,7 @@ class InvoiceReklas(models.TransientModel): 'credit': self.pay_amt, 'name': ref_name } - else: # pembelian + else: parameter_debit = { 'move_id': account_move.id, 'account_id': 438, @@ -153,11 +90,7 @@ class InvoiceReklas(models.TransientModel): 'credit': self.pay_amt, 'name': ref_name } - - # Simpan journal lines request.env['account.move.line'].create([parameter_debit, parameter_credit]) - - # Tampilkan hasil jurnal reklas return { 'name': _('Journal Entries'), 'view_mode': 'form', @@ -167,3 +100,4 @@ class InvoiceReklas(models.TransientModel): 'type': 'ir.actions.act_window', 'res_id': account_move.id } +
\ No newline at end of file |
