ERPNext Foundation ERPNext Cloud Chat Blog Discuss Frappé* Donate

Projects automatic numbering – workaround using client custom script

projects
customization
custom_script

#1

Hi,
we have hundreds of projects and so we need an unique identifier for projects. Manual numbering in project_name field is not very comfortable and can lead to meaningless names like Project1, Project2 etc. If I do it using naming_series in Project doctype, I won’t be able to make updates via bench update, is it right? And this is what I don’t want.

Is there a way or workaround, how to do it without touching project doctype using client side customization?
I thought about creating a custom script, which will set project_name to some auto-incremented value automatically on project creation. Descriptive project name then could be saved in a new custom field, called for example project_title. Is it possible to do it like this? Or is there a better/simpler way?

I have tried to do it using this script, but it didn’t work for me. It will be my first script, could you please outline possible solution?


#2

Any ideas?


#3

You ran ‘bench update’ and had a naming_series problem?

Sorry I am not clear - your problem is theoretical or from actual testing?


#4

Hi @clarkej
problem is both theoretical and practical.

Theoretical part is, that I have read somewhere to not touch doctypes, because it breaks updates.

But I tried it anyway, and came to this message after running bench update:

Cannot proceed with update: You have local changes in app "erpnext" that are not committed.

Here are your choices:

1. Merge the erpnext app manually with "git pull" / "git pull --rebase" and fix conflicts.
1. Temporarily remove your changes with "git stash" or discard them completely
        with "bench update --reset" or for individual repositries "git reset --hard"
2. If your changes are helpful for others, send in a pull request via GitHub and
        wait for them to be merged in the core.

This is where I ended, because I’m not sure what to choose to both keep my changes and have erpnext still upgradable.


#5

ok yes update overwrites your local (server side) code changes.

A search like ‘save local changes’ or ‘git pull or git stash’ will inform your options and steps on what to do and expect.

You can identify your changes with say git status and diff - to learn git basics

To experiment and discover a practice or test environment is best.


#6

Hello @clarkej
thank you for your response, I know something about git, but I don’t know enough about ERPNext.
You are right that to experiment and discovery is best to learn, but some guides and advices can save time…

So bench update is something like git pull & bench migrate? There is not any other magic behind it?

Sorry for asking such general question, but are there any guidelines or best practices, when is reasonable to make changes directly to doctypes and when is better to create separate module/app for these changes?


#7

With general questions the devil is in the details…does this help What is the best practice for custom scripts?


#8

Hello @clarkej,
thank you for helping me, I have followed the link with some searching around and I found some stuff that have moved me forward. After a lot of reading and trying I suppose, that the best way will be to keep changes in one place = in separate app. I have found this guide which was very helpful (thanks to @root13F) .

But I still have two, this time very specific, questions to which I didn’t find clear answer:

How to pair changes I have made with available fixture types? I found this list of fixtures
fixtures = [‘Report’, ‘Role Profile’, ‘Role’, ‘Custom Field’, ‘Custom Script’, ‘Property Setter’, ‘Workflow’, ‘Workflow State’, ‘Workflow Action’]
I suppose that if I have made changes for example in Sales order via Customize form, the correct fixture is Custom Field (no matter if I added or modified fields?). But what if I made changes directly to DocType via editing it in DocType form in developer mode(adding fields there or changing naming series)? Will exporting fixtures of Custom Field type reflect also these changes? I have tried it on test site and custom_field.json file looked exactly the same before and after direct modifying of DocType.
If it is not possible to export changes made to DocTypes this way, is there any other way, how to move changes made to existing DocTypes to separate app?

And another question is, if I export fixtures to separate app, does it “undoes” all the changes I have made to erpnext? In other words, is it move or copy?