How to Filter Items Without a Linked eBay Listing in List View?

Hi everyone,

I’m relatively new to ERPNext and have been using it for a few months—I really like it so far!

I have a custom Doctype called “eBay Listings”, which is linked to Item via the item_code field.

Problem:

In the Item List View, I want to filter and find all Items that do not have a linked eBay Listing. However, I couldn’t find an elegant way to achieve this with the built-in filters.

What I’ve Tried:

  1. Using standard filters in the Item List View, but there is no direct way to filter based on a linked Doctype.
  2. Exploring custom fields to count related eBay Listings, but I prefer an out-of-the-box solution.
  3. Attempting a Custom Script to filter the List View dynamically, but I’m not sure if there’s a simpler way.

Question:

Is there a native way in ERPNext to filter Items without a linked eBay Listing in the List View?
Or do I need a custom SQL report or Client Script to achieve this?

Would really appreciate any guidance or best practices on how to implement this efficiently.

Thanks in advance! :blush:

Computed and relational fields are a bit of a gap in the Frappe ORM. This would be trivial to create in a report, but I’m not aware of any simple way to do it in the current list view.

One approach would be to create custom checkbox field in your Item doctype (has_ebay_listing, or something) and then an on_save hook in your new doctype. The on_save hook updates the item checkbox whenever an ebay listing is changed. It creates some redundant data that can possibly get out of sync, which makes it a less-than-ideal solution, but it should work fine.

1 Like

thankyou, i have added a serversctipt updating an integer custom field (read only) on_save hook from the custom doctype

ebay_count = frappe.db.count("eBay Listings", {"item_code": doc.item_code})
frappe.db.set_value("Item", doc.item_code, "custom_has_ebay_listing", ebay_count)

Hi @maydo7777:

Most times, as @peterg well said, you can use a new field to store this value …

Additionally, check formatters feature …
https://docs.frappe.io/framework/user/en/api/list

Edit: Sorry, i missunderstood this … probably won’t work here.
Anyway, since this pretty “hidden”, keep this post :crazy_face:

Just a heads up: this script will never set your custom field to zero if you remove or change your link field.

To remove counts for link fields that were changed, you might use the get_doc_before_save method.

https://docs.frappe.io/framework/user/en/api/document#docget_doc_before_save

thankyou, your right, it will never set zero, i have added a second script with after delete hook

You’ll still have problems if you set the link field to Item A and then change it to Item B (the item A tally will not be removed), but perhaps that’s not possible in your workflow.

this is ok, the linked docs will not change to another

1 Like