summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
authorIndoteknik . <it@fixcomart.co.id>2025-06-19 14:00:29 +0700
committerIndoteknik . <it@fixcomart.co.id>2025-06-19 14:00:29 +0700
commit9afff443c6d1f489c30f3306cd60e4c97e3cebd1 (patch)
tree57bb1da547d1f717ad9399e04699e2c814679177 /indoteknik_custom/models
parent0367831ed39894eea690a59999722c0d9a248fe4 (diff)
(andri) add button related BU di PO yang hasilnya mengarah ke list related BU
Diffstat (limited to 'indoteknik_custom/models')
-rwxr-xr-xindoteknik_custom/models/purchase_order.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py
index 505df735..59d8c789 100755
--- a/indoteknik_custom/models/purchase_order.py
+++ b/indoteknik_custom/models/purchase_order.py
@@ -91,6 +91,37 @@ class PurchaseOrder(models.Model):
is_cab_visible = fields.Boolean(string='Tampilkan Tombol CAB', compute='_compute_is_cab_visible')
+ picking_ids = fields.One2many('stock.picking', 'purchase_id', string='Pickings')
+
+ def action_view_related_bu(self):
+ self.ensure_one()
+
+ # Step 1: cari semua BU pertama (PUT, INT) yang berasal dari PO ini
+ base_bu = self.env['stock.picking'].search([
+ ('name', 'ilike', 'BU/'),
+ ('origin', 'ilike', self.name)
+ ])
+ base_bu_names = base_bu.mapped('name')
+
+ # Step 2: cari BU turunan (seperti BU/VRT) yang origin-nya mengandung nama BU tersebut
+ domain = [
+ '|',
+ '&',
+ ('name', 'ilike', 'BU/'),
+ ('origin', 'ilike', self.name),
+ ('origin', 'in', [f"Return of {name}" for name in base_bu_names])
+ ]
+
+ return {
+ 'name': 'Related BU (INT/PRT/PUT/VRT)',
+ 'type': 'ir.actions.act_window',
+ 'res_model': 'stock.picking',
+ 'view_mode': 'tree,form',
+ 'target': 'current',
+ 'domain': domain,
+ }
+
+
@api.depends('move_id.state')
def _compute_is_cab_visible(self):
for order in self:
@@ -929,6 +960,12 @@ class PurchaseOrder(models.Model):
if self.product_bom_id:
self._remove_product_bom()
+ # Tambahan: redirect ke BU hanya untuk single PO yang berhasil dikonfirmasi
+ _logger.info("Jumlah PO: %s | State: %s", len(self), self.state)
+ if len(self) == 1:
+ _logger.info("Redirecting ke BU")
+ return self.action_view_related_bu()
+
return res
def _remove_product_bom(self):