Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][FIX] purchase_open_qty: Error in add custom filter, and search… #2421

Open
wants to merge 1 commit into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading