From 4c5ded71ae3562a1efe2584bad3b4e03ad06af16 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 20 Mar 2023 11:30:36 +0700 Subject: process semi automatic create uang muka penjualan --- indoteknik_custom/__manifest__.py | 1 + indoteknik_custom/models/__init__.py | 1 + indoteknik_custom/models/account_payment.py | 82 ++++++++++++++++++++++++++ indoteknik_custom/models/uangmuka_penjualan.py | 65 ++++++++++++++++++++ indoteknik_custom/security/ir.model.access.csv | 3 +- indoteknik_custom/views/sale_order.xml | 2 + indoteknik_custom/views/uangmuka_penjualan.xml | 30 ++++++++++ 7 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 indoteknik_custom/models/account_payment.py create mode 100644 indoteknik_custom/models/uangmuka_penjualan.py create mode 100644 indoteknik_custom/views/uangmuka_penjualan.xml diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index 449fd09c..288927a9 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -40,6 +40,7 @@ 'views/x_product_tags.xml', 'views/stock_vendor.xml', 'views/crm_lead.xml', + 'views/uangmuka_penjualan.xml', 'views/sale_order.xml', 'views/account_asset_views.xml', 'views/ir_sequence.xml', 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 + } diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index d5142381..bbb73e7d 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -35,4 +35,5 @@ access_ip_lookup,access.ip.lookup,model_ip_lookup,,1,1,1,1 access_ip_lookup_line,access.ip.lookup.line,model_ip_lookup_line,,1,1,1,1 access_wati_notification,access.wati.notification,model_wati_notification,,1,1,1,1 access_user_company_request,access.user.company.request,model_user_company_request,,1,1,1,1 -access_res_partner_company_type,access.res.partner.company_type,model_res_partner_company_type,,1,1,1,1 \ No newline at end of file +access_res_partner_company_type,access.res.partner.company_type,model_res_partner_company_type,,1,1,1,1 +access_uangmuka_penjualan,access.uangmuka.penjualan,model_uangmuka_penjualan,,1,1,1,1 \ No newline at end of file diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index d6df24a0..3bdb705b 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -15,6 +15,8 @@ string="Ask Approval" type="object" /> + diff --git a/indoteknik_custom/views/uangmuka_penjualan.xml b/indoteknik_custom/views/uangmuka_penjualan.xml new file mode 100644 index 00000000..b2353f12 --- /dev/null +++ b/indoteknik_custom/views/uangmuka_penjualan.xml @@ -0,0 +1,30 @@ + + + + Uangmuka Penjualan + uangmuka.penjualan + +
+

+ Pembuatan semi otomatis Uang Muka Penjualan, mohon dicek kembali +

+ + + + +
+
+
+
+
+ + + Create Uang Muka Penjualan + ir.actions.act_window + uangmuka.penjualan + form + new + + +
-- cgit v1.2.3