summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2025-11-28 02:49:15 +0000
committerIT Fixcomart <it@fixcomart.co.id>2025-11-28 02:49:15 +0000
commitff09d1f3a975dbb28df91769ea04a4e5cbbdd615 (patch)
tree27c7085c18038f432a3639a297219f36fc7815a9
parent6c43ee02300fbeee3a838a1d2d4b145096fa7df8 (diff)
parent15717173d3774635bdb3838fb0b37cee91e0dcd5 (diff)
Merged in fix_validate_ccm (pull request #470)
Fix validate vcm
-rw-r--r--indoteknik_custom/models/stock_picking.py44
1 files changed, 43 insertions, 1 deletions
diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py
index 1a5239d7..900529b9 100644
--- a/indoteknik_custom/models/stock_picking.py
+++ b/indoteknik_custom/models/stock_picking.py
@@ -1406,6 +1406,47 @@ class StockPicking(models.Model):
else:
raise UserError('Hanya MD yang bisa Approve')
+ def validate_seq_vcm(self):
+ for picking in self:
+ tg_po = picking.tukar_guling_po_id
+ if not tg_po:
+ continue
+
+ return_type = tg_po.return_type
+ if return_type not in ['retur_po', 'tukar_guling']:
+ continue
+
+ picking_order = []
+ if return_type == 'retur_po':
+ picking_order = ['BU/INPUT', 'BU/PUT']
+ elif return_type == 'tukar_guling':
+ picking_order = ['BU/VRT', 'BU/PRT', 'BU/INPUT', 'BU/PUT']
+
+ related_pickings = self.env['stock.picking'].search([
+ ('tukar_guling_po_id', '=', tg_po.id)
+ ])
+
+ ordered_pickings = []
+ for prefix in picking_order:
+ match = next((p for p in related_pickings if p.name.startswith(prefix)), None)
+ if not match:
+ raise UserError(f"Picking dengan prefix {prefix} belum ada.")
+ ordered_pickings.append(match)
+
+ current_index = -1
+ for idx, p in enumerate(ordered_pickings):
+ if p.id == picking.id:
+ current_index = idx
+ break
+
+ if current_index == -1:
+ raise UserError("Picking ini tidak ditemukan dalam urutan picking yang sesuai.")
+
+ for prev_picking in ordered_pickings[:current_index]:
+ if prev_picking.state != 'done':
+ raise UserError(
+ f"Tidak bisa validasi {picking.name} sebelum {prev_picking.name} divalidasi."
+ )
def button_validate(self):
self.check_invoice_date()
_logger.info("Kode Picking: %s", self.picking_type_id.code)
@@ -1416,6 +1457,7 @@ class StockPicking(models.Model):
group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id
users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])])
active_model = self.env.context.get('active_model')
+ self.validate_seq_vcm()
if self.is_so_fiktif == True:
raise UserError("SO Fiktif tidak bisa di validate")
if self.location_id.id == 47 and self.env.user.id not in users_in_group.mapped(
@@ -2821,4 +2863,4 @@ class StockPickingSjDocument(models.Model):
picking_id = fields.Many2one('stock.picking', required=True, ondelete='cascade')
image = fields.Binary('Gambar', required=True, attachment=True)
- sequence = fields.Integer('Urutan', default=10) \ No newline at end of file
+ sequence = fields.Integer('Urutan', default=10)