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 Oct 21, 2024
1 parent 4233544 commit 9a1f2b0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
20 changes: 20 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,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",
Expand Down
10 changes: 10 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,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(
Expand Down

0 comments on commit 9a1f2b0

Please sign in to comment.