diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2025-08-04 09:55:46 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2025-08-04 09:55:46 +0700 |
| commit | ca5912d9f29f4bb2e7b482cce01f917285ed53cb (patch) | |
| tree | 5b5a6e3dc607f0bcd0a448c780cacdcad4f949a2 /fixco_custom/models/uangmuka_pembelian.py | |
| parent | c99a62f139fd7dfad7ffb2911eaaa7e7b95c7dd5 (diff) | |
penyusutan, reklas, journal uang muka
Diffstat (limited to 'fixco_custom/models/uangmuka_pembelian.py')
| -rw-r--r-- | fixco_custom/models/uangmuka_pembelian.py | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/fixco_custom/models/uangmuka_pembelian.py b/fixco_custom/models/uangmuka_pembelian.py new file mode 100644 index 0000000..9374ba2 --- /dev/null +++ b/fixco_custom/models/uangmuka_pembelian.py @@ -0,0 +1,121 @@ +from odoo import fields, models, _, api +from odoo.exceptions import UserError +from datetime import datetime +from odoo.http import request + +import logging, math + +_logger = logging.getLogger(__name__) + + +class UangmukaPembelian(models.TransientModel): + _name = 'uangmuka.pembelian' + _description = 'digunakan untuk membuat Uang Muka Pembelian' + + pay_amt = fields.Float(string='Uang Muka', help='berapa nilai yang terbentuk untuk COA Uang Muka Pembelian') + account_id = fields.Many2one('account.account', string='Bank Intransit', default=389, help='pilih COA intransit bank') + ongkir_amt = fields.Float(string='Ongkir', help='masukan nilai yang akan menjadi Pendapatan Ongkos Kirim') + selisih_amt = fields.Float(string='Selisih', help='masukan nilai yang akan menjadi Selisih Pembayaran') + total_amt = fields.Float(string='Total', help='Total yang akan masuk di journal entries') + + @api.onchange('pay_amt', 'ongkir_amt', 'selisih_amt') + def _compute_total_amt(self): + for o in self: + o.total_amt = o.pay_amt + o.ongkir_amt + o.selisih_amt + + def create_uangmukapembelian(self): + if not self.account_id: + raise UserError('Bank Intransit harus diisi') + + orders = self.env['purchase.order'].browse(self._context.get('active_ids',[])) + current_time = datetime.now() + + is_have_ongkir = is_have_selisih = False + if self.ongkir_amt > 0: + is_have_ongkir = True + if not math.isclose(self.selisih_amt, 0): + is_have_selisih = True + + for order in orders: + # if order.is_create_uangmuka == True: + # action = self.env['ir.actions.act_window']._for_xml_id('indoteknik_custom.action_purchase_order_multi_uangmuka2') + # action['context'] = { + # 'order_ids': [x.id for x in order] + # } + # return action + partner_name = order.partner_id.name + if order.partner_id.parent_id: + partner_name = order.partner_id.parent_id.name + ref_label = 'UANG MUKA PEMBELIAN '+order.name+' '+partner_name + param_header = { + 'ref': ref_label, + 'date': current_time, + 'journal_id': 23, + 'purchase_order_id': order.id + } + + account_move = request.env['account.move'].create([param_header]) + _logger.info('Success Create Uang Muka Pembelian %s' % account_move.name) + account_move.purchase_order_id = order.id # isi field purchase_order_id + + if order.partner_id.parent_id: + partner_id = order.partner_id.parent_id.id + else: + partner_id = order.partner_id.id + + param_debit = { + 'move_id': account_move.id, + 'account_id': 579, # uang muka persediaan barang dagang + 'partner_id': partner_id, + 'currency_id': 12, + 'debit': self.pay_amt, + 'credit': 0, + 'name': ref_label, + } + param_debit_ongkir = { + 'move_id': account_move.id, + 'account_id': 758, # biaya ongkos kirim + 'partner_id': partner_id, + 'currency_id': 12, + 'debit': self.ongkir_amt, + 'credit': 0, + 'name': ref_label, + } + param_debit_selisih = { + 'move_id': account_move.id, + 'account_id': 767, # selisih pembayaran + 'partner_id': partner_id, + 'currency_id': 12, + 'debit': self.selisih_amt, + 'credit': 0, + 'name': ref_label, + } + + param_credit = { + 'move_id': account_move.id, + 'account_id': self.account_id.id, # bank in transit + 'partner_id': partner_id, + 'currency_id': 12, + 'debit': 0, + 'credit': self.pay_amt + self.ongkir_amt + self.selisih_amt, + 'name': ref_label, + } + if is_have_ongkir and is_have_selisih: + request.env['account.move.line'].create([param_debit, param_debit_ongkir, param_debit_selisih, param_credit]) + elif is_have_ongkir: + request.env['account.move.line'].create([param_debit, param_debit_ongkir, param_credit]) + elif is_have_selisih: + request.env['account.move.line'].create([param_debit, param_debit_selisih, param_credit]) + else: + request.env['account.move.line'].create([param_debit, param_credit]) + # order.is_create_uangmuka = True + order.move_entry_id = account_move.id + return { + 'name': _('Journal Entries'), + 'view_mode': 'form', + 'res_model': 'account.move', + 'target': 'current', + 'view_id': False, + 'type': 'ir.actions.act_window', + 'res_id': account_move.id + } |
