diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2023-03-20 16:19:04 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2023-03-20 16:19:04 +0700 |
| commit | 36964fe87a29803265fa33223a208db66d434891 (patch) | |
| tree | 468f580af53c801ce558173d421ecac1a8abe9bd | |
| parent | cdd6919af886ab6eba9daa32d10254c6f3e14101 (diff) | |
add selisih and ongkir in uang muka pembelian
| -rw-r--r-- | indoteknik_custom/models/uangmuka_pembelian.py | 47 | ||||
| -rw-r--r-- | indoteknik_custom/views/uangmuka_pembelian.xml | 3 |
2 files changed, 46 insertions, 4 deletions
diff --git a/indoteknik_custom/models/uangmuka_pembelian.py b/indoteknik_custom/models/uangmuka_pembelian.py index 3d271117..02371418 100644 --- a/indoteknik_custom/models/uangmuka_pembelian.py +++ b/indoteknik_custom/models/uangmuka_pembelian.py @@ -1,9 +1,9 @@ -from odoo import fields, models, _ +from odoo import fields, models, _, api from odoo.exceptions import UserError from datetime import datetime from odoo.http import request -import logging +import logging, math _logger = logging.getLogger(__name__) @@ -14,7 +14,15 @@ class UangmukaPembelian(models.TransientModel): pay_amt = fields.Float(string='Payment', 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 self.pay_amt <= 0: raise UserError('Payment Amount harus diisi') @@ -26,6 +34,12 @@ class UangmukaPembelian(models.TransientModel): 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: ref_label = 'UANG MUKA PEMBELIAN '+order.name+' '+order.partner_id.name param_header = { @@ -46,6 +60,24 @@ class UangmukaPembelian(models.TransientModel): 'credit': 0, 'name': ref_label, } + param_debit_ongkir = { + 'move_id': account_move.id, + 'account_id': 536, # biaya ongkos kirim + 'partner_id': order.partner_id.id, + 'currency_id': 12, + 'debit': self.ongkir_amt, + 'credit': 0, + 'name': ref_label, + } + param_debit_selisih = { + 'move_id': account_move.id, + 'account_id': 561, # selisih pembayaran + 'partner_id': order.partner_id.id, + 'currency_id': 12, + 'debit': self.selisih_amt, + 'credit': 0, + 'name': ref_label, + } param_credit = { 'move_id': account_move.id, @@ -53,10 +85,17 @@ class UangmukaPembelian(models.TransientModel): 'partner_id': order.partner_id.id, 'currency_id': 12, 'debit': 0, - 'credit': self.pay_amt, + 'credit': self.pay_amt + self.ongkir_amt + self.selisih_amt, 'name': ref_label, } - request.env['account.move.line'].create([param_debit, param_credit]) + 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]) return { 'name': _('Journal Entries'), 'view_mode': 'form', diff --git a/indoteknik_custom/views/uangmuka_pembelian.xml b/indoteknik_custom/views/uangmuka_pembelian.xml index 6cd0bec5..7bc6e7a6 100644 --- a/indoteknik_custom/views/uangmuka_pembelian.xml +++ b/indoteknik_custom/views/uangmuka_pembelian.xml @@ -10,7 +10,10 @@ </p> <group> <field name="pay_amt"/> + <field name="ongkir_amt"/> + <field name="selisih_amt"/> <field name="account_id" domain="[('name', 'ilike', 'intransit')]"/> + <field name="total_amt" readonly="1"/> </group> <footer> <button name="create_uangmukapembelian" id="create_uangmukapembelian" string="Create" type="object" required="1"/> |
