diff options
| author | Indoteknik . <it@fixcomart.co.id> | 2025-06-19 15:21:18 +0700 |
|---|---|---|
| committer | Indoteknik . <it@fixcomart.co.id> | 2025-06-19 15:21:18 +0700 |
| commit | 6be435f0321929f2fb696e9bf91b64737f387769 (patch) | |
| tree | 5399e0e867db7efcc15094bbb02548716dd9e856 /indoteknik_custom/models | |
| parent | 9afff443c6d1f489c30f3306cd60e4c97e3cebd1 (diff) | |
(andri) add count bu related
Diffstat (limited to 'indoteknik_custom/models')
| -rwxr-xr-x | indoteknik_custom/models/purchase_order.py | 28 |
1 files changed, 27 insertions, 1 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() |
