diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2024-06-12 11:12:30 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2024-06-12 11:12:30 +0700 |
| commit | e035d5ce7097daf04fbe289298a5950108a54002 (patch) | |
| tree | 9be9d95785146e2669be8f00b0b59d3d192b309b | |
| parent | 2c7c774119f47025d1577cfa6b8c88e3cc5a0607 (diff) | |
function multi create uangmuka pembelian on po
| -rwxr-xr-x | indoteknik_custom/__manifest__.py | 1 | ||||
| -rwxr-xr-x | indoteknik_custom/models/__init__.py | 2 | ||||
| -rwxr-xr-x | indoteknik_custom/models/purchase_order.py | 8 | ||||
| -rw-r--r-- | indoteknik_custom/models/purchase_order_multi_uangmuka.py | 131 | ||||
| -rwxr-xr-x | indoteknik_custom/security/ir.model.access.csv | 1 | ||||
| -rwxr-xr-x | indoteknik_custom/views/purchase_order.xml | 9 | ||||
| -rw-r--r-- | indoteknik_custom/views/purchase_order_multi_uangmuka.xml | 36 |
7 files changed, 186 insertions, 2 deletions
diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index 3d2b01e5..1d8e3533 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -129,6 +129,7 @@ 'views/def_cargo_province.xml', 'views/def_cargo_city.xml', 'views/def_cargo_district.xml', + 'views/purchase_order_multi_uangmuka.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 510dd659..13d8f0b4 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -106,7 +106,7 @@ from . import po_multi_cancel from . import logbook_sj from . import report_logbook_sj from . import role_permission - +from . import purchase_order_multi_uangmuka from . import cust_commision from . import report_stock_forecasted from . import web_logging diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 3a959391..8bef8274 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -116,6 +116,13 @@ class PurchaseOrder(models.Model): } return action + def open_form_multi_create_uang_muka(self): + action = self.env['ir.actions.act_window']._for_xml_id('indoteknik_custom.action_purchase_order_multi_uangmuka') + action['context'] = { + 'po_ids': [x.id for x in self] + } + return action + def action_multi_update_paid_status(self): for purchase in self: purchase.update({ @@ -401,7 +408,6 @@ class PurchaseOrder(models.Model): if purchasing_job_state: for purchasing_job in purchasing_job_state: purchasing_job.unlink() - def _send_po_not_sync(self): diff --git a/indoteknik_custom/models/purchase_order_multi_uangmuka.py b/indoteknik_custom/models/purchase_order_multi_uangmuka.py new file mode 100644 index 00000000..eae92b67 --- /dev/null +++ b/indoteknik_custom/models/purchase_order_multi_uangmuka.py @@ -0,0 +1,131 @@ +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 PurchaseOrderMultiUangmuka(models.TransientModel): + _name = 'purchase.order.multi_uangmuka' + _description = 'digunakan untuk membuat Uang Muka Pembelian' + + 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_uangmukapembelian(self, orders): + 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.has_group('account.group_account_manager'): + raise UserError('Hanya Finance yang dapat membuat Uang Muka Pembelian') + + 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 = ', '.join([rec.partner_id.name for rec in orders]) + if any(rec.partner_id.parent_id for rec in orders): + partner_name = ', '.join([rec.partner_id.parent_id.name for rec in orders]) + + order_names = ', '.join([data.name for data in orders]) # Menggabungkan nama order menjadi satu string + ref_label = f'UANG MUKA PEMBELIAN {order_names} {partner_name}' + param_header = { + 'ref': ref_label, + 'date': current_time, + 'journal_id': 11 + } + + account_move = self.env['account.move'].create([param_header]) + debit_entries = [] + pay_amt = 0 + + for order in orders: + _logger.info('Success Create Uang Muka Pembelian %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_debit = { + 'move_id': account_move.id, + 'account_id': 401, # uang muka persediaan barang dagang + 'partner_id': partner_id, + 'currency_id': 12, + 'debit': self.pay_amt, + 'credit': 0, + 'name': f'UANG MUKA PEMBELIAN {order.name} {partner}', + } + param_debit_ongkir = { + 'move_id': account_move.id, + 'account_id': 536, # biaya ongkos kirim + 'partner_id': partner_id, + 'currency_id': 12, + 'debit': self.ongkir_amt, + 'credit': 0, + 'name': f'UANG MUKA PEMBELIAN {order.name} {partner}', + } + param_debit_selisih = { + 'move_id': account_move.id, + 'account_id': 561, # selisih pembayaran + 'partner_id': partner_id, + 'currency_id': 12, + 'debit': self.selisih_amt, + 'credit': 0, + 'name': f'UANG MUKA PEMBELIAN {order.name} {partner}', + } + + debit_entries.append(param_debit) + pay_amt += self.pay_amt + + if is_have_ongkir: + debit_entries.append(param_debit_ongkir) + pay_amt += self.ongkir_amt + + if is_have_selisih: + debit_entries.append(param_debit_selisih) + pay_amt += self.selisih_amt + + param_credit = { + 'move_id': account_move.id, + 'account_id': self.account_id.id, # bank in transit + 'partner_id': partner_id, + 'currency_id': 12, + 'debit': 0, + 'credit': pay_amt, + 'name': f'UANG MUKA PEMBELIAN {order.name} {partner}', + } + + debit_entries.append(param_credit) + + # Create all account.move.line entries at once + self.env['account.move.line'].create(debit_entries) + + return account_move.id + + def save_multi_create_uang_muka(self): + po_ids = self._context['po_ids'] + purchase = self.env['purchase.order'].browse(po_ids) + account_move = self.create_uangmukapembelian(purchase) + 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 + }
\ 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 744ce1c7..a5e8d8f9 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -120,3 +120,4 @@ access_account_move_multi_update_bills,access.account.move.multi_update_bills,mo access_def_cargo_province,access.def.cargo.province,model_def_cargo_province,,1,1,1,1 access_def_cargo_city,access.def.cargo.city,model_def_cargo_city,,1,1,1,1 access_def_cargo_district,access.def.cargo.district,model_def_cargo_district,,1,1,1,1 +access_purchase_order_multi_uangmuka,access.purchase.order.multi_uangmuka,model_purchase_order_multi_uangmuka,,1,1,1,1 diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml index bb38715e..47dc7a15 100755 --- a/indoteknik_custom/views/purchase_order.xml +++ b/indoteknik_custom/views/purchase_order.xml @@ -247,6 +247,15 @@ </record> </data> <data> + <record id="purchase_order_multi_create_uangmuka_ir_actions_server" model="ir.actions.server"> + <field name="name">Uang Muka</field> + <field name="model_id" ref="purchase.model_purchase_order"/> + <field name="binding_model_id" ref="purchase.model_purchase_order"/> + <field name="state">code</field> + <field name="code">action = records.open_form_multi_create_uang_muka()</field> + </record> + </data> + <data> <record id="purchase_order_multi_cancel_ir_actions_server" model="ir.actions.server"> <field name="name">Cancel PO</field> <field name="model_id" ref="purchase.model_purchase_order"/> diff --git a/indoteknik_custom/views/purchase_order_multi_uangmuka.xml b/indoteknik_custom/views/purchase_order_multi_uangmuka.xml new file mode 100644 index 00000000..68290cfa --- /dev/null +++ b/indoteknik_custom/views/purchase_order_multi_uangmuka.xml @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<odoo> + <data> + <record id="view_purchase_order_multi_create_uangmuka_form" model="ir.ui.view"> + <field name="name">Purchase Order Multi Create Uangmuka</field> + <field name="model">purchase.order.multi_uangmuka</field> + <field name="arch" type="xml"> + <form string="Invoice Sales Order"> + <p class="oe_grey"> + Pembuatan semi otomatis Uang Muka Pembelian, mohon dicek kembali + </p> + <group> + <field name="pay_amt"/> + <field name="ongkir_amt"/> + <field name="selisih_amt"/> + <field name="account_id" domain="[('name', 'ilike', 'intransit')]"/> + <field name="total_amt" readonly="1"/> + </group> + <footer> + <button name="save_multi_create_uang_muka" string="Update Paid Status" type="object" default_focus="1" class="oe_highlight"/> + <button string="Cancel" class="btn btn-secondary" special="cancel" /> + </footer> + </form> + </field> + </record> + + <record id="action_purchase_order_multi_uangmuka" model="ir.actions.act_window"> + <field name="name">Purchase Order Multi Create Uangmuka</field> + <field name="res_model">purchase.order.multi_uangmuka</field> + <field name="type">ir.actions.act_window</field> + <field name="view_mode">form</field> + <field name="view_id" ref="view_purchase_order_multi_create_uangmuka_form"/> + <field name="target">new</field> + </record> + </data> +</odoo>
\ No newline at end of file |
