diff options
| author | FIN-IT_AndriFP <andrifebriyadiputra@gmail.com> | 2025-12-03 09:35:16 +0700 |
|---|---|---|
| committer | FIN-IT_AndriFP <andrifebriyadiputra@gmail.com> | 2025-12-03 09:35:16 +0700 |
| commit | a6ce141542392888f8191e0e0dd4ccd6abf1b334 (patch) | |
| tree | 342e368823dcce3f83297c9cd359244ede337709 /indoteknik_custom/models/stock_picking.py | |
| parent | 0a5376fe987ca2a6656d9b63c52b939c33150a21 (diff) | |
| parent | 015269c0268f2cd9a38ad708c8e26bf85a79fcf3 (diff) | |
Merge branch 'odoo-backup' of https://bitbucket.org/altafixco/indoteknik-addons into odoo-backup
Diffstat (limited to 'indoteknik_custom/models/stock_picking.py')
| -rw-r--r-- | indoteknik_custom/models/stock_picking.py | 48 |
1 files changed, 45 insertions, 3 deletions
diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index e7686b75..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( @@ -1453,10 +1495,10 @@ class StockPicking(models.Model): if not self.linked_manual_bu_out and 'BU/PICK/' in self.name: raise UserError(_("Isi BU Out terlebih dahulu!")) - if len(self.check_product_lines) == 0 and 'BU/PICK/' in self.name: + if len(self.check_product_lines) == 0 and 'BU/PICK/' in self.name and not self.env.user.has_group('indoteknik_custom.group_role_it'): raise UserError(_("Tidak ada Check Product! Harap periksa kembali.")) - if len(self.check_product_lines) == 0 and 'BU/INPUT/' in self.name: + if len(self.check_product_lines) == 0 and 'BU/INPUT/' in self.name and not self.env.user.has_group('indoteknik_custom.group_role_it'): raise UserError(_("Tidak ada Check Product! Harap periksa kembali.")) if self.total_koli > self.total_so_koli: @@ -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) |
