Skip to content

Commit

Permalink
[14.0][FIX] purchase_open_qty: Error in add custom filter, and search…
Browse files Browse the repository at this point in the history
… for "Qty to Bill", and "Qty to receive".
  • Loading branch information
alfredoavanzosc committed Nov 12, 2024
1 parent 4233544 commit 89116c7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
18 changes: 18 additions & 0 deletions purchase_open_qty/models/purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,24 @@ 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):
value = float(value) if value else 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):
value = float(value) if value else 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",
Expand Down
22 changes: 22 additions & 0 deletions purchase_open_qty/tests/test_purchase_open_qty.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,28 @@ 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),
)
with self.assertRaises(ValueError):
self.purchase_order_model._search_pending_qty_to_invoice(">>", 0.0)
with self.assertRaises(ValueError):
self.purchase_order_model._search_qty_to_invoice(">>", 0.0)
purchases = self.purchase_order_model.search([("qty_to_invoice", ">", 0)])
purchases_qty_cond = self.purchase_order_model._search_qty_to_invoice(
">", False
)
purchases_qty = self.purchase_order_model.search(purchases_qty_cond)
for purchase in purchases:
self.assertIn(purchase, purchases_qty)
with self.assertRaises(ValueError):
self.purchase_order_model._search_pending_qty_to_receive(">>", 0.0)
with self.assertRaises(ValueError):
self.purchase_order_model._search_qty_to_receive(">>", 0.0)
purchases = self.purchase_order_model.search([("qty_to_receive", ">", 0)])
purchases_qty_cond = self.purchase_order_model._search_qty_to_receive(
">", False
)
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(
Expand Down

0 comments on commit 89116c7

Please sign in to comment.