From f24d7fc1c60fb0198dbb62f7ba996912ce9f2b9d Mon Sep 17 00:00:00 2001 From: Mqdd Date: Sun, 15 Feb 2026 17:29:54 +0700 Subject: fix flow adjusment out --- fixco_custom/models/stock_inventory.py | 56 +++++++++++++++++++++------------- fixco_custom/views/stock_inventory.xml | 4 --- 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/fixco_custom/models/stock_inventory.py b/fixco_custom/models/stock_inventory.py index 1a8f3b0..e507af5 100644 --- a/fixco_custom/models/stock_inventory.py +++ b/fixco_custom/models/stock_inventory.py @@ -20,7 +20,7 @@ class StockInventory(models.Model): ('logistic', 'Logistic'), ('accounting', 'Accounting'), ('approved', 'Approved'), - ], default='logistic', tracking=True) + ], tracking=True) def _generate_number_stock_inventory(self): """Men-generate nomor untuk semua stock inventory yang belum memiliki number.""" @@ -58,46 +58,60 @@ 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 [10, 14, 20, 21]: - raise UserError("Hanya User tertentu yang dapat melakukan Adjust-In") + if self.env.user.id not in [10, 14, 20, 21, 15]: + raise UserError("Hanya User tertentu yang dapat melakukan Adjust-In/Out") return super(StockInventory, self).action_start() @api.model def create(self, vals): """Pastikan nomor hanya dibuat saat penyimpanan.""" + + if vals.get('adjusment_type') == 'in': + vals['approval_state'] = False + elif vals.get('adjusment_type') == 'out': + vals['approval_state'] = 'logistic' + if 'adjusment_type' in vals and not vals.get('number'): - vals['number'] = False # Jangan buat number otomatis dulu + vals['number'] = False order = super(StockInventory, self).create(vals) if order.adjusment_type: - self._assign_number(order) # Generate number setelah save + self._assign_number(order) return order - - def action_approve(self): + + def action_validate(self): if self.adjusment_type == 'out': - for rec in self: - if rec.approval_state == 'logistic': - if not rec.env.user.id in [10, 14, 20, 21]: - raise UserError("Harus diapprove logistic") - rec.approval_state = 'accounting' - elif rec.approval_state == 'accounting': - if not rec.env.user.id in [13, 24, 2]: - raise UserError("Harus diapprove accounting") - rec.approval_state = 'approved' + + if self.approval_state != 'approved': + + if self.approval_state == 'logistic': + if not self.env.user.id in [10, 14, 20, 21]: + raise UserError("Adjustment Out harus diapprove oleh Logistic") + self.approval_state = 'accounting' + return True + + elif self.approval_state == 'accounting': + if not self.env.user.id in [13, 24, 2]: + raise UserError("Adjustment Out harus diapprove oleh Accounting") + self.approval_state = 'approved' + return super(StockInventory, self).action_validate() + else: - raise UserError("Sudah Approved") + raise UserError("Adjustment Out harus melalui approval terlebih dahulu.") + + return super(StockInventory, self).action_validate() def write(self, vals): """Jika adjusment_type diubah, generate ulang nomor.""" res = super(StockInventory, self).write(vals) if 'adjusment_type' in vals: for record in self: - self._assign_number(record) + if record.adjusment_type == 'in': + record.approval_state = False + elif record.adjusment_type == 'out' and record.approval_state == False: + record.approval_state = 'logistic' return res def copy(self, default=None): diff --git a/fixco_custom/views/stock_inventory.xml b/fixco_custom/views/stock_inventory.xml index 89c058e..a343db3 100644 --- a/fixco_custom/views/stock_inventory.xml +++ b/fixco_custom/views/stock_inventory.xml @@ -6,10 +6,6 @@ stock.inventory -
-
-- cgit v1.2.3