From 0346d579b0db5969bf3a4e475cf8abb1b788cdd2 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 28 Jun 2024 13:37:44 +0700 Subject: multi create uang muka penjualan --- indoteknik_custom/__manifest__.py | 1 + indoteknik_custom/models/__init__.py | 1 + indoteknik_custom/models/sale_order.py | 7 ++ .../models/sale_order_multi_uangmuka_penjualan.py | 136 +++++++++++++++++++++ indoteknik_custom/security/ir.model.access.csv | 1 + indoteknik_custom/views/sale_order.xml | 10 ++ .../views/sale_order_multi_uangmuka_penjualan.xml | 36 ++++++ 7 files changed, 192 insertions(+) create mode 100644 indoteknik_custom/models/sale_order_multi_uangmuka_penjualan.py create mode 100644 indoteknik_custom/views/sale_order_multi_uangmuka_penjualan.xml diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index 9ffcd5ce..67f16800 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -134,6 +134,7 @@ 'views/purchase_order_multi_uangmuka2.xml', 'views/logbook_bill.xml', 'views/report_logbook_bill.xml', + 'views/sale_order_multi_uangmuka_penjualan.xml', 'report/report.xml', 'report/report_banner_banner.xml', 'report/report_banner_banner2.xml', diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index 510b8b9d..ffd1b645 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -119,3 +119,4 @@ from . import def_cargo from . import purchase_order_multi_uangmuka2 from . import logbook_bill from . import report_logbook_bill +from . import sale_order_multi_uangmuka_penjualan diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index efcbf606..ce54bc74 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -99,6 +99,13 @@ class SaleOrder(models.Model): compute_fullfillment = fields.Boolean(string='Compute Fullfillment', compute="_compute_fullfillment") note_ekspedisi = fields.Char(string="Note Ekspedisi") + def open_form_multi_create_uang_muka(self): + action = self.env['ir.actions.act_window']._for_xml_id('indoteknik_custom.action_sale_order_multi_uangmuka') + action['context'] = { + 'so_ids': [x.id for x in self] + } + return action + def _compute_fullfillment(self): for rec in self: rec.fullfillment_line.unlink() diff --git a/indoteknik_custom/models/sale_order_multi_uangmuka_penjualan.py b/indoteknik_custom/models/sale_order_multi_uangmuka_penjualan.py new file mode 100644 index 00000000..bf717a4f --- /dev/null +++ b/indoteknik_custom/models/sale_order_multi_uangmuka_penjualan.py @@ -0,0 +1,136 @@ +from odoo import fields, models, _, api +from odoo.exceptions import UserError +from datetime import datetime +from odoo.http import request + +import logging, math + +_logger = logging.getLogger(__name__) + + +class PurchaseOrderMultiUangmukaPenjualan(models.TransientModel): + _name = 'sale.order.multi_uangmuka_penjualan' + _description = 'digunakan untuk membuat Uang Muka Penjualan' + + pay_amt = fields.Float(string='Uang Muka', 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') + 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_uangmukapenjualanselected(self): + so_ids = self._context['so_ids'] + orders = self.env['sale.order'].browse(so_ids) + po_is_uangmuka = self.env['sale.order'].search([ + ('id', 'in', [x.id for x in orders]) + ]) + + if not self.account_id: + raise UserError('Bank Intransit harus diisi') + if not self.env.user.has_group('account.group_account_manager'): + raise UserError('Hanya Finance yang dapat membuat Uang Muka penjualan') + + current_time = datetime.now() + + 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 + + partner_name = orders[0].partner_id.name + if orders[0].partner_id.parent_id: + partner_name = orders[0].partner_id.parent_id.name + + order_names = ', '.join([data.name for data in orders]) # Menggabungkan nama order menjadi satu string + ref_label = f'UANG MUKA penjualan {order_names} {partner_name}' + param_header = { + 'ref': ref_label, + 'date': current_time, + 'journal_id': 11, + # 'sale_id': order.id, + } + + account_move = self.env['account.move'].create([param_header]) + debit_entries = [] + pay_amt = 0 + + + for order in orders: + _logger.info('Success Create Uang Muka penjualan %s' % account_move.name) + partner_id = order.partner_id.parent_id.id if order.partner_id.parent_id else order.partner_id.id + partner = order.partner_id.parent_id.name if order.partner_id.parent_id else order.partner_id.name + + param_credit = { + 'move_id': account_move.id, + 'account_id': 449, # uang muka penjualan + 'partner_id': partner_id, + 'currency_id': 12, + 'debit': 0, + 'credit': order.amount_total, + 'name': f'UANG MUKA PEMBELIAN {order.name} {partner}', + } + param_ongkir_credit = { + 'move_id': account_move.id, + 'account_id': 550, # pendapatan ongkos kirim + 'partner_id': partner_id, + 'currency_id': 12, + 'debit': 0, + 'credit': self.ongkir_amt, + 'name': f'UANG MUKA PEMBELIAN {order.name} {partner}', + } + param_selisih_credit = { + 'move_id': account_move.id, + 'account_id': 561, # selisih pembayaran + 'partner_id': partner_id, + 'currency_id': 12, + 'debit': 0, + 'credit': self.selisih_amt, + 'name': f'UANG MUKA PEMBELIAN {order.name} {partner}', + } + + debit_entries.append(param_credit) + pay_amt += order.amount_total + + if is_have_ongkir: + debit_entries.append(param_ongkir_credit) + pay_amt += self.ongkir_amt + + if is_have_selisih: + debit_entries.append(param_selisih_credit) + pay_amt += self.selisih_amt + + param_debit = { + 'move_id': account_move.id, + 'account_id': self.account_id.id, # intransit + 'partner_id': partner_id, + 'currency_id': 12, + 'debit': pay_amt, + 'credit': 0, + 'name': ref_label, + } + + debit_entries.append(param_debit) + + # Create all account.move.line entries at once + self.env['account.move.line'].create(debit_entries) + + 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 + } + + # def save_multi_create_uang_muka(self): + + # account_move = self.create_uangmukapenjualanselected(purchase, is_create_uangmuka) + \ No newline at end of file diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index d143c9e9..30bc7d06 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -127,3 +127,4 @@ access_logbook_bill_line,access.logbook.sj.line,model_logbook_bill_line,,1,1,1,1 access_report_logbook_bill,access.report.logbook.sj,model_report_logbook_bill,,1,1,1,1 access_report_logbook_bill_line,access.report.logbook.sj.line,model_report_logbook_bill_line,,1,1,1,1 access_report_logbook_bill_line,access.report.logbook.sj.line,model_report_logbook_bill_line,,1,1,1,1 +access_sale_order_multi_uangmuka_penjualan,access.sale.order.multi_uangmuka_penjualan,model_sale_order_multi_uangmuka_penjualan,,1,1,1,1 diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index 2ca4dcb3..b4c8b892 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -312,6 +312,16 @@ + + + Uang Muka + + + code + action = records.open_form_multi_create_uang_muka() + + + Sale Order: Notification to Salesperson diff --git a/indoteknik_custom/views/sale_order_multi_uangmuka_penjualan.xml b/indoteknik_custom/views/sale_order_multi_uangmuka_penjualan.xml new file mode 100644 index 00000000..a72aed87 --- /dev/null +++ b/indoteknik_custom/views/sale_order_multi_uangmuka_penjualan.xml @@ -0,0 +1,36 @@ + + + + + Sale Order Multi Create Uangmuka + sale.order.multi_uangmuka_penjualan + +
+

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

+ + + + + + + +
+
+
+
+
+ + + Sale Order Multi Create Uangmuka + sale.order.multi_uangmuka_penjualan + ir.actions.act_window + form + + new + +
+
\ No newline at end of file -- cgit v1.2.3