summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/invoice_reklas.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2023-01-12 14:20:13 +0700
committerstephanchrst <stephanchrst@gmail.com>2023-01-12 14:20:13 +0700
commiteca50fa062424b6a7aa9b3d00649dd3db29b3ab6 (patch)
tree9ce1da22bcdfb8c85c4b11a7b8f27eac4a3cf82c /indoteknik_custom/models/invoice_reklas.py
parente74ac27eb94a05c569f9789b1f875f7c85b6dc02 (diff)
parent0f8fbe56e89ec285c6fbcdd2bed5a67f62bcfe59 (diff)
Merge branch 'release' into staging
Diffstat (limited to 'indoteknik_custom/models/invoice_reklas.py')
-rw-r--r--indoteknik_custom/models/invoice_reklas.py89
1 files changed, 89 insertions, 0 deletions
diff --git a/indoteknik_custom/models/invoice_reklas.py b/indoteknik_custom/models/invoice_reklas.py
new file mode 100644
index 00000000..43736059
--- /dev/null
+++ b/indoteknik_custom/models/invoice_reklas.py
@@ -0,0 +1,89 @@
+from odoo import api, fields, models, _
+from odoo.exceptions import UserError
+from datetime import datetime
+from odoo.http import request
+
+import logging
+
+_logger = logging.getLogger(__name__)
+
+
+class InvoiceReklas(models.TransientModel):
+ _name = 'invoice.reklas'
+ _description = "digunakan untuk reklas Uang Muka Penjualan"
+ reklas_id = fields.Many2one('account.move', string='Nomor CAB')
+ pay_amt = fields.Float(string='Yang dibayarkan')
+ reklas_type = fields.Selection([
+ ('penjualan', 'Penjualan'),
+ ('pembelian', 'Pembelian'),
+ ], string='Reklas Tipe')
+
+ def create_reklas(self):
+ if not self.reklas_type:
+ raise UserError('Reklas Tipe harus diisi')
+ if not self.reklas_id:
+ raise UserError('Nomor CAB harus diisi')
+ invoices = self.env['account.move'].browse(self._context.get('active_ids', []))
+ current_time = datetime.now()
+ for invoice in invoices:
+
+ if self.reklas_type == 'penjualan':
+ parameters_header = {
+ 'ref': 'REKLAS '+self.reklas_id.name+" UANG MUKA PENJUALAN "+invoice.name+" "+invoice.partner_id.name,
+ 'date': current_time,
+ 'journal_id': 13
+ }
+ else:
+ parameters_header = {
+ 'ref': 'REKLAS ' + self.reklas_id.name + " UANG MUKA PEMBELIAN " + invoice.name + " " + invoice.partner_id.name,
+ 'date': current_time,
+ 'journal_id': 13
+ }
+
+ account_move = request.env['account.move'].create([parameters_header])
+ _logger.info('Success Reklas with %s' % account_move.name)
+
+ if self.reklas_type == 'penjualan':
+ parameter_debit = {
+ 'move_id': account_move.id,
+ 'account_id': 449,
+ 'partner_id': invoice.partner_id.id,
+ 'currency_id': 12,
+ 'debit': self.pay_amt,
+ 'credit': 0
+ }
+ parameter_credit = {
+ 'move_id': account_move.id,
+ 'account_id': 395,
+ 'partner_id': invoice.partner_id.id,
+ 'currency_id': 12,
+ 'debit': 0,
+ 'credit': self.pay_amt
+ }
+ else:
+ parameter_debit = {
+ 'move_id': account_move.id,
+ 'account_id': 438,
+ 'partner_id': invoice.partner_id.id,
+ 'currency_id': 12,
+ 'debit': self.pay_amt,
+ 'credit': 0
+ }
+ parameter_credit = {
+ 'move_id': account_move.id,
+ 'account_id': 401,
+ 'partner_id': invoice.partner_id.id,
+ 'currency_id': 12,
+ 'debit': 0,
+ 'credit': self.pay_amt
+ }
+ request.env['account.move.line'].create([parameter_debit, parameter_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
+ }