From baaaa901391b4cd6956cb28aff992735e84962e4 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Fri, 3 Oct 2025 19:38:57 +0700 Subject: CR BU/IU Approval flow --- indoteknik_custom/models/stock_picking.py | 46 +++++++++++++++++++++++-------- indoteknik_custom/views/stock_picking.xml | 10 +++++++ 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index ae7121da..eea87926 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -176,6 +176,28 @@ class StockPicking(models.Model): linked_manual_bu_out = fields.Many2one('stock.picking', string='BU Out', copy=False) area_name = fields.Char(string="Area", compute="_compute_area_name") + is_bu_iu = fields.Boolean('Is BU/IU', compute='_compute_is_bu_iu', default=False, copy=False, readonl=True) + + @api.depends('name') + def _compute_is_bu_iu(self): + for record in self: + if 'BU/IU' in record.name: + record.is_bu_iu = True + else: + record.is_bu_iu = False + + def action_bu_iu_to_pengajuan2(self): + for rec in self: + if not rec.is_bu_iu or not rec.is_internal_use: + raise UserError(_("Tombol ini hanya untuk dokumen BU/IU - Internal Use.")) + if rec.approval_status == False: + raise UserError("Harus Ask Approval terlebih dahulu") + if rec.approval_status in ['pengajuan1'] and self.env.user.is_accounting: + rec.approval_status = 'pengajuan2' + # raise UserError(_("Hanya bisa dijalankan saat status di 'pengajuan1'.")) + rec.message_post(body=_("Status naik ke Approval Logistik oleh %s") % self.env.user.display_name) + + return True # def _get_biteship_api_key(self): # # return self.env['ir.config_parameter'].sudo().get_param('biteship.api_key_test') @@ -1082,9 +1104,12 @@ class StockPicking(models.Model): def ask_approval(self): - if self.env.user.is_accounting: - raise UserError("Bisa langsung Validate") - if self.env.user.is_logistic_approver and self.location_id.id == 57 or self.location_id== 57: + # if self.env.user.is_accounting: + # if self.env.user.is_accounting and self.location_id.id == 57 or self.location_id == 57 and self.approval_status in ['pengajuan1', ''] and 'BU/IU' in self.name and self.approval_status == 'pengajuan1': + # raise UserError("Bisa langsung set ke approval logistik") + if self.env.user.is_accounting and self.approval_status == "pengajuan2" and 'BU/IU' in self.name: + raise UserError("Tidak perlu ask approval sudah approval logistik") + if self.env.user.is_logistic_approver and self.location_id.id == 57 or self.location_id== 57 and self.approval_status == 'pengajuan2' and 'BU/IU' in self.name: raise UserError("Bisa langsung Validate") @@ -1110,9 +1135,7 @@ class StockPicking(models.Model): if line.qty_done <= 0: raise UserError("Qty tidak boleh 0") pick.approval_status = 'pengajuan1' - if pick.location_id.id == 57: - pick.approval_status = 'pengajuan2' - return + def ask_receipt_approval(self): if self.env.user.is_logistic_approver: @@ -1315,10 +1338,10 @@ class StockPicking(models.Model): if self.picking_type_id.code == 'incoming' and self.group_id.id == False and self.is_internal_use == False: raise UserError(_('Tidak bisa Validate jika tidak dari Document SO / PO')) - if self.is_internal_use and not self.env.user.is_logistic_approver and self.location_id.id == 57: + if self.is_internal_use and not self.env.user.is_logistic_approver and self.location_id.id == 57 and self.approval_status == 'pengajuan2': raise UserError("Harus di Approve oleh Logistik") - if self.is_internal_use and not self.env.user.is_accounting: + if self.is_internal_use and not self.env.user.is_accounting and self.approval_status == 'pengajuan1' and self.location_id.id == 57: raise UserError("Harus di Approve oleh Accounting") if self.picking_type_id.id == 28 and not self.env.user.is_logistic_approver: @@ -1327,8 +1350,10 @@ class StockPicking(models.Model): if self.location_dest_id.id == 47 and not self.env.user.is_purchasing_manager: raise UserError("Transfer ke gudang selisih harus di approve Rafly Hanggara") - if self.is_internal_use: + if self.is_internal_use and self.approval_status == 'pengajuan2': self.approval_status = 'approved' + elif self.is_internal_use and self.approval_status in ['pengajuan1', '', False]: + raise UserError("Tidak Bisa Validate, set approval status ke approval logistik terlebih dahhulu") elif self.picking_type_id.code == 'incoming': self.approval_receipt_status = 'approved' @@ -1360,9 +1385,6 @@ class StockPicking(models.Model): ) self.validation_minus_onhand_quantity() - loc = self.location_id - if loc.id == 57 and not self.env.user.is_logistic_approver and self.approval_status in ['pengajuan2']: - raise UserError ("Harus Ask Approval Logistik") self.responsible = self.env.user.id # self.send_koli_to_so() if self.picking_type_code == 'outgoing' and 'BU/OUT/' in self.name: diff --git a/indoteknik_custom/views/stock_picking.xml b/indoteknik_custom/views/stock_picking.xml index 21762202..7f0865f4 100644 --- a/indoteknik_custom/views/stock_picking.xml +++ b/indoteknik_custom/views/stock_picking.xml @@ -45,6 +45,14 @@ stock.picking + + +