summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/tukar_guling_po.py
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2025-07-31 08:35:01 +0700
committerit-fixcomart <it@fixcomart.co.id>2025-07-31 08:35:01 +0700
commitaeb4fc3b4b8a4c38d6628946232c236a4d2fe2a9 (patch)
tree28db4b1dc10a10bc65f5b57a4470d39e78629ef7 /indoteknik_custom/models/tukar_guling_po.py
parent8d1af98bb7dab812f91d7d275b4004c4e5b0ff75 (diff)
parentd6bdde8fe63ff15ce8f3fee6bc5e8ae903fc78ce (diff)
<hapit>merge
Diffstat (limited to 'indoteknik_custom/models/tukar_guling_po.py')
-rw-r--r--indoteknik_custom/models/tukar_guling_po.py88
1 files changed, 68 insertions, 20 deletions
diff --git a/indoteknik_custom/models/tukar_guling_po.py b/indoteknik_custom/models/tukar_guling_po.py
index 7c9680f8..23ca1923 100644
--- a/indoteknik_custom/models/tukar_guling_po.py
+++ b/indoteknik_custom/models/tukar_guling_po.py
@@ -10,7 +10,7 @@ _logger = logging.getLogger(__name__)
class TukarGulingPO(models.Model):
_name = 'tukar.guling.po'
- _description = 'Tukar Guling PO'
+ _description = 'Pengajuan Retur PO'
_inherit = ['mail.thread', 'mail.activity.mixin']
vendor_id = fields.Many2one('res.partner', string='Vendor Name', readonly=True)
@@ -49,6 +49,7 @@ class TukarGulingPO(models.Model):
('approval_purchase', 'Approval Purchasing'),
('approval_finance', 'Approval Finance'),
('approval_logistic', 'Approval Logistic'),
+ ('approved', 'Waiting for Operations'),
('done', 'Done'),
('cancel', 'Cancel'),
], string='Status', default='draft', tracking=3)
@@ -245,12 +246,12 @@ class TukarGulingPO(models.Model):
return True
- def _is_already_returned(self, picking):
- return self.env['stock.picking'].search_count([
- ('origin', '=', 'Return of %s' % picking.name),
- # ('returned_from_id', '=', picking.id),
- ('state', 'not in', ['cancel', 'draft']),
- ]) > 0
+ # def _is_already_returned(self, picking):
+ # return self.env['stock.picking'].search_count([
+ # ('origin', '=', 'Return of %s' % picking.name),
+ # # ('returned_from_id', '=', picking.id),
+ # ('state', 'not in', ['cancel', 'draft']),
+ # ]) > 0
def copy(self, default=None):
if default is None:
@@ -311,7 +312,7 @@ class TukarGulingPO(models.Model):
def unlink(self):
for record in self:
- if record.state == 'done':
+ if record.state == 'done' or record.state == 'approved':
raise UserError("Tidak bisa hapus pengajuan jika sudah done, set ke draft terlebih dahulu")
ongoing_bu = self.po_picking_ids.filtered(lambda p: p.state != 'done')
for picking in ongoing_bu:
@@ -320,14 +321,23 @@ class TukarGulingPO(models.Model):
def action_view_picking(self):
self.ensure_one()
- action = self.env.ref('stock.action_picking_tree_all').read()[0]
- pickings = self.po_picking_ids
- if len(pickings) > 1:
- action['domain'] = [('id', 'in', pickings.ids)]
- elif pickings:
- action['views'] = [(self.env.ref('stock.view_picking_form').id, 'form')]
- action['res_id'] = pickings.id
- return action
+
+ # picking_origin = f"Return of {self.operations.name}"
+ returs = self.env['stock.picking'].search([
+ ('tukar_guling_po_id', '=', self.id),
+ ])
+
+ if not returs:
+ raise UserError("Doc Retrun Not Found")
+
+ return {
+ 'type': 'ir.actions.act_window',
+ 'name': 'Delivery Pengajuan Retur PO',
+ 'res_model': 'stock.picking',
+ 'view_mode': 'tree,form',
+ 'domain': [('id', 'in', returs.ids)],
+ 'target': 'current',
+ }
def action_draft(self):
"""Reset to draft state"""
@@ -365,8 +375,8 @@ class TukarGulingPO(models.Model):
if pick_id not in [75, 28]:
raise UserError("❌ Tidak bisa retur bukan BU/INPUT atau BU/PUT!")
- if self._is_already_returned(self.operations):
- raise UserError("BU ini sudah pernah diretur oleh dokumen lain.")
+ # if self._is_already_returned(self.operations):
+ # raise UserError("BU ini sudah pernah diretur oleh dokumen lain.")
if self.state != 'draft':
raise UserError("Submit hanya bisa dilakukan dari Draft.")
@@ -403,12 +413,50 @@ class TukarGulingPO(models.Model):
elif rec.state == 'approval_logistic':
if not rec.env.user.has_group('indoteknik_custom.group_role_logistic'):
raise UserError("Hanya Logistic Manager yang boleh approve tahap ini.")
- rec.state = 'done'
+ rec.state = 'approved'
rec._create_pickings()
rec.date_logistic = now
else:
raise UserError("Status ini tidak bisa di-approve.")
+ def update_stae(self):
+ # bu input rev po
+ if self.operations.picking_type_id.id == 28 and self.return_type == 'revisi_po':
+ prt = self.env['stock.picking'].search([
+ ('tukar_guling_po_id', '=', self.id),
+ ('state', '=', 'done'),
+ ('picking_type_id.id', '=', 76)
+ ])
+ if self.state == 'aproved' and prt:
+ self.state = 'done'
+ # bu put rev po
+ elif self.operations.picking_type_id.id == 75 and self.return_type == 'revisi_po':
+ total_prt = self.env['stock.picking'].search_count([
+ ('tukar_guling_po_id', '=', self.id),
+ ('picking_type_id.id', '=', 76)
+ ])
+ prt = self.env['stock.picking'].search_count([
+ ('tukar_guling_po_id', '=', self.id),
+ ('state', '=', 'done'),
+ ('picking_type_id.id', '=', 76)
+ ])
+ if self.state == 'aproved' and total_prt > 0 and prt == total_prt:
+ self.state = 'done'
+ # bu put tukar guling
+ elif self.operations.picking_type_id.id == 75 and self.return_type == 'tukar_guling':
+ total_put = self.env['stock.picking'].search_count([
+ ('tukar_guling_po_id', '=', self.id),
+ ('picking_type_id.id', '=', 75)
+ ])
+ put = self.env['stock.picking'].search_count([
+ ('tukar_guling_po_id', '=', self.id),
+ ('state', '=', 'done'),
+ ('picking_type_id.id', '=', 75)
+ ])
+ if self.state == 'aproved' and total_put > 0 and put == total_put:
+ self.state = 'done'
+
+
def action_cancel(self):
self.ensure_one()
# if self.state == 'done':
@@ -629,7 +677,7 @@ class TukarGulingLinePO(models.Model):
@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']:
+ if rec.tukar_guling_po_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):