diff options
| -rw-r--r-- | indoteknik_custom/models/stock_inventory.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/indoteknik_custom/models/stock_inventory.py b/indoteknik_custom/models/stock_inventory.py index b3580a4c..efd52e5c 100644 --- a/indoteknik_custom/models/stock_inventory.py +++ b/indoteknik_custom/models/stock_inventory.py @@ -21,7 +21,7 @@ class StockInventory(models.Model): ('logistic', 'Logistic'), ('accounting', 'Accounting'), ('approved', 'Approved'), - ], default='logistic', tracking=True, readonly=True) + ], tracking=True, readonly=True) def action_validate(self): if self.adjusment_type == 'out': @@ -38,7 +38,7 @@ class StockInventory(models.Model): 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 + return super(StockInventory, self).action_validate() else: raise UserError("Adjustment Out harus melalui approval terlebih dahulu.") @@ -89,6 +89,12 @@ class StockInventory(models.Model): @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 @@ -105,6 +111,10 @@ class StockInventory(models.Model): 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 |
