From 9a1f2b06a4805f61971e1c7df4f13e6919fff84e Mon Sep 17 00:00:00 2001 From: Alfredo Date: Wed, 2 Oct 2024 12:55:27 +0200 Subject: [PATCH] [14.0][FIX] purchase_open_qty: Error in add custom filter, and search for "Qty to Bill", and "Qty to receive". --- purchase_open_qty/models/purchase_order.py | 20 +++++++++++++++++++ .../tests/test_purchase_open_qty.py | 10 ++++++++++ 2 files changed, 30 insertions(+) diff --git a/purchase_open_qty/models/purchase_order.py b/purchase_open_qty/models/purchase_order.py index e1383009d23..09dc9a77949 100644 --- a/purchase_open_qty/models/purchase_order.py +++ b/purchase_open_qty/models/purchase_order.py @@ -114,6 +114,26 @@ def _search_pending_qty_to_invoice(self, operator, value): else: return [("id", "not in", orders.ids)] + @api.model + def _search_qty_to_invoice(self, operator, value): + if not value: + value = 0.0 + po_line_obj = self.env["purchase.order.line"] + cond = [("qty_to_invoice", operator, value)] + po_lines = po_line_obj.search(cond) + orders = po_lines.mapped("order_id") + return [("id", "in", orders.ids)] + + @api.model + def _search_qty_to_receive(self, operator, value): + if not value: + value = 0.0 + po_line_obj = self.env["purchase.order.line"] + cond = [("qty_to_receive", operator, value)] + po_lines = po_line_obj.search(cond) + orders = po_lines.mapped("order_id") + return [("id", "in", orders.ids)] + qty_to_invoice = fields.Float( compute="_compute_qty_to_invoice", search="_search_qty_to_invoice", diff --git a/purchase_open_qty/tests/test_purchase_open_qty.py b/purchase_open_qty/tests/test_purchase_open_qty.py index 028865d3ca8..3af05f80cc0 100644 --- a/purchase_open_qty/tests/test_purchase_open_qty.py +++ b/purchase_open_qty/tests/test_purchase_open_qty.py @@ -189,6 +189,16 @@ def test_search_qty_to_invoice_and_receive(self): "Expected PO %s not to be in POs %s" % (self.purchase_order_2.id, found.ids), ) + purchases = self.purchase_order_model.search([("qty_to_invoice", ">", 0)]) + purchases_qty_cond = self.purchase_order_model._search_qty_to_invoice(">", 0.0) + purchases_qty = self.purchase_order_model.search(purchases_qty_cond) + for purchase in purchases: + self.assertIn(purchase, purchases_qty) + purchases = self.purchase_order_model.search([("qty_to_receive", ">", 0)]) + purchases_qty_cond = self.purchase_order_model._search_qty_to_receive(">", 0.0) + purchases_qty = self.purchase_order_model.search(purchases_qty_cond) + for purchase in purchases: + self.assertIn(purchase, purchases_qty) def test_03_po_line_with_services(self): self.assertEqual(