From 57221d2537684168a4761ce2eb0b2ede5586325f Mon Sep 17 00:00:00 2001 From: Mqdd Date: Sat, 14 Feb 2026 12:02:15 +0700 Subject: fix flow approval state adjust out --- indoteknik_custom/models/stock_inventory.py | 44 +++++++++++++++++------------ indoteknik_custom/views/stock_inventory.xml | 7 ++--- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/indoteknik_custom/models/stock_inventory.py b/indoteknik_custom/models/stock_inventory.py index cb7d3773..b3580a4c 100644 --- a/indoteknik_custom/models/stock_inventory.py +++ b/indoteknik_custom/models/stock_inventory.py @@ -16,11 +16,35 @@ class StockInventory(models.Model): ('in', 'Adjusment In'), ('out', 'Adjusment Out'), ], string='Adjusments Type', required=True) + approval_state = fields.Selection([ ('logistic', 'Logistic'), ('accounting', 'Accounting'), ('approved', 'Approved'), - ], default='logistic', tracking=True) + ], default='logistic', tracking=True, readonly=True) + + def action_validate(self): + if self.adjusment_type == 'out': + + if self.approval_state != 'approved': + + if self.approval_state == 'logistic': + if not self.env.user.has_group('indoteknik_custom.group_role_logistic'): + raise UserError("Adjustment Out harus dilakukan oleh Logistic") + self.approval_state = 'accounting' + return True + + elif self.approval_state == 'accounting': + if not self.env.user.has_group('indoteknik_custom.group_role_fat'): + raise UserError("Adjustment Out harus dilakukan oleh Accounting") + self.approval_state = 'approved' + return True + + else: + raise UserError("Adjustment Out harus melalui approval terlebih dahulu.") + + return super(StockInventory, self).action_validate() + def _generate_number_stock_inventory(self): """Men-generate nomor untuk semua stock inventory yang belum memiliki number.""" @@ -58,10 +82,7 @@ class StockInventory(models.Model): return "00001" # Jika belum ada data, mulai dari 00001 def action_start(self): - if self.approval_state != 'approved' and self.adjusment_type == 'out': - raise UserError('Harus melalui proses approval') - if self.adjusment_type == 'in': - if self.env.user.id not in [21, 17, 571, 28]: + if self.env.user.id not in [21, 17, 571, 28, 25]: raise UserError("Hanya Rafly, Denise, Iqmal, dan Stephan yang bisa start inventory") return super(StockInventory, self).action_start() @@ -78,19 +99,6 @@ class StockInventory(models.Model): return order - def action_approve(self): - if self.adjusment_type == 'out': - for rec in self: - if rec.approval_state == 'logistic': - if not rec.env.user.has_group('indoteknik_custom.group_role_logistic'): - raise UserError("Harus diapprove logistic") - rec.approval_state = 'accounting' - elif rec.approval_state == 'accounting': - if not rec.env.user.has_group('indoteknik_custom.group_role_fat'): - raise UserError("Harus diapprove accounting") - rec.approval_state = 'approved' - else: - raise UserError("Sudah Approved") def write(self, vals): """Jika adjusment_type diubah, generate ulang nomor.""" diff --git a/indoteknik_custom/views/stock_inventory.xml b/indoteknik_custom/views/stock_inventory.xml index 89c058ea..ab1b6eec 100644 --- a/indoteknik_custom/views/stock_inventory.xml +++ b/indoteknik_custom/views/stock_inventory.xml @@ -6,14 +6,10 @@ stock.inventory -
-
- +
@@ -26,6 +22,7 @@ + -- cgit v1.2.3