diff options
| author | Miqdad <ahmadmiqdad27@gmail.com> | 2025-07-24 17:35:11 +0700 |
|---|---|---|
| committer | Miqdad <ahmadmiqdad27@gmail.com> | 2025-07-24 17:35:11 +0700 |
| commit | b8efc85091fe0af596872bffeb3cf6c78fe2beed (patch) | |
| tree | 2ca2037b60e8027ec4e1b374c1c16bb1682979a5 | |
| parent | 4d87e7317448dd7cc46d01e32ac2c953f02d72b1 (diff) | |
<miqdad> cant delete when done and in approval state
| -rw-r--r-- | indoteknik_custom/models/tukar_guling.py | 29 | ||||
| -rw-r--r-- | indoteknik_custom/models/tukar_guling_po.py | 17 |
2 files changed, 45 insertions, 1 deletions
diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py index c5ccad80..7253afb7 100644 --- a/indoteknik_custom/models/tukar_guling.py +++ b/indoteknik_custom/models/tukar_guling.py @@ -98,6 +98,8 @@ class TukarGuling(models.Model): @api.onchange('operations') def _onchange_operations(self): """Auto-populate lines ketika operations dipilih""" + if self.operations.picking_type_id.id not in [29,30]: + raise UserError("❌ Picking type harus BU/OUT atau BU/PICK") for rec in self: if rec.operations and rec.operations.picking_type_id.id == 30: rec.return_type = 'revisi_so' @@ -343,6 +345,8 @@ class TukarGuling(models.Model): def write(self, vals): self.ensure_one() + if self.operations.picking_type_id.id not in [29,30]: + raise UserError("❌ Picking type harus BU/OUT atau BU/PICK") self._check_invoice_on_revisi_so() operasi = self.operations.picking_type_id.id tipe = self.return_type @@ -756,6 +760,18 @@ class TukarGulingLine(models.Model): product_uom = fields.Many2one('uom.uom', string='Unit of Measure') name = fields.Text('Description') + @api.constrains('product_uom_qty') + def _check_qty_change_allowed(self): + for rec in self: + if rec.tukar_guling_id and rec.tukar_guling_id.state not in ['draft', 'cancel']: + raise ValidationError("Tidak bisa mengubah Quantity karena status dokumen bukan Draft atau Cancel.") + + def unlink(self): + for rec in self: + if rec.tukar_guling_id and rec.tukar_guling_id.state not in ['draft', 'cancel']: + raise UserError("Tidak bisa menghapus data karena status dokumen bukan Draft atau Cancel.") + return super(TukarGulingLine, self).unlink() + @api.model_create_multi def create(self, vals_list): """Override create to auto-assign sequence""" @@ -813,4 +829,15 @@ class TukarGulingMappingKoli(models.Model): product_id = fields.Many2one('product.product', string='Product') qty_done = fields.Float(string='Qty Done BU PICK') qty_return = fields.Float(string='Qty diretur') - sequence = fields.Integer(string='Sequence', default=10)
\ No newline at end of file + sequence = fields.Integer(string='Sequence', default=10) + @api.constrains('qty_return') + def _check_qty_return_editable(self): + for rec in self: + if rec.tukar_guling_id and rec.tukar_guling_id.state not in ['draft', 'cancel']: + raise ValidationError("Tidak Bisa ubah qty retur jika status sudah approval atau done.") + + def unlink(self): + for rec in self: + if rec.tukar_guling_id and rec.tukar_guling_id.state not in ['draft', 'cancel']: + raise UserError("Tidak bisa menghapus Mapping Koli karena status Tukar Guling bukan Draft atau Cancel.") + return super(TukarGulingMappingKoli, self).unlink()
\ No newline at end of file diff --git a/indoteknik_custom/models/tukar_guling_po.py b/indoteknik_custom/models/tukar_guling_po.py index b3279077..7c9680f8 100644 --- a/indoteknik_custom/models/tukar_guling_po.py +++ b/indoteknik_custom/models/tukar_guling_po.py @@ -90,6 +90,9 @@ class TukarGulingPO(models.Model): @api.onchange('operations') def _onchange_operations(self): """Auto-populate lines ketika operations dipilih""" + if self.operations.picking_type_id.id not in [75, 28]: + raise UserError("❌ Picking type harus BU/INPUT atau BU/PUT") + if self.operations: from_return_picking = self.env.context.get('from_return_picking', False) or \ self.env.context.get('default_line_ids', False) @@ -275,6 +278,8 @@ class TukarGulingPO(models.Model): return new_record def write(self, vals): + if self.operations.picking_type_id.id not in [75, 28]: + raise UserError("❌ Tidak bisa retur bukan BU/INPUT atau BU/PUT!") self._check_bill_on_revisi_po() tipe = vals.get('return_type', self.return_type) @@ -621,6 +626,18 @@ class TukarGulingLinePO(models.Model): product_uom = fields.Many2one('uom.uom', string='Unit of Measure') name = fields.Text('Description') + @api.constrains('product_uom_qty') + def _check_qty_change_allowed(self): + for rec in self: + if rec.tukar_guling_id and rec.tukar_guling_po_id.state not in ['draft', 'cancel']: + raise ValidationError("Tidak bisa mengubah Quantity karena status dokumen bukan Draft atau Cancel.") + + def unlink(self): + for rec in self: + if rec.tukar_guling_po_id and rec.tukar_guling_po_id.state not in ['draft', 'cancel']: + raise UserError("Tidak bisa menghapus data karena status dokumen bukan Draft atau Cancel.") + return super(TukarGulingLinePO, self).unlink() + class StockPicking(models.Model): _inherit = 'stock.picking' |
