ERPNext Conference 2019* ERPNext.com Blog

Frappe Hack: Links using related title, instead of name


#1

This is a small hack to frappé, to enable Links, for doctypes that have a title.

This works is based in the discussion with @Pau_Rosello on gitter!

@rmehta, @anand, @JoEz, @priya_s, @fellipeh

Related with:


Linked value

Related DocType


How to override auto selected name field from linked child table
#2

Hello everyone,

We had an interesting discussion on how to approach the fact that when a user select a document in a Link field the Name is shown in the form.

Although my implementation is different from the one @max_morais_dmm provided we are trying to achieve the same thing, to show a different field than Name when a user select a Link document.

Here is an example of what I have working right now with: https://gist.github.com/paurosello/da635c831b0c5560c74ea8ab2a2906ad

Right now this only works if I override the Link control, not If I create a new control. Max was kind enoguh to explain me that backend changes would be needed for this to work.

I’ve tested a very simple application and some users would really benefit from having this feature in Frappe.

Regards!


#3

@max_morais_dmm thanks a lot for to share it, i’ll sure try it!

Info, do the code will be overwritten on future updates? If so, can be added as feature in ERPNext?

Thx in advance


#4

@max_morais_dmm sorry, can’t understand what is the hooks.py to modify …can u share an example for customer or suppliers DocType?

Thx in advance


#5

I just packaged my solution in a ERP-Next app, if anyone can test it and share your thoughts it would be great.

You can get it here: https://github.com/paurosello/linktitle


#6

@max_morais_dmm @Pau_Rosello send a PR for this. I think there are a lot of places we can use this.

Quick question: Do you need 2 fields for this or is the “title” loaded in “onload” ?


#7

@rmehta, me and @Pau_Rosello was working in 2 implementations for the same issue! My implementation change only the link display.
The implementation of @Pau_Rosello modify links to works like attachments.

Basically we stuck in the same issue, so, we shared our codes, allowing to both continue ahead with they own implementation.


#8

@max_morais_dmm I prefer to change the display as well …should be created a new app using your code?

btw, add a PR so that can be added to erpnext by default …


#9

@JoEz, is the best way!

But for that case, in the hooks.py do you need replace some parts:

The original name of my app is subscription so in the app_include_js you need change it by your app name,

in the override_witelisted_methods, do you need add your app name as prefixs in “routes.”

And do you need add:
routes.py in the same dir of hooks.py of your app
widgets in public/js of your app!


#10

@JoEz, if you give me some minutes, I can put it in a app, and share it here!


#11

@max_morais_dmm surely …take ur time …and don’t forget to add a PR :grin:


#12

@JoEz, my code, and the code of @Pau_Rosello are very small.

I understand that @rmehta, needs a PR, but we have 2 distinct implementations, so, which one him wants? :wink:


#13

@max_morais_dmm …well put both …they will choose … :yum:

I’m quite new at frappe / erpnext …let me ask you …if i want to use your app to all of the links used in erpnext …i.e. Customer, Suppliers …etc …what to change?


#14

@JoEz just install this app in the site, and enjoy!
My app adds a new behavior for the link, so you dont need change nothing!


#15

@max_morais_dmm great work! i really needed that! :wink: :grin:


#16

@JoEz https://github.com/mxmo-co/title_links


#17

@max_morais_dmm i’ve installed and tested on item code for supplier in item …but still showing naming_series instead of title …

…sorry my fault … :smile: i didn’t installed …now installed and .getting an error

message is: App subscription is not installed


#18

@JoEz, fixed!

Go to the app and run, git pull


#19

@max_morais_dmm ok, thanks

a couple of errors:

when supplier is selected, it shows Distributor instead of Supplier Name …i’ve checked in the doc type and title field is supplier_name, see pics:

when u press done, and go back to the row to edit, the link shows empty, pic:


#20

@JoEz, this is because your cache is not cleared!

Run

bench clear-cache and bench restart