summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
Diffstat (limited to 'indoteknik_custom/models')
-rwxr-xr-xindoteknik_custom/models/__init__.py1
-rw-r--r--indoteknik_custom/models/account_payment.py82
-rw-r--r--indoteknik_custom/models/uangmuka_penjualan.py65
3 files changed, 148 insertions, 0 deletions
diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py
index ebbf2e09..432b0641 100755
--- a/indoteknik_custom/models/__init__.py
+++ b/indoteknik_custom/models/__init__.py
@@ -51,3 +51,4 @@ from . import leads_monitoring
from . import midtrans
from . import ip_lookup
from . import wati
+from . import uangmuka_penjualan
diff --git a/indoteknik_custom/models/account_payment.py b/indoteknik_custom/models/account_payment.py
new file mode 100644
index 00000000..11c664eb
--- /dev/null
+++ b/indoteknik_custom/models/account_payment.py
@@ -0,0 +1,82 @@
+from odoo import models, api, fields
+from odoo.exceptions import AccessError, UserError, ValidationError
+import logging
+
+_logger = logging.getLogger(__name__)
+
+
+class AccountPayment(models.Model):
+ _inherit = 'account.payment'
+
+ invoice_bill_ids = fields.Many2many('account.move', string='Invoice/Bill', help='Masukan invoice atau bill yang ingin di alokasi')
+ # lookup_line = fields.One2many('ip.lookup.line', 'ip_lookup_id', string='Lookup Lines', auto_join=True)
+ payment_line = fields.One2many('account.payment.line', 'payment_id', string='Payment Lines', auto_join=True)
+ total_allocated_amt = fields.Float(string='Total Allocated', help='Total Allocated Amount dari setiap Line', compute='_compute_total_payment_line')
+ total_difference = fields.Float(string='Total Difference', help='Total Difference dari setiap Line', compute='_compute_total_payment_line')
+
+ def _compute_total_payment_line(self):
+ for payment in self:
+ total_allocated_amt = total_difference = 0
+ for line in payment.payment_line:
+ total_allocated_amt += line.allocated_amt
+ total_difference += line.difference
+ payment.total_allocated_amt = total_allocated_amt
+ payment.total_difference = total_difference
+
+ def generate_account_payment_lines(self):
+ for payment in self:
+ for invoice in payment.invoice_bill_ids:
+ self.env['account.payment.line'].create([{
+ 'payment_id': payment.id,
+ 'account_move_id': invoice.id,
+ 'open_amt': invoice.amount_residual
+ }])
+
+ def write(self, vals):
+ res = super(AccountPayment, self).write(vals)
+
+ for line in self.payment_line:
+ line.difference = line.open_amt - line.allocated_amt
+
+ return res
+
+ def allocate_invoices(self):
+ for payment in self:
+ if self.
+ for line in payment.payment_line:
+ invoice = line.account_move_id
+ move_lines = payment.line_ids.filtered(lambda line: line.account_internal_type in ('receivable', 'payable'))
+ for line in move_lines:
+ invoice.js_assign_outstanding_line(line.id)
+ _logger.info('Allocated Invoice %s' % invoice.name)
+
+ # def _post(self, soft=True):
+ # # OVERRIDE
+ # # Auto-reconcile the invoice with payments coming from transactions.
+ # # It's useful when you have a "paid" sale order (using a payment transaction) and you invoice it later.
+ # posted = super()._post(soft)
+
+ # for invoice in posted.filtered(lambda move: move.is_invoice()):
+ # payments = invoice.mapped('transaction_ids.payment_id')
+ # move_lines = payments.line_ids.filtered(lambda line: line.account_internal_type in ('receivable', 'payable') and not line.reconciled)
+ # for line in move_lines:
+ # invoice.js_assign_outstanding_line(line.id)
+ # return posted
+
+class PaymentLine(models.Model):
+ _name = 'account.payment.line'
+ _description = 'Custom indoteknik untuk multiple allocation payment atau receipt'
+
+ payment_id = fields.Many2one('account.payment', string='Payment Reference', required=True, ondelete='cascade', index=True, copy=False)
+ # order_id = fields.Many2one('sale.order', string='Order Reference', required=True, ondelete='cascade', index=True, copy=False)
+ account_move_id = fields.Many2one('account.move', string='Invoice/Bill', help='Pilih invoice / bill yang akan dialokasi dengan uang masuk atau uang keluar')
+ open_amt = fields.Float(string='Open', help='Jumlah open amount dari invoice / bill tersebut')
+ allocated_amt = fields.Float(string='Allocated', help='Berapa yang ingin di alokasi untuk invoice / bill tersebut')
+ difference = fields.Float(string='Difference', help='Sisa setelah alokasi')
+
+ def _compute_difference(self):
+ for record in self:
+ if record.open_amt and record.allocated_amt:
+ print(record.open_amt-record.allocated_amt)
+ record.difference = record.open_amt - record.allocated_amt
+ \ No newline at end of file
diff --git a/indoteknik_custom/models/uangmuka_penjualan.py b/indoteknik_custom/models/uangmuka_penjualan.py
new file mode 100644
index 00000000..6c234369
--- /dev/null
+++ b/indoteknik_custom/models/uangmuka_penjualan.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 UangmukaPenjualan(models.TransientModel):
+ _name = 'uangmuka.penjualan'
+ _description = 'digunakan untuk membuat Uang Muka Penjualan'
+
+ pay_amt = fields.Float(string='Payment', help='berapa nilai yang terbentuk untuk COA Uang Muka Penjualan')
+ account_id = fields.Many2one('account.account', string='Bank Intransit', default=389, help='pilih COA intransit bank')
+
+ def create_uangmukapenjualan(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 Penjualan')
+
+ orders = self.env['sale.order'].browse(self._context.get('active_ids',[]))
+ current_time = datetime.now()
+
+ for order in orders:
+ param_header = {
+ 'ref': 'UANG MUKA PENJUALAN '+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 Penjualan %s' % account_move.name)
+
+ param_debit = {
+ 'move_id': account_move.id,
+ 'account_id': self.account_id.id,
+ 'partner_id': order.partner_id.id,
+ 'currency_id': 12,
+ 'debit': self.pay_amt,
+ 'credit': 0,
+ }
+
+ param_credit = {
+ 'move_id': account_move.id,
+ 'account_id': 449, # uang muka penjualan
+ '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
+ }