diff options
| author | Miqdad <ahmadmiqdad27@gmail.com> | 2025-06-17 08:09:57 +0700 |
|---|---|---|
| committer | Miqdad <ahmadmiqdad27@gmail.com> | 2025-06-17 08:09:57 +0700 |
| commit | abd7da741c6eec02dbefa195b91dbedd70b3323e (patch) | |
| tree | e6abb2af2a8b685f0a509cd87a28ebb76b7a5cbe /indoteknik_custom/models | |
| parent | a0e90200638e26ad06d1caaf2d91d0aeea3ba19d (diff) | |
<miqdad> add tukar guling PO and move from inventory
Diffstat (limited to 'indoteknik_custom/models')
| -rw-r--r-- | indoteknik_custom/models/tukar_guling.py | 56 |
1 files changed, 48 insertions, 8 deletions
diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py index 95aa7cd6..aeb2c9e7 100644 --- a/indoteknik_custom/models/tukar_guling.py +++ b/indoteknik_custom/models/tukar_guling.py @@ -142,12 +142,25 @@ class TukarGuling(models.Model): class TukarGulingPO(models.Model): _name = 'tukar.guling.po' - _inherit = 'tukar.guling' _description = 'Tukar Guling PO' - # tukar_guling_id = fields.Many2one( - # 'tukar.guling', required=True, ondelete='cascade', string='Tukar Guling Ref' - # ) + name = fields.Char('Number', required=True, copy=False, readonly=True, default='New') + date = fields.Datetime('Date', default=fields.Datetime.now, required=True) + out_num = 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'), @@ -165,7 +178,7 @@ class TukarGulingPO(models.Model): def _check_product_lines(self): """Constraint: Product lines harus ada jika state bukan draft""" for record in self: - if record.state in ('approval_sales', 'approval_logistic', 'approval_finance', 'done') and not record.line_ids: + 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): @@ -223,7 +236,7 @@ class TukarGulingPO(models.Model): if self.state != 'draft': raise UserError("Submit hanya bisa dilakukan dari Draft.") - self.state = 'approval_sales' + self.state = 'approval_purchase' def action_approve(self): self.ensure_one() @@ -234,12 +247,21 @@ class TukarGulingPO(models.Model): if not self.return_type: raise UserError("Return Type harus diisi!") - if self.state == 'approval_sales': + 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.") @@ -281,4 +303,22 @@ class TukarGulingLine(models.Model): def _onchange_product_id(self): if self.product_id: self.name = self.product_id.display_name - self.product_uom = self.product_id.uom_id
\ No newline at end of file + 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 |
