From ede74761c8556b18b4555af22738a76538682512 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 11 Feb 2025 14:52:22 +0700 Subject: add CR cancel so >30jt --- indoteknik_custom/models/sale_order.py | 73 +++++++++++++++++++++++++- indoteknik_custom/security/ir.model.access.csv | 3 +- indoteknik_custom/views/sale_order.xml | 25 +++++++++ 3 files changed, 99 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 9631fe6e..b1039750 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -7,6 +7,44 @@ from collections import defaultdict _logger = logging.getLogger(__name__) +class CancelReasonOrder(models.TransientModel): + _name = 'cancel.reason.order' + _description = 'Wizard for Cancel Reason order' + + request_id = fields.Many2one('sale.order', string='Request') + reason_cancel = fields.Selection([ + ('harga_terlalu_mahal', 'Harga barang terlalu mahal'), + ('harga_web_tidak_valid', 'Harga web tidak valid'), + ('stok_kosong', 'Stock kosong'), + ('tidak_mau_indent', 'Customer tidak mau indent'), + ('batal_rencana_pembelian', 'Customer membatalkan rencana pembelian'), + ('vendor_tidak_support_demo', 'Vendor tidak support demo/trial product'), + ('product_knowledge_kurang', 'Product knowledge kurang baik'), + ('barang_tidak_sesuai', 'Barang tidak sesuai/tepat'), + ('tidak_sepakat_pembayaran', 'Tidak menemukan kesepakatan untuk pembayaran'), + ('dokumen_tidak_support', 'Indoteknik tidak bisa support document yang dibutuhkan (Ex: TKDN, COO, SNI)'), + ('ganti_quotation', 'Ganti Quotation'), + ('testing_internal', 'Testing Internal'), + ], string='Reason for Cancel', required=True, copy=False, index=True, tracking=3) + attachment_bukti = fields.Many2many( + 'ir.attachment', + string="Attachment Bukti", readonly=False, + tracking=3, required=True + ) + nomor_so_pengganti = fields.Char(string='Nomor SO Pengganti', copy=False, tracking=3) + + def confirm_reject(self): + order = self.request_id + if order: + order.write({'reason_cancel': self.reason_cancel}) + order.write({'attachment_bukti': self.attachment_bukti}) + order.message_post(body='Attachment Bukti Cancel', + attachment_ids=[self.attachment_bukti.id]) + if self.nomor_so_pengganti or self.reason_cancel == 'ganti_quotation': + order.write({'nomor_so_pengganti': self.nomor_so_pengganti}) + order.confirm_cancel_order() + + return {'type': 'ir.actions.act_window_close'} class SaleOrder(models.Model): _inherit = "sale.order" @@ -145,6 +183,25 @@ class SaleOrder(models.Model): ('NP', 'Non Pareto') ]) shipping_method_picking = fields.Char(string='Shipping Method Picking', compute='_compute_shipping_method_picking') + reason_cancel = fields.Selection([ + ('harga_terlalu_mahal', 'Harga barang terlalu mahal'), + ('harga_web_tidak_valid', 'Harga web tidak valid'), + ('stok_kosong', 'Stock kosong'), + ('tidak_mau_indent', 'Customer tidak mau indent'), + ('batal_rencana_pembelian', 'Customer membatalkan rencana pembelian'), + ('vendor_tidak_support_demo', 'Vendor tidak support demo/trial product'), + ('product_knowledge_kurang', 'Product knowledge kurang baik'), + ('barang_tidak_sesuai', 'Barang tidak sesuai/tepat'), + ('tidak_sepakat_pembayaran', 'Tidak menemukan kesepakatan untuk pembayaran'), + ('dokumen_tidak_support', 'Indoteknik tidak bisa support document yang dibutuhkan (Ex: TKDN, COO, SNI)'), + ('ganti_quotation', 'Ganti Quotation'), + ('testing_internal', 'Testing Internal'), + ], string='Reason for Cancel', copy=False, index=True, tracking=3) + attachment_bukti = fields.Many2one( + 'ir.attachment', + string="Attachment Bukti Cancel", readonly=False, + ) + nomor_so_pengganti = fields.Char(string='Nomor SO Pengganti', copy=False, tracking=3) def _compute_shipping_method_picking(self): for order in self: @@ -1085,8 +1142,22 @@ class SaleOrder(models.Model): self.due_id = False if main_parent.use_so_approval: self.send_notif_to_salesperson(cancel=True) + for order in self: + if order.amount_total > 30000000: + return { + 'type': 'ir.actions.act_window', + 'name': _('Cancel Reason'), + 'res_model': 'cancel.reason.order', + 'view_mode': 'form', + 'target': 'new', + 'context': {'default_request_id': self.id}, + } return super(SaleOrder, self).action_cancel() - + + def confirm_cancel_order(self): + """Fungsi ini akan dipanggil oleh wizard setelah alasan pembatalan dipilih""" + return super(SaleOrder, self).action_cancel() + def validate_partner_invoice_due(self): parent_id = self.partner_id.parent_id.id parent_id = parent_id if parent_id else self.partner_id.id diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index d4b79cd9..6709370f 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -161,4 +161,5 @@ access_reject_reason_wizard,reject.reason.wizard,model_reject_reason_wizard,,1,1 access_confirm_approval_wizard,confirm.approval.wizard,model_confirm_approval_wizard,,1,1,1,0 access_barcode_product,access.barcode.product,model_barcode_product,,1,1,1,1 access_barcoding_product,access.barcoding.product,model_barcoding_product,,1,1,1,1 -access_barcoding_product_line,access.barcoding.product.line,model_barcoding_product_line,,1,1,1,1 \ No newline at end of file +access_barcoding_product_line,access.barcoding.product.line,model_barcoding_product_line,,1,1,1,1 +access_cancel_reason_order,cancel.reason.order,model_cancel_reason_order,,1,1,1,0 diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index 2a46901a..daa2b095 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -283,6 +283,31 @@ + + + cancel.reason.order.form + cancel.reason.order + +
+ + + + + +
+
+
+
+
+ + + Cancel Reason + cancel.reason.order + form + new + -- cgit v1.2.3 From 7f284e263de51242459ca780af32fe0e372f7ac4 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Wed, 12 Feb 2025 15:02:14 +0700 Subject: update code --- indoteknik_custom/models/sale_order.py | 9 +++++++-- indoteknik_custom/views/sale_order.xml | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index b1039750..d0b72ed3 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -37,11 +37,16 @@ class CancelReasonOrder(models.TransientModel): order = self.request_id if order: order.write({'reason_cancel': self.reason_cancel}) + if not self.attachment_bukti: + raise UserError('Attachment bukti wajib disertakan') order.write({'attachment_bukti': self.attachment_bukti}) order.message_post(body='Attachment Bukti Cancel', attachment_ids=[self.attachment_bukti.id]) - if self.nomor_so_pengganti or self.reason_cancel == 'ganti_quotation': - order.write({'nomor_so_pengganti': self.nomor_so_pengganti}) + if self.reason_cancel == 'ganti_quotation': + if self.nomor_so_pengganti: + order.write({'nomor_so_pengganti': self.nomor_so_pengganti}) + else: + raise UserError('Nomor SO pengganti wajib disertakan') order.confirm_cancel_order() return {'type': 'ir.actions.act_window_close'} diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index daa2b095..163330c5 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -291,7 +291,7 @@
- +