From 8ebc34a141841ed5d2c794c3b13b5db08ab673cf Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 20 Mar 2023 10:39:08 +0700 Subject: add info uang muka penjualan --- indoteknik_custom/models/invoice_reklas.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indoteknik_custom/models/invoice_reklas.py b/indoteknik_custom/models/invoice_reklas.py index 43736059..70469b72 100644 --- a/indoteknik_custom/models/invoice_reklas.py +++ b/indoteknik_custom/models/invoice_reklas.py @@ -46,7 +46,7 @@ class InvoiceReklas(models.TransientModel): if self.reklas_type == 'penjualan': parameter_debit = { 'move_id': account_move.id, - 'account_id': 449, + 'account_id': 449, # uang muka penjualan 'partner_id': invoice.partner_id.id, 'currency_id': 12, 'debit': self.pay_amt, -- cgit v1.2.3 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 From d8750844beed392c0dd3e588ea242be3c86f2be9 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 20 Mar 2023 11:43:50 +0700 Subject: process semi automatic for generate uang muka pembelian --- indoteknik_custom/__manifest__.py | 1 + indoteknik_custom/models/__init__.py | 1 + indoteknik_custom/models/uangmuka_pembelian.py | 65 ++++++++++++++++++++++++++ indoteknik_custom/security/ir.model.access.csv | 3 +- indoteknik_custom/views/purchase_order.xml | 2 + indoteknik_custom/views/uangmuka_pembelian.xml | 30 ++++++++++++ 6 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 indoteknik_custom/models/uangmuka_pembelian.py create mode 100644 indoteknik_custom/views/uangmuka_pembelian.xml diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index 288927a9..c4f0cce0 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -21,6 +21,7 @@ 'views/product_pricelist_item.xml', 'views/product_public_category.xml', 'views/product_template.xml', + 'views/uangmuka_pembelian.xml', 'views/purchase_order.xml', 'views/purchase_pricelist.xml', 'views/sale_monitoring.xml', 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 + } diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index bbb73e7d..4bfbd705 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -36,4 +36,5 @@ 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 -access_uangmuka_penjualan,access.uangmuka.penjualan,model_uangmuka_penjualan,,1,1,1,1 \ No newline at end of file +access_uangmuka_penjualan,access.uangmuka.penjualan,model_uangmuka_penjualan,,1,1,1,1 +access_uangmuka_pembelian,access.uangmuka.pembelian,model_uangmuka_pembelian,,1,1,1,1 \ No newline at end of file diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml index 3220c1da..fb85f4c1 100755 --- a/indoteknik_custom/views/purchase_order.xml +++ b/indoteknik_custom/views/purchase_order.xml @@ -25,6 +25,8 @@ string="Ask Approval" type="object" /> + diff --git a/indoteknik_custom/views/uangmuka_pembelian.xml b/indoteknik_custom/views/uangmuka_pembelian.xml new file mode 100644 index 00000000..6cd0bec5 --- /dev/null +++ b/indoteknik_custom/views/uangmuka_pembelian.xml @@ -0,0 +1,30 @@ + + + + Uangmuka Pembelian + uangmuka.pembelian + +
+

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

+ + + + +
+
+
+
+
+ + + Create Uang Muka Pembelian + ir.actions.act_window + uangmuka.pembelian + form + new + + +
-- cgit v1.2.3 From cdd6919af886ab6eba9daa32d10254c6f3e14101 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 20 Mar 2023 14:46:25 +0700 Subject: add ongkir and selisih in process uang muka penjualan --- indoteknik_custom/models/uangmuka_pembelian.py | 5 ++- indoteknik_custom/models/uangmuka_penjualan.py | 60 +++++++++++++++++++++++--- indoteknik_custom/views/uangmuka_penjualan.xml | 3 ++ 3 files changed, 60 insertions(+), 8 deletions(-) diff --git a/indoteknik_custom/models/uangmuka_pembelian.py b/indoteknik_custom/models/uangmuka_pembelian.py index 29d188d3..3d271117 100644 --- a/indoteknik_custom/models/uangmuka_pembelian.py +++ b/indoteknik_custom/models/uangmuka_pembelian.py @@ -27,8 +27,9 @@ class UangmukaPembelian(models.TransientModel): current_time = datetime.now() for order in orders: + ref_label = 'UANG MUKA PEMBELIAN '+order.name+' '+order.partner_id.name param_header = { - 'ref': 'UANG MUKA PEMBELIAN '+order.name+' '+order.partner_id.name, + 'ref': ref_label, 'date': current_time, 'journal_id': 11 } @@ -43,6 +44,7 @@ class UangmukaPembelian(models.TransientModel): 'currency_id': 12, 'debit': self.pay_amt, 'credit': 0, + 'name': ref_label, } param_credit = { @@ -52,6 +54,7 @@ class UangmukaPembelian(models.TransientModel): 'currency_id': 12, 'debit': 0, 'credit': self.pay_amt, + 'name': ref_label, } request.env['account.move.line'].create([param_debit, param_credit]) return { diff --git a/indoteknik_custom/models/uangmuka_penjualan.py b/indoteknik_custom/models/uangmuka_penjualan.py index 6c234369..406caa4e 100644 --- a/indoteknik_custom/models/uangmuka_penjualan.py +++ b/indoteknik_custom/models/uangmuka_penjualan.py @@ -1,9 +1,9 @@ -from odoo import fields, models, _ +from odoo import fields, models, _, api from odoo.exceptions import UserError from datetime import datetime from odoo.http import request -import logging +import logging, math _logger = logging.getLogger(__name__) @@ -14,7 +14,15 @@ class UangmukaPenjualan(models.TransientModel): 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') + ongkir_amt = fields.Float(string='Ongkir', help='masukan nilai yang akan menjadi Pendapatan Ongkos Kirim') + selisih_amt = fields.Float(string='Selisih', help='masukan nilai yang akan menjadi Selisih Pembayaran') + total_amt = fields.Float(string='Total', help='Total yang akan masuk di journal entries') + @api.onchange('pay_amt', 'ongkir_amt', 'selisih_amt') + def _compute_total_amt(self): + for o in self: + o.total_amt = o.pay_amt + o.ongkir_amt + o.selisih_amt + def create_uangmukapenjualan(self): if self.pay_amt <= 0: raise UserError('Payment Amount harus diisi') @@ -23,12 +31,22 @@ class UangmukaPenjualan(models.TransientModel): if not self.env.user.is_accounting: raise UserError('Hanya Finance yang dapat membuat Uang Muka Penjualan') + is_have_ongkir = is_have_selisih = False + + if self.ongkir_amt > 0: + is_have_ongkir = True + if not math.isclose(self.selisih_amt, 0): + is_have_selisih = True + # elif self.selisih_amt > 0: + # is_have_selisih = True + orders = self.env['sale.order'].browse(self._context.get('active_ids',[])) current_time = datetime.now() for order in orders: + ref_label = 'UANG MUKA PENJUALAN '+order.name+' '+order.partner_id.name param_header = { - 'ref': 'UANG MUKA PENJUALAN '+order.name+' '+order.partner_id.name, + 'ref': ref_label, 'date': current_time, 'journal_id': 11 } @@ -38,13 +56,14 @@ class UangmukaPenjualan(models.TransientModel): param_debit = { 'move_id': account_move.id, - 'account_id': self.account_id.id, + 'account_id': self.account_id.id, # intransit 'partner_id': order.partner_id.id, 'currency_id': 12, - 'debit': self.pay_amt, + 'debit': self.pay_amt + self.ongkir_amt + self.selisih_amt, 'credit': 0, + 'name': ref_label, } - + # sisa di credit untuk uang muka penjualan, diluar ongkir dan selisih param_credit = { 'move_id': account_move.id, 'account_id': 449, # uang muka penjualan @@ -52,8 +71,35 @@ class UangmukaPenjualan(models.TransientModel): 'currency_id': 12, 'debit': 0, 'credit': self.pay_amt, + 'name': ref_label, + } + param_ongkir_credit = { + 'move_id': account_move.id, + 'account_id': 550, # pendapatan ongkos kirim + 'partner_id': order.partner_id.id, + 'currency_id': 12, + 'debit': 0, + 'credit': self.ongkir_amt, + 'name': ref_label, + } + param_selisih_credit = { + 'move_id': account_move.id, + 'account_id': 561, # selisih pembayaran + 'partner_id': order.partner_id.id, + 'currency_id': 12, + 'debit': 0, + 'credit': self.selisih_amt, + 'name': ref_label, } - request.env['account.move.line'].create([param_debit, param_credit]) + + if is_have_ongkir and is_have_selisih: + request.env['account.move.line'].create([param_debit, param_credit, param_ongkir_credit, param_selisih_credit]) + elif is_have_ongkir: + request.env['account.move.line'].create([param_debit, param_credit, param_ongkir_credit]) + elif is_have_selisih: + request.env['account.move.line'].create([param_debit, param_credit, param_selisih_credit]) + else: + request.env['account.move.line'].create([param_debit, param_credit]) return { 'name': _('Journal Entries'), 'view_mode': 'form', diff --git a/indoteknik_custom/views/uangmuka_penjualan.xml b/indoteknik_custom/views/uangmuka_penjualan.xml index b2353f12..f2fc83bc 100644 --- a/indoteknik_custom/views/uangmuka_penjualan.xml +++ b/indoteknik_custom/views/uangmuka_penjualan.xml @@ -10,7 +10,10 @@

+ + +