diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2025-06-19 08:37:17 +0000 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2025-06-19 08:37:17 +0000 |
| commit | 111cb931a88fceb811cafa9551c0dbd809ea2446 (patch) | |
| tree | ea6653e6b7c9717a7384e30a1105354a6eb84c21 | |
| parent | 1beabdd925218c888ad1b3b684a8eab020316a2e (diff) | |
| parent | 8a0293f9f644c2006182f71c241a78d62b8cc3a7 (diff) | |
Merged in bu-button-po (pull request #340)
Bu button po
| -rwxr-xr-x | indoteknik_custom/models/purchase_order.py | 63 | ||||
| -rwxr-xr-x | indoteknik_custom/views/purchase_order.xml | 9 |
2 files changed, 72 insertions, 0 deletions
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 505df735..1a7e50f8 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -91,6 +91,63 @@ 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') + + 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() + + # 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 +986,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..7b568d07 100755 --- a/indoteknik_custom/views/purchase_order.xml +++ b/indoteknik_custom/views/purchase_order.xml @@ -27,6 +27,15 @@ <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'])]}"> + <field name="bu_related_count" widget="statinfo" string="BU Related"/> + </button> + <field name="picking_count" invisible="1"/> </xpath> <button id="draft_confirm" position="after"> <button name="po_approve" |
