summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/account_payment.py
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-03-24 15:51:53 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-03-24 15:51:53 +0700
commitd7838ad087daf51826d3be27888df04eac09a293 (patch)
tree629154312c99d14f08d61f541165a2396f175561 /indoteknik_custom/models/account_payment.py
parent056a719bbb24a931b119515f0483b96ad2f4d415 (diff)
parent3aa64db9c10d0fcb8009e9e6f942672a12669099 (diff)
fix conflict
Diffstat (limited to 'indoteknik_custom/models/account_payment.py')
-rw-r--r--indoteknik_custom/models/account_payment.py82
1 files changed, 82 insertions, 0 deletions
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