diff options
| author | Miqdad <ahmadmiqdad27@gmail.com> | 2025-06-19 10:33:02 +0700 |
|---|---|---|
| committer | Miqdad <ahmadmiqdad27@gmail.com> | 2025-06-19 10:33:02 +0700 |
| commit | 1542b2373ef4cff98ded7c9bbf426e18b5524162 (patch) | |
| tree | dbe7867e87eaf8009a194c38435be9150901b160 /indoteknik_custom/models/tukar_guling.py | |
| parent | ff9b0cb54bb2f9c99773cfc7c8c5b612bb5d7444 (diff) | |
<miqdad> push
Diffstat (limited to 'indoteknik_custom/models/tukar_guling.py')
| -rw-r--r-- | indoteknik_custom/models/tukar_guling.py | 148 |
1 files changed, 0 insertions, 148 deletions
diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py index 186cff97..08b862a7 100644 --- a/indoteknik_custom/models/tukar_guling.py +++ b/indoteknik_custom/models/tukar_guling.py @@ -355,137 +355,6 @@ class TukarGuling(models.Model): ort_picking.action_confirm() ort_picking.action_assign() -class TukarGulingPO(models.Model): - _name = 'tukar.guling.po' - _description = 'Tukar Guling PO' - - name = fields.Char('Number', required=True, copy=False, readonly=True, default='New') - date = fields.Datetime('Date', default=fields.Datetime.now, required=True) - operations = fields.Many2one('stock.picking', 'Nomor BU/Out', - domain=[('picking_type_id.code', '=', 'outgoing')]) - ba_num = fields.Text('Nomor BA') - notes = fields.Text('Notes') - state = fields.Selection(string='Status', selection=[ - ('draft', 'Draft'), - ('approval_purchase', ' Approval Purchase'), - ('approval_logistic', 'Approval Logistic'), - ('approval_finance', 'Approval Finance'), - ('done', 'Done'), - ('cancel', 'Canceled') - ], default='draft', tracking=True, required=True) - - line_ids = fields.One2many('tukar.guling.line.po', 'tukar_guling_po_id', string='Product Lines') - tukar_guling_po_id = fields.Many2one('tukar.guling.po', 'Tukar Guling PO') - - return_type = fields.Selection([ - ('tukar_guling', 'Tukar Guling'), - ('revisi_po', 'Revisi PO'), - ('debit_memo', 'Debit Memo'), - ], string='Return Type', required=True) - - @api.constrains('return_type', 'operations') - def _check_required_bu_fields(self): - for record in self: - if record.return_type in ['tukar_guling', 'revisi_po', 'debit_memo'] and not record.operations: - raise ValidationError("BU/Out harus diisi!") - - @api.constrains('line_ids', 'state') - def _check_product_lines(self): - """Constraint: Product lines harus ada jika state bukan draft""" - for record in self: - if record.state in ('approval_purchase', 'approval_logistic', 'approval_finance', 'done') and not record.line_ids: - raise ValidationError("Product lines harus diisi sebelum submit atau approve!") - - def _validate_product_lines(self): - """Helper method untuk validasi product lines""" - self.ensure_one() - - # Check ada product lines - if not self.line_ids: - raise UserError("Belum ada product lines yang ditambahkan!") - - # Check product sudah diisi - empty_lines = self.line_ids.filtered(lambda line: not line.product_id) - if empty_lines: - raise UserError("Ada product lines yang belum diisi productnya!") - - # Check quantity > 0 - zero_qty_lines = self.line_ids.filtered(lambda line: line.product_uom_qty <= 0) - if zero_qty_lines: - raise UserError("Quantity product tidak boleh kosong atau 0!") - return True - - @api.model - def create(self, vals): - if not vals.get('name') or vals['name'] in ('New', False): - vals['name'] = self.env['ir.sequence'].next_by_code('tukar.guling.po') or 'New' - return super(TukarGulingPO, self).create(vals) - def copy(self, default=None): - if default is None: - default = {} - - # Generate sequence satu-satunya di sini - default['name'] = self.env['ir.sequence'].next_by_code('tukar.guling.po') or 'New' - default['state'] = 'draft' - default['date'] = fields.Datetime.now() - - new_record = super(TukarGulingPO, self).copy(default) - - # Re-sequence lines - if new_record.line_ids: - for i, line in enumerate(new_record.line_ids): - line.sequence = (i + 1) * 10 - - return new_record - - def action_draft(self): - """Reset to draft state""" - for record in self: - if record.state == 'cancel': - record.write({'state': 'draft'}) - else: - raise UserError("Hanya record yang di-cancel yang bisa dikembalikan ke draft") - - def action_submit(self): - self.ensure_one() - - if self.state != 'draft': - raise UserError("Submit hanya bisa dilakukan dari Draft.") - self.state = 'approval_purchase' - - def action_approve(self): - self.ensure_one() - - if not self.operations: - raise UserError("BU/Out harus diisi!") - - if not self.return_type: - raise UserError("Return Type harus diisi!") - - if self.state == 'approval_purchase': - if not self.env.user.has_group('indoteknik_custom.group_role_purchasing'): - raise UserError("Hanya Purchasing yang boleh approve tahap ini.") - self.state = 'approval_logistic' - - elif self.state == 'approval_logistic': - if not self.env.user.has_group('indoteknik_custom.group_role_logistic'): - raise UserError("Hanya Logistic Manager yang boleh approve tahap ini.") - self.state = 'approval_finance' - - elif self.state == 'approval_finance': - if not self.env.user.has_group('indoteknik_custom.group_role_fat'): - raise UserError("Hanya Finance Manager yang boleh approve tahap ini.") - self.state = 'done' - - else: - raise UserError("Status ini tidak bisa di-approve.") - - def action_cancel(self): - self.ensure_one() - # if self.state == 'done': - # raise UserError("Tidak bisa cancel jika sudah done") - self.state = 'cancel' - class TukarGulingLine(models.Model): _name = 'tukar.guling.line' _description = 'Tukar Guling Line' @@ -520,23 +389,6 @@ class TukarGulingLine(models.Model): self.name = self.product_id.display_name self.product_uom = self.product_id.uom_id -class TukarGulingLinePO(models.Model): - _name = 'tukar.guling.line.po' - _description = 'Tukar Guling Line (PO)' - _order = 'sequence, id' - - tukar_guling_po_id = fields.Many2one('tukar.guling.po', string='Tukar Guling PO', required=True, ondelete='cascade') - sequence = fields.Integer('Sequence', default=10, copy=False) - product_id = fields.Many2one('product.product', string='Product', required=True) - product_uom_qty = fields.Float('Quantity', digits='Product Unit of Measure', required=True, default=1.0) - product_uom = fields.Many2one('uom.uom', string='Unit of Measure') - name = fields.Text('Description') - - @api.onchange('product_id') - def _onchange_product_id(self): - if self.product_id: - self.name = self.product_id.display_name - self.product_uom = self.product_id.uom_id class StockPicking(models.Model): _inherit = 'stock.picking' |
