summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/purchase_order.py
diff options
context:
space:
mode:
authorMiqdad <ahmadmiqdad27@gmail.com>2025-06-22 19:14:06 +0700
committerMiqdad <ahmadmiqdad27@gmail.com>2025-06-22 19:14:06 +0700
commit4430c79a3388c591725cdbd12e32c6c371b6ecd3 (patch)
treea5935e7e5fda73c7929d4ef5a84e734b9c305626 /indoteknik_custom/models/purchase_order.py
parent680748ae128a90b9999acff60c770e2472c7fcbe (diff)
parenteeb72c4ed24c33403bb733a51198b9cc0f356e6a (diff)
Merge branch 'odoo-backup' of https://bitbucket.org/altafixco/indoteknik-addons into tukar_guling
Diffstat (limited to 'indoteknik_custom/models/purchase_order.py')
-rwxr-xr-xindoteknik_custom/models/purchase_order.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py
index 004a1fa4..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:
@@ -452,6 +509,18 @@ class PurchaseOrder(models.Model):
'company_id': self.company_id.id,
'payment_schedule': payment_schedule
}
+
+ receipt = self.env['stock.picking'].search([
+ ('purchase_id', '=', self.id),
+ ('state', '=', 'done'),
+ ('picking_type_code', '=', 'incoming'),
+ ('date_done', '!=', False)
+ ], order='date_done desc', limit=1)
+
+ if receipt:
+ invoice_vals['invoice_date'] = receipt.date_done
+ invoice_vals['date'] = receipt.date_done
+
return invoice_vals
def _compute_matches_so(self):
@@ -917,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):