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 10, 2024
1 parent 4233544 commit 82180e2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion purchase_open_qty/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"name": "Purchase Open Qty",
"summary": "Allows to identify the purchase orders that have quantities "
"pending to invoice or to receive.",
"version": "14.0.1.1.2",
"version": "14.0.1.1.3",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/purchase-workflow",
"category": "Purchases",
Expand Down
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 82180e2

Please sign in to comment.