Frappe Hack: Links using related title, instead of name

now i get error:

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 55, in application
    response = frappe.handler.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 19, in handle
    execute_cmd(cmd)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 36, in execute_cmd
    ret = frappe.call(method, **frappe.form_dict)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 875, in call
    return fn(*args, **newargs)
TypeError: search_title() takes exactly 2 arguments (1 given)

@JoEz, sounds that you have a link passing a null value!

Edit: Anyway I have fixed it now!

@max_morais_dmm …same error in all doctypes …tested in Sales Invoices with links in customer …probably i can try to uninstall and reinstall …

@max_morais_dmm …it seems kind of strange as the error rises up just after pulling the changes to correct “subscription app” problem …

Oh ok …i’ll pull and check …

@max_morais_dmm it seems to work …the only thing is that when u click and select the link it shows Distributor instead of SupplierName … once u re-edit it shows correctly …

see pictures, while selecting:

once selected:

saving it and re-editing it shows the supplier_name correctly.

I’ve cleared the cache, bench restart but nothing changes …can u please have a look?

Thank a lot in advance …

@rmehta, I can prepare a PR, if someone guideme with some things!

###About the Pull Request
I would gladly prepare a PR but my implementation changes only the UI when an item is selected in order to work like an attachment while the implementation done by Max changes the value shown with no UI changes.

Max’s implementation also modifies the search list showing the title instead of the name.

Based on this I think that we could merge the changes if your prefer the “attachment” to the current UI while also getting the new feature of modifying the items in the search list.


###List Views

If you want to show the subscriber name in the list, the best option would be to create a hidden field that is filled with:

`cur_frm.add_fetch("subscriber", "subscriber_name", "subscriber_name");`

The problem with this is that if you change the name of the subscriber afterwards it will not be updated in the linked documents.

I cannot think of an implementation for this without making too much impact in performance.
Making a REST call for each document in the list is not feasible, maybe getting the title of the Link fields in the backed is the way to go but I don’t know where to start on this.

@Pau_Rosello add_fetch have 2 problems, it is not updated when you update the related document, and dont is supported by backend!

Add fetch have an alvernative syntax, fieldname.target_field, but again only works in the client side!

The issue with use an alternative column, dont make sense because we lose the behavior of the links, that apply filters in list!

@max_morais_dmm …thinking about the problem, any chance to use the <select> tag instead of <input type="text"> … probably that would solve the problem …

@JoEz, dont make sense use select due the purpose of autocomplete is save resources, let me show an example, Few years ago, I managed one instance with 300K of Items, the will turn impossible to load in lagest database!

@max_morais_dmm i see …i’m wondering how to manage item name (aka product description) used as primary key in the table with 300k items …

What is hard to manage is using the primary key (name in erpnext) as the description. In Item group, for example, its not uncommon to have “not classified” group name inside a different groups …how to manage it? …normally its used a code as primary key to avoid problems …

I really hope you’ll be able to find the best way to implement your feature :smile:

By the way, i’m still experiencing the problem i wrote in previous post …

@JoEz, yesterday I published some fixes in the github! Please check it!

In the past, I discovered that is impossible manage “Humanized Item description” as PK, because you will have a lot of colisions!, In my case, the users only can access they own Items because each user design they own products in AutoCAD, and from AutoCAD we load the parts to build the product in ERPNext.

As primary scheme, I created a pattern where the Item name is:

{item-group} - {customer_name} - {user_name} - {year} - {month}, the item description is
{customer_name} - {item_group} - {day}/{month}/{year},

The first point that your keep in mind is, how limit the user vision! Because largest item tables, increase the number of possible mistakes!
The another point, is how you can automate the item selection, usually, when you have a large number of item, is because one item, is related with others!

So, keep your focus into these 2 points, and I believe you will got success!

If are you trying to use my code, to solve this issue, sorry to say, you are looking for the wrong approach! Automation is the key!

The purpose of this code, is to increase the readability of FK’s! Due I’ll use GUID for all record name.

@max_morais_dmm …i agree …infact i normally use a UID to store the PK and a Description for the user …and i’m using same approach in erpnext …where is possible …infact seems that on item group is not possible unless to modify DocType, enabling developer mode …

I’m not trying to use your code to solve the problem of how to store reliable PK in the db …i’m trying to use ur code to show user the description while keep storing the UID or naming_series as PK.

…about the code …i pulled last version but still facing the problem as in post

@max_morais_dmm Hi there, any news on PR? :grin:

@JoEz have some fixes to publish! But without the positioning of @rmehta, I don’t will open a PR!

We have 2 projects, him need decide which one him wants!

And I put others terms to publish the PR, Have issued to solve in list views and reports

EDIT: @JoEz The fixes are published!

@max_morais_dmm I see …thanx for the fix i’ll test and let u know. If i can help in any way in list view and reports let me know …

@JoEz Any help is wellcome!

@max_morais_dmm can u explain exactly the problem?

@JoEz the issue is the same of the forms!

When we are in a List View or in a Report the link should display the Title instead of the Value

If I add a fetch to display the title we will lose in the list view the hability of apply filters in the list-view clicking in a link and for go to the related link in the reports.

Edit: Maybe in list view, I’m able to solve too!

@max_morais_dmm hummmmmmm …not sure if i can help :frowning: