diff options
| author | Indoteknik . <it@fixcomart.co.id> | 2025-06-10 13:10:35 +0700 |
|---|---|---|
| committer | Indoteknik . <it@fixcomart.co.id> | 2025-06-10 13:10:35 +0700 |
| commit | c827294ee6dd613de089af846521cfdc76550e16 (patch) | |
| tree | 9483340f1c8465c35b9c6089890f2cd261b410fc | |
| parent | 9200e74126c99410b79ef2c344915251bef6af19 (diff) | |
(andri) revisi mengenai onchange create reklas dan yang lain
| -rw-r--r-- | indoteknik_custom/models/account_move.py | 3 | ||||
| -rw-r--r-- | indoteknik_custom/models/invoice_reklas.py | 97 | ||||
| -rw-r--r-- | indoteknik_custom/models/invoice_reklas_penjualan.py | 60 | ||||
| -rw-r--r-- | indoteknik_custom/views/account_move.xml | 1 |
4 files changed, 118 insertions, 43 deletions
diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index 3333af8f..4cd2b6b3 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -68,6 +68,9 @@ class AccountMove(models.Model): purchase_order_id = fields.Many2one('purchase.order', string='Purchase Order') length_of_payment = fields.Integer(string="Length of Payment", compute='compute_length_of_payment') reklas_misc_id = fields.Many2one('account.move', string='Journal Entries Reklas') + # Di model account.move + bill_id = fields.Many2one('account.move', string='Vendor Bill', domain=[('move_type', '=', 'in_invoice')], help='Bill asal dari proses reklas ini') + def name_get(self): result = [] diff --git a/indoteknik_custom/models/invoice_reklas.py b/indoteknik_custom/models/invoice_reklas.py index 5e21a787..b7d52371 100644 --- a/indoteknik_custom/models/invoice_reklas.py +++ b/indoteknik_custom/models/invoice_reklas.py @@ -20,12 +20,26 @@ class InvoiceReklas(models.TransientModel): @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 - # Tambahan ini: - if len(invoices) == 1 and invoices.move_type == 'entry': - self.reklas_id = invoices.id + active_ids = self._context.get('active_ids', []) + if not active_ids: + return + + 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: + self.reklas_id = cab.id + + # ✅ Selalu ambil nilai dari invoice yang direklas (bukan dari CAB) + self.pay_amt = move.amount_total @api.model def default_get(self, fields): @@ -33,11 +47,23 @@ class InvoiceReklas(models.TransientModel): 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': - res['reklas_id'] = move.id - res['pay_amt'] = move.amount_total # atau amount_residual jika mau sisa + 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': @@ -49,33 +75,47 @@ class InvoiceReklas(models.TransientModel): 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: - 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 - } + # 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 + } 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, @@ -91,7 +131,7 @@ class InvoiceReklas(models.TransientModel): 'credit': self.pay_amt, 'name': ref_name } - else: + else: # pembelian parameter_debit = { 'move_id': account_move.id, 'account_id': 438, @@ -110,7 +150,11 @@ 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', @@ -120,4 +164,3 @@ class InvoiceReklas(models.TransientModel): 'type': 'ir.actions.act_window', 'res_id': account_move.id } -
\ No newline at end of file diff --git a/indoteknik_custom/models/invoice_reklas_penjualan.py b/indoteknik_custom/models/invoice_reklas_penjualan.py index 80c3ed43..2f5ee160 100644 --- a/indoteknik_custom/models/invoice_reklas_penjualan.py +++ b/indoteknik_custom/models/invoice_reklas_penjualan.py @@ -17,43 +17,70 @@ class InvoiceReklasPenjualan(models.TransientModel): def create_reklas_penjualan(self): invoices = self.invoice_reklas_line - current_time = datetime.now() account_move_ids = [] - for invoice in invoices: - ref_name = 'REKLAS ' + invoice.reklas_id.name + " UANG MUKA PENJUALAN " + invoice.name + " " + invoice.partner_id.name + + for line in invoices: + # Ambil nama SO jika ada + so_name = line.sale_id.name if line.sale_id else '' + + # Susun referensi nama jurnal + ref_name = 'REKLAS {} UANG MUKA PENJUALAN {}{} {}'.format( + line.reklas_id.name or '', + line.name or '', + f" - {so_name}" if so_name else '', + line.partner_id.name or '' + ) + + # Header jurnal parameters_header = { 'ref': ref_name, 'date': current_time, - 'journal_id': 13 + 'journal_id': 13, + # ⬇️ Tambahkan jika tahu invoice asal (name = ID Bill) + 'bill_id': int(line.name) if line.name and line.name.isdigit() else False, } account_move = self.env['account.move'].create([parameters_header]) _logger.info('Success Reklas with %s' % account_move.name) - parameter_debit = { + # Simpan info asal (optional) + account_move.invoice_origin = line.name + + # Simpan juga ke `reklas_misc_id` jika ditemukan invoice valid + if line.name and line.name.isdigit(): + invoice_id = self.env['account.move'].browse(int(line.name)) + if invoice_id.exists(): + invoice_id.reklas_misc_id = account_move.id + + # Buat debit kredit line + debit_line = { 'move_id': account_move.id, - 'account_id': 668, # uang muka penjualan - 'partner_id': invoice.partner_id.id, + 'account_id': 668, # akun penerimaan belum alokasi + 'partner_id': line.partner_id.id, 'currency_id': 12, - 'debit': invoice.pay_amt, + 'debit': line.pay_amt, 'credit': 0, 'name': ref_name } - parameter_credit = { + credit_line = { 'move_id': account_move.id, - 'account_id': 395, - 'partner_id': invoice.partner_id.id, + 'account_id': 395, # akun pengurang + 'partner_id': line.partner_id.id, 'currency_id': 12, 'debit': 0, - 'credit': invoice.pay_amt, + 'credit': line.pay_amt, 'name': ref_name } - self.env['account.move.line'].create([parameter_debit, parameter_credit]) + + self.env['account.move.line'].create([debit_line, credit_line]) account_move_ids.append(account_move.id) - invoice.unlink() - - self.unlink() + + line.unlink() # bersihkan line setelah selesai + + self.unlink() # hapus wizard utama setelah selesai + + # Tampilkan hasil jurnal reklas return { 'name': _('Journal Entries'), 'view_mode': 'tree,form', @@ -63,6 +90,7 @@ class InvoiceReklasPenjualan(models.TransientModel): 'domain': [('id', 'in', account_move_ids)], } + class InvoiceReklasPenjualanLine(models.TransientModel): _name = 'invoice.reklas.penjualan.line' _description = "digunakan untuk reklas Uang Muka Penjualan" diff --git a/indoteknik_custom/views/account_move.xml b/indoteknik_custom/views/account_move.xml index 07efc077..3a620a6a 100644 --- a/indoteknik_custom/views/account_move.xml +++ b/indoteknik_custom/views/account_move.xml @@ -38,6 +38,7 @@ <field name="ref" position="after"> <field name="sale_id" readonly="1" attrs="{'invisible': [('move_type', '!=', 'entry')]}"/> <field name="purchase_order_id" context="{'form_view_ref': 'purchase.purchase_order_form'}" options="{'no_create': True}"/> + <field name="bill_id" readonly="1" attrs="{'invisible': [('move_type', '!=', 'entry')]}"/> </field> <field name="partner_shipping_id" position="before"> <field name="real_invoice_id" readonly="1" attrs="{'invisible': [('move_type', '!=', 'out_invoice')]}"/> |
