summaryrefslogtreecommitdiff
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
parent0367831ed39894eea690a59999722c0d9a248fe4 (diff)
(andri) add button related BU di PO yang hasilnya mengarah ke list related BU
-rwxr-xr-xindoteknik_custom/models/purchase_order.py37
-rwxr-xr-xindoteknik_custom/views/purchase_order.xml13
2 files changed, 50 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):
diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml
index 9084bcbb..e4e75bf2 100755
--- a/indoteknik_custom/views/purchase_order.xml
+++ b/indoteknik_custom/views/purchase_order.xml
@@ -27,6 +27,19 @@
<t t-esc="record.move_id.name"/>
</span>
</button>
+ <button type="object"
+ name="action_view_related_bu"
+ class="oe_stat_button"
+ icon="fa-truck"
+ style="width: 200px;"
+ attrs="{'invisible': [('state', 'in', ['draft', 'sent'])]}">
+ <div class="o_stat_info">
+ <span class="o_stat_value">
+ <t t-esc="len(record.picking_ids)"/>
+ </span>
+ <span class="o_stat_text">BU Related</span>
+ </div>
+ </button>
</xpath>
<button id="draft_confirm" position="after">
<button name="po_approve"