From 0198b0a0683cc7db1241ec9b7184c2cb608ba049 Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Tue, 15 Jul 2025 11:52:33 +0700 Subject: (andri) fix edit unit price PO --- indoteknik_custom/models/purchase_order.py | 9 ++++++++- indoteknik_custom/views/purchase_order.xml | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 4dc26d74..6901ecb6 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -668,9 +668,16 @@ class PurchaseOrder(models.Model): resposible_ids = list(set(resposible_ids)) purchase.responsible_ids = resposible_ids + # def _compute_has_active_invoice(self): + # for order in self: + # order.has_active_invoice = any(invoice.state != 'cancel' for invoice in order.invoice_ids) + def _compute_has_active_invoice(self): for order in self: - order.has_active_invoice = any(invoice.state != 'cancel' for invoice in order.invoice_ids) + related_invoices = order.invoice_ids.filtered( + lambda inv: inv.purchase_order_id.id == order.id and inv.move_type == 'in_invoice' and inv.state != 'cancel' + ) + order.has_active_invoice = bool(related_invoices) def add_product_to_pricelist(self): i = 0 diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml index dae23eed..fa8d40d5 100755 --- a/indoteknik_custom/views/purchase_order.xml +++ b/indoteknik_custom/views/purchase_order.xml @@ -164,7 +164,7 @@ - {'readonly': ['|', ('state', 'in', ['purchase', 'done', 'cancel']), ('has_active_invoice', '=', True)]} + {'readonly': ['&', ('state', 'in', ['purchase', 'done', 'cancel']), ('has_active_invoice', '=', True)]} -- cgit v1.2.3