diff options
Diffstat (limited to 'fixco_custom/models/stock_inventory.py')
| -rw-r--r-- | fixco_custom/models/stock_inventory.py | 55 |
1 files changed, 35 insertions, 20 deletions
diff --git a/fixco_custom/models/stock_inventory.py b/fixco_custom/models/stock_inventory.py index 1a8f3b0..37104ff 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,45 +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: + if record.adjusment_type == 'in': + record.approval_state = False + elif record.adjusment_type == 'out' and record.approval_state == False: + record.approval_state = 'logistic' self._assign_number(record) return res |
