summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2023-03-20 11:43:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2023-03-20 11:43:50 +0700
commitd8750844beed392c0dd3e588ea242be3c86f2be9 (patch)
tree6371a9dc15db3caf2dfe147f859e6c251cd3fb9a /indoteknik_custom/models
parent4c5ded71ae3562a1efe2584bad3b4e03ad06af16 (diff)
process semi automatic for generate uang muka pembelian
Diffstat (limited to 'indoteknik_custom/models')
-rwxr-xr-xindoteknik_custom/models/__init__.py1
-rw-r--r--indoteknik_custom/models/uangmuka_pembelian.py65
2 files changed, 66 insertions, 0 deletions
diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py
index 432b0641..d86b1225 100755
--- a/indoteknik_custom/models/__init__.py
+++ b/indoteknik_custom/models/__init__.py
@@ -52,3 +52,4 @@ from . import midtrans
from . import ip_lookup
from . import wati
from . import uangmuka_penjualan
+from . import uangmuka_pembelian
diff --git a/indoteknik_custom/models/uangmuka_pembelian.py b/indoteknik_custom/models/uangmuka_pembelian.py
new file mode 100644
index 00000000..29d188d3
--- /dev/null
+++ b/indoteknik_custom/models/uangmuka_pembelian.py
@@ -0,0 +1,65 @@
+from odoo import fields, models, _
+from odoo.exceptions import UserError
+from datetime import datetime
+from odoo.http import request
+
+import logging
+
+_logger = logging.getLogger(__name__)
+
+
+class UangmukaPembelian(models.TransientModel):
+ _name = 'uangmuka.pembelian'
+ _description = 'digunakan untuk membuat Uang Muka Pembelian'
+
+ 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')
+
+ def create_uangmukapembelian(self):
+ if self.pay_amt <= 0:
+ raise UserError('Payment Amount harus diisi')
+ if not self.account_id:
+ raise UserError('Bank Intransit harus diisi')
+ if not self.env.user.is_accounting:
+ raise UserError('Hanya Finance yang dapat membuat Uang Muka Pembelian')
+
+ orders = self.env['purchase.order'].browse(self._context.get('active_ids',[]))
+ current_time = datetime.now()
+
+ for order in orders:
+ param_header = {
+ 'ref': 'UANG MUKA PEMBELIAN '+order.name+' '+order.partner_id.name,
+ 'date': current_time,
+ 'journal_id': 11
+ }
+
+ account_move = request.env['account.move'].create([param_header])
+ _logger.info('Success Create Uang Muka Pembelian %s' % account_move.name)
+
+ param_debit = {
+ 'move_id': account_move.id,
+ 'account_id': 401, # uang muka persediaan barang dagang
+ 'partner_id': order.partner_id.id,
+ 'currency_id': 12,
+ 'debit': self.pay_amt,
+ 'credit': 0,
+ }
+
+ param_credit = {
+ 'move_id': account_move.id,
+ 'account_id': self.account_id.id, # bank in transit
+ 'partner_id': order.partner_id.id,
+ 'currency_id': 12,
+ 'debit': 0,
+ 'credit': self.pay_amt,
+ }
+ request.env['account.move.line'].create([param_debit, param_credit])
+ 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
+ }