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 | |
| parent | 9afff443c6d1f489c30f3306cd60e4c97e3cebd1 (diff) | |
(andri) add count bu related
| -rwxr-xr-x | indoteknik_custom/models/purchase_order.py | 28 | ||||
| -rwxr-xr-x | 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'])]}"> - <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> + <field name="bu_related_count" widget="statinfo" string="BU Related"/> </button> </xpath> <button id="draft_confirm" position="after"> |
