From 6be435f0321929f2fb696e9bf91b64737f387769 Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Thu, 19 Jun 2025 15:21:18 +0700 Subject: (andri) add count bu related --- indoteknik_custom/models/purchase_order.py | 28 +++++++++++++++++++++++++++- indoteknik_custom/views/purchase_order.xml | 7 +------ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 59d8c789..1a7e50f8 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -91,7 +91,33 @@ 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') + # picking_ids = fields.One2many('stock.picking', 'purchase_id', string='Pickings') + + bu_related_count = fields.Integer( + string="BU Related Count", + compute='_compute_bu_related_count' + ) + + @api.depends('name') + def _compute_bu_related_count(self): + for order in self: + if not order.name: + order.bu_related_count = 0 + continue + + # BU langsung dari PO + base_bu = self.env['stock.picking'].search([ + ('name', 'ilike', 'BU/'), + ('origin', 'ilike', order.name) + ]) + base_names = base_bu.mapped('name') + + # Return dari BU di atas + return_bu = self.env['stock.picking'].search([ + ('origin', 'in', [f"Return of {name}" for name in base_names]) + ]) + + order.bu_related_count = len(base_bu) + len(return_bu) def action_view_related_bu(self): self.ensure_one() diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml index e4e75bf2..5417e53c 100755 --- a/indoteknik_custom/views/purchase_order.xml +++ b/indoteknik_custom/views/purchase_order.xml @@ -33,12 +33,7 @@ icon="fa-truck" style="width: 200px;" attrs="{'invisible': [('state', 'in', ['draft', 'sent'])]}"> -
- - - - BU Related -
+