How to apply a patch in custom app?

239 views
Skip to first unread message

Aditya Duggal

unread,
Aug 22, 2014, 10:59:39 AM8/22/14
to erpnext-dev...@googlegroups.com
Hi,

I have tried to understand the developer guide but could not find any guide as to how to apply patches. Basically what I am doing is that I have a set of code running on item codes for item master, now every now and then this file of code is changed to apply new rules to items.

The initial practice I do is that I commit my code changes on github and then to check if all items are ok and are within the ambit of the rules in the code, I generally import all items with one field.

Now the problem is that this method of importing all items is very lengthy and cumbersome and hence I was thinking if I could somehow try to make all items get checked through the code via the patches path then it would be great.

Rushabh Mehta

unread,
Aug 23, 2014, 4:52:22 AM8/23/14
to erpnext-dev...@googlegroups.com
On 22-Aug-2014, at 8:29 pm, Aditya Duggal <aditya...@gmail.com> wrote:

Hi,

I have tried to understand the developer guide but could not find any guide as to how to apply patches. Basically what I am doing is that I have a set of code running on item codes for item master, now every now and then this file of code is changed to apply new rules to items.

1. Create a /patches folder in your app
2. Add your patch code file there. The patch file must be a python file with a function called "execute" 


3. Add the files in the patches.txt file in your repo

Similar to this


Thats it. Your patches will be automatically run when you run latest



The initial practice I do is that I commit my code changes on github and then to check if all items are ok and are within the ambit of the rules in the code, I generally import all items with one field.

Now the problem is that this method of importing all items is very lengthy and cumbersome and hence I was thinking if I could somehow try to make all items get checked through the code via the patches path then it would be great.


--
Note:
 
If you are posting an issue,
 
1. ERPNext is a free and open source software and support is given on this forum by a team (https://frappe.io/webnotes). So please consider donating if you find this forum useful (https://frappe.io/buy). Even a small amount would be helpful.
2. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
3. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
4. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.
 
End of Note
---
You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/ebe945db-f562-4d5c-ac97-bbdd09a7d3ed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Aditya Duggal

unread,
Aug 25, 2014, 4:18:42 AM8/25/14
to erpnext-dev...@googlegroups.com
Thanks Rushabh,

I am trying the things as I write this post but stumbled upon 2 more things, 

  1. I would like to find and apply patch to those items which are showing in golden color (means items which are not saved), I am unable to find a way to find those items.
  2. Would the patch run every time we do the update of the app

To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+unsub...@googlegroups.com.

Rushabh Mehta

unread,
Aug 25, 2014, 5:49:18 AM8/25/14
to erpnext-dev...@googlegroups.com
On 25-Aug-2014, at 1:48 pm, Aditya Duggal <aditya...@gmail.com> wrote:

Thanks Rushabh,

I am trying the things as I write this post but stumbled upon 2 more things, 

  1. I would like to find and apply patch to those items which are showing in golden color (means items which are not saved), I am unable to find a way to find those items.
there must be some way to find them out! (SQL ?)
  1. Would the patch run every time we do the update of the app

No only once - system keeps track of all patches installed.

To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/226a36f5-d8f1-47c6-999f-caadbcf522c3%40googlegroups.com.

Aditya Duggal

unread,
Aug 30, 2014, 2:10:15 AM8/30/14
to erpnext-dev...@googlegroups.com
I am getting this error:

ImportError: No module named patches.item_master.patch_item

Now this is my folder structure: frappe-bench/apps/rigpl-erpnext/rigpl_erpnext/patches/item_master/patch_item.py

Now I have a text file patches.txt in frappe-bench/apps/rigpl-erpnext/rigpl_erpnext

The line mentioned in patches.txt is rigpl_erpnext.patches.item_master.patch_item

Please note the difference in the rigpl-erpnext & rigpl_erpnext folders.

What am I missing?

Anand Doshi

unread,
Aug 30, 2014, 2:28:42 AM8/30/14
to erpnext-dev...@googlegroups.com
Create a file __init__.py in patches folder. 

Sent from my phone
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/90090a0a-37c8-4b14-b6a4-8a43bc8a1855%40googlegroups.com.

Anand Doshi

unread,
Aug 30, 2014, 2:29:25 AM8/30/14
to erpnext-dev...@googlegroups.com
Also in item_master folder

Sent from my phone

On 30-Aug-2014, at 11:40, Aditya Duggal <aditya...@gmail.com> wrote:

To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/90090a0a-37c8-4b14-b6a4-8a43bc8a1855%40googlegroups.com.

Aditya Duggal

unread,
Aug 30, 2014, 2:58:19 AM8/30/14
to erpnext-dev...@googlegroups.com
Thanks a lot Anand, works fine.

Just wanted to know if I could reset the patch applied since I am kind of testing the application of patch and I am sometimes not aware what results would it bear.

Is it possible to somehow reset the list of patches applied so that I could test my patch files multiple times.

Aditya Duggal

unread,
Aug 30, 2014, 3:13:05 AM8/30/14
to erpnext-dev...@googlegroups.com
Hi Anand,

I found a way for the patches. Just enabled developer mode in my local account and gave the admin the rights to delete the patch log items.

Thanks once again for the help.

Aditya Duggal

unread,
Aug 30, 2014, 3:28:58 AM8/30/14
to erpnext-dev...@googlegroups.com
Hi,

I have just figured out that when I execute the patch then the validation code for that doctype is skipped. Is it possible to invoke the validations during the execution of the patch as I am unable to find a way to invoke validations while executing a patch.

Anand Doshi

unread,
Aug 30, 2014, 3:40:04 AM8/30/14
to ERPNext Developer's Forum
Hi Aditya,

What exactly are you trying to do?

-Anand.


To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/8ed031c2-943c-4270-bc5e-cd974ab8c246%40googlegroups.com.

Aditya Duggal

unread,
Aug 30, 2014, 3:44:18 AM8/30/14
to erpnext-dev...@googlegroups.com
Hi Anand,

I have a validation code on item master, now every time I change the validation code I would like to know if there are any items which do not satisfy the validation checks.

Now to do this I am trying to create a patch.

The other method is to import all items with a small change and then the validation is done while importing but that is a very tedious task for 9k items.
Hi,

To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+unsubscr...@googlegroups.com.

--
Note:
 
If you are posting an issue,
 
1. ERPNext is a free and open source software and support is given on this forum by a team (https://frappe.io/webnotes). So please consider donating if you find this forum useful (https://frappe.io/buy). Even a small amount would be helpful.
2. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
3. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
4. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.
 
End of Note
---
You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+unsubscr...@googlegroups.com.

--
Note:
 
If you are posting an issue,
 
1. ERPNext is a free and open source software and support is given on this forum by a team (https://frappe.io/webnotes). So please consider donating if you find this forum useful (https://frappe.io/buy). Even a small amount would be helpful.
2. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
3. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
4. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.
 
End of Note
---
You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+unsubscr...@googlegroups.com.

--
Note:
 
If you are posting an issue,
 
1. ERPNext is a free and open source software and support is given on this forum by a team (https://frappe.io/webnotes). So please consider donating if you find this forum useful (https://frappe.io/buy). Even a small amount would be helpful.
2. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
3. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
4. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.
 
End of Note
---
You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+unsub...@googlegroups.com.

Anand Doshi

unread,
Aug 30, 2014, 4:38:52 AM8/30/14
to ERPNext Developer's Forum
Can you share the code? I am not clear on what you are implying by "validation" code. Validation code is called when running "save" or other similar methods or you call it explicitly using doc.run_method("validate")

-Anand.

Aditya Duggal

unread,
Aug 31, 2014, 1:12:41 AM8/31/14
to erpnext-dev...@googlegroups.com
Hi Anand,

I have this custom code running whenever a change on item is made. I would like to check if all items are as per this code, since I make a lot of changes to this code. Now I am finding a faster way to go through this check code and I thought the patch method would be good.

Let me know how could I achieve the same.

Rushabh Mehta

unread,
Sep 1, 2014, 1:35:22 AM9/1/14
to erpnext-dev...@googlegroups.com
Do you want items to rename every time you change the logic?


--
Note:
 
If you are posting an issue,
 
1. ERPNext is a free and open source software and support is given on this forum by a team (https://frappe.io/webnotes). So please consider donating if you find this forum useful (https://frappe.io/buy). Even a small amount would be helpful.
2. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
3. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
4. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.
 
End of Note
---
You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/e8402905-2840-4c07-a229-511fc9581f5b%40googlegroups.com.

Aditya Duggal

unread,
Sep 1, 2014, 2:13:11 PM9/1/14
to erpnext-dev...@googlegroups.com
No, I just want the items to be checked if their naming is correct or not according to the code. If there is any error then it should throw an error which could let me know if there is anything wrong with the item code or something is wrong with my code itself.


On Monday, September 1, 2014 11:05:22 AM UTC+5:30, rushabh wrote:
Do you want items to rename every time you change the logic?


On 31-Aug-2014, at 10:42 am, Aditya Duggal <aditya...@gmail.com> wrote:

Hi Anand,

I have this custom code running whenever a change on item is made. I would like to check if all items are as per this code, since I make a lot of changes to this code. Now I am finding a faster way to go through this check code and I thought the patch method would be good.

Let me know how could I achieve the same.

On Saturday, August 30, 2014 2:08:52 PM UTC+5:30, Anand Doshi wrote:
Can you share the code? I am not clear on what you are implying by "validation" code. Validation code is called when running "save" or other similar methods or you call it explicitly using doc.run_method("validate")

-Anand.

--
Note:
 
If you are posting an issue,
 
1. ERPNext is a free and open source software and support is given on this forum by a team (https://frappe.io/webnotes). So please consider donating if you find this forum useful (https://frappe.io/buy). Even a small amount would be helpful.
2. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
3. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
4. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.
 
End of Note
---
You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+unsub...@googlegroups.com.

Rushabh Mehta

unread,
Sep 2, 2014, 9:04:35 AM9/2/14
to erpnext-dev...@googlegroups.com
Now you are getting into test cases :)


To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/28026380-bc0e-47d6-a0be-b2d1293dd87b%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages