summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/stock_inventory.py
diff options
context:
space:
mode:
Diffstat (limited to 'indoteknik_custom/models/stock_inventory.py')
-rw-r--r--indoteknik_custom/models/stock_inventory.py44
1 files changed, 42 insertions, 2 deletions
diff --git a/indoteknik_custom/models/stock_inventory.py b/indoteknik_custom/models/stock_inventory.py
index 84eb5a17..efd52e5c 100644
--- a/indoteknik_custom/models/stock_inventory.py
+++ b/indoteknik_custom/models/stock_inventory.py
@@ -17,6 +17,35 @@ class StockInventory(models.Model):
('out', 'Adjusment Out'),
], string='Adjusments Type', required=True)
+ approval_state = fields.Selection([
+ ('logistic', 'Logistic'),
+ ('accounting', 'Accounting'),
+ ('approved', 'Approved'),
+ ], 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 super(StockInventory, self).action_validate()
+
+ 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."""
stock_records = self.env['stock.inventory'].search([('number', '=', False)], order='id asc')
@@ -53,13 +82,19 @@ class StockInventory(models.Model):
return "00001" # Jika belum ada data, mulai dari 00001
def action_start(self):
- if self.env.user.id not in [21, 17, 571, 28]:
- raise UserError("Hanya Rafly, Denise, Iqmal, dan Stephan yang bisa start inventory")
+ 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()
@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
@@ -69,12 +104,17 @@ class StockInventory(models.Model):
self._assign_number(order) # Generate number setelah save
return order
+
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