diff options
| author | Mqdd <ahmadmiqdad27@gmail.com> | 2025-11-27 17:11:37 +0700 |
|---|---|---|
| committer | Mqdd <ahmadmiqdad27@gmail.com> | 2025-11-27 17:11:37 +0700 |
| commit | 6439ce89ae7c89663d61aed0abb5affc7fb75d23 (patch) | |
| tree | 122f8fe0a3753a695e3f9a443050e967f785e809 | |
| parent | 6c43ee02300fbeee3a838a1d2d4b145096fa7df8 (diff) | |
<Miqdad> urutan validate picking vcm
| -rw-r--r-- | indoteknik_custom/models/stock_picking.py | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 1a5239d7..fbcddc5a 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -1416,6 +1416,37 @@ 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') + if self.tukar_guling_po_id: + for po in self.tukar_guling_po_id: + pickings = po.picking_ids.filtered(lambda p: p.return_type == 'tukar_guling') + + # Buat mapping picking berdasarkan prefix + picking_map = { + 'BU/VRT': None, + 'BU/PRT': None, + 'BU/INPUT': None, + 'BU/PUT': None, + } + + for picking in pickings: + for prefix in picking_map: + if picking.name.startswith(prefix): + picking_map[prefix] = picking + + # Cek apakah keempat jenis picking tersedia + missing = [key for key, val in picking_map.items() if val is None] + if missing: + raise UserError(f"Picking untuk tukar guling tidak lengkap: {', '.join(missing)}") + + # Cek urutan sesuai aturan: VRT -> PRT -> INPUT -> PUT + ordered_pickings = [picking_map['BU/VRT'], picking_map['BU/PRT'], picking_map['BU/INPUT'], picking_map['BU/PUT']] + done_pickings = [p for p in ordered_pickings if p.state == 'done'] + + for i, picking in enumerate(done_pickings): + expected = ordered_pickings[i] + if picking != expected: + raise UserError("Urutan validasi picking tukar guling tidak sesuai. Harus mengikuti urutan: BU/VRT → BU/PRT → BU/INPUT → BU/PUT") + 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 +2852,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) |
