Migration from CGI framework to frappe

130 views
Skip to first unread message

Rohit Waghchaure

unread,
May 29, 2014, 5:42:34 AM5/29/14
to erpnext-dev...@googlegroups.com
Hi,

Is it possible to migrate CGI(responsive UI) framework to frappe? Or we have to migrate it first to WSGI i.e. Version 3.x.x and then to frappe? And if we need to migrate it to WSGI (3.x.x) then to which repository we need to point?

Regards,
Rohit

Pratik Vyas

unread,
May 29, 2014, 5:48:55 AM5/29/14
to erpnext-dev...@googlegroups.com
To migrate to version 4, all patches of version 3 have to be applied.
Version 4 doesn't have these patches.

>
> Regards,
> Rohit
>
> --
> Note:
>
> If you are posting an issue,
> 1. 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.
> 2. Paste your code at http://pastebin.com or http://gist.github.com and send
> only the URL via email
> 3. 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/566b9e84-1c32-4012-a405-78898e8c6a14%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Pratik
erpnext

MP

unread,
Jun 2, 2014, 9:31:40 AM6/2/14
to erpnext-dev...@googlegroups.com
Hi Pratik,

It will be very useful if you can provide us with a step by step instruction on how to migrate from CGI version to version 4. There are lot of us who are still using CGI version. Thanks.

Kind regards,
MP

Pratik Vyas

unread,
Jun 2, 2014, 10:46:25 AM6/2/14
to erpnext-dev...@googlegroups.com
Hi Mayur,

https://github.com/webnotes/erpnext/wiki/Migrating-your-erpnext-instance-to-wsgi

plus

https://github.com/frappe/frappe-bench#migrating-from-erpnext-version-3

should get you to version 4. It will have to be two step as we've
version 4 doesn't have the patches. Can you try migrating your
database? We'll be happy to help you through the errors you face.

Thanks,
--
Pratik
erpnext

MP

unread,
Jun 23, 2014, 6:44:08 AM6/23/14
to erpnext-dev...@googlegroups.com
Thanks Pratik,

I will try to migrate one of the clone site. I will let you know how I go. Thanks.

Kind regards,
MP

MP

unread,
Jul 14, 2014, 12:11:07 PM7/14/14
to erpnext-dev...@googlegroups.com
Hi Pratik,

As per your suggestion, we have successfully migrated from CGI to WSGI using https://github.com/webnotes/erpnext/wiki/Migrating-your-erpnext-instance-to-wsgi. But we are getting below error when following instruction from https://github.com/frappe/frappe-bench#migrating-from-erpnext-version-3. When we ran ./scripts/install.sh migrate_3_to_4 /var/www/erp-prod, we got below error message half way through.

Executing frappe.patches.v4_0.update_custom_field_insert_after in erp-prod (sirius_erp_prod)
Traceback (most recent call last):
  File "scripts/3to4.py", line 32, in <module>
    migrate(args.site)
  File "scripts/3to4.py", line 26, in migrate
    latest()
  File "/var/www/frappe-bench/apps/frappe/frappe/cli.py", line 67, in new_fn
    return fn(*args, **new_kwargs)
  File "/var/www/frappe-bench/apps/frappe/frappe/cli.py", line 417, in latest
    frappe.modules.patch_handler.run_all()
  File "/var/www/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 25, in run_all
    if not run_single(patchmodule = patch):
  File "/var/www/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 50, in run_single
    return execute_patch(patchmodule, method, methodargs)
  File "/var/www/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 66, in execute_patch
    frappe.get_attr(patchmodule + ".execute")()
  File "/var/www/frappe-bench/apps/frappe/frappe/patches/v4_0/update_custom_field_insert_after.py", line 18, in execute
    cf.save()
  File "/var/www/frappe-bench/apps/frappe/frappe/model/document.py", line 194, in save
    self.run_post_save_methods()
  File "/var/www/frappe-bench/apps/frappe/frappe/model/document.py", line 414, in run_post_save_methods
    self.run_method("on_update")
  File "/var/www/frappe-bench/apps/frappe/frappe/model/document.py", line 387, in run_method
    return Document.hook(fn)(self, *args, **kwargs)
  File "/var/www/frappe-bench/apps/frappe/frappe/model/document.py", line 463, in composer
    return composed(self, method, *args, **kwargs)
  File "/var/www/frappe-bench/apps/frappe/frappe/model/document.py", line 446, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "/var/www/frappe-bench/apps/frappe/frappe/model/document.py", line 381, in <lambda>
    fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
  File "/var/www/frappe-bench/apps/frappe/frappe/core/doctype/custom_field/custom_field.py", line 38, in on_update
    validate_fields_for_doctype(self.dt)
  File "/var/www/frappe-bench/apps/frappe/frappe/core/doctype/doctype/doctype.py", line 186, in validate_fields_for_doctype
    validate_fields(frappe.get_meta(doctype).get("fields"))
  File "/var/www/frappe-bench/apps/frappe/frappe/core/doctype/doctype/doctype.py", line 244, in validate_fields
    check_unique_fieldname(d.fieldname)
  File "/var/www/frappe-bench/apps/frappe/frappe/core/doctype/doctype/doctype.py", line 199, in check_unique_fieldname
    frappe.throw(_("Fieldname {0} appears multiple times in rows {1}").format(fieldname, ", ".join(duplicates)))
  File "/var/www/frappe-bench/apps/frappe/frappe/__init__.py", line 206, in throw
    msgprint(msg, raise_exception=exc)
  File "/var/www/frappe-bench/apps/frappe/frappe/__init__.py", line 203, in msgprint
    _raise_exception()
  File "/var/www/frappe-bench/apps/frappe/frappe/__init__.py", line 187, in _raise_exception
    raise raise_exception, msg
frappe.exceptions.ValidationError: Fieldname cost_center appears multiple times in rows 17, 41

Could you please help in resolving this error? In our existing system, we have setup cost_center custom fields for following doctypes:
- Purchase Order Item
- Purchase Receipt Item

Kind regards,
Mayur Patel



Rushabh Mehta

unread,
Jul 15, 2014, 12:41:34 AM7/15/14
to erpnext-dev...@googlegroups.com
Mayur,

Your custom fields are redundant because there are already fields with that name, so just remove them and continue the patch.


--
Note:
 
If you are posting an issue,
1. 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.
2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
3. 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.

MP

unread,
Jul 15, 2014, 6:48:37 AM7/15/14
to erpnext-dev...@googlegroups.com
Thanks Rushabh. The reason we added these fields in our existing ERPNext system because they were not there in old version of ERPNext. I am assuming that you guys have added these fields as part of these doctypes.  I am also assuming that I won't loose any existing data stored in these custom fields.

Kind regards,
Mayur Patel

Rushabh Mehta

unread,
Jul 15, 2014, 7:38:47 AM7/15/14
to erpnext-dev...@googlegroups.com
Yeah - you should not lose and data - but take a backup to be safe


--
Note:
 
If you are posting an issue,
1. 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.
2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
3. 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.

MP

unread,
Jul 15, 2014, 7:48:44 AM7/15/14
to erpnext-dev...@googlegroups.com
Hi Rushabh,

So delete these two records from 'tabCustom Field' table and then run the run ./scripts/install.sh migrate_3_to_4 /var/www/erp-prod again? I remember that last time when I try to run this script again after I got an error, it complained that 'site erp-prod already exists'. erp-prod is the name of the site. So should I delete this erp-prod folder from site directory and run the above script again? Please guide.

Kind regards,
Mayur Patel

Rushabh Mehta

unread,
Jul 15, 2014, 9:48:57 PM7/15/14
to erpnext-dev...@googlegroups.com
@Pratik can you help.

@MP - we are putting the finishing touches on a new deployment platform.


Pratik will post it later today.



@rushabh_mehta

--
Note:
 
If you are posting an issue,
1. 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.
2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
3. 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.

Pratik Vyas

unread,
Jul 16, 2014, 12:32:37 AM7/16/14
to erpnext-dev...@googlegroups.com
Hi Mayur,
Sorry for the late reply.

You can remove the Custom Field from python shell via( `frappe
--ipython erp-prod`) and use

frappe.delete_doc('Custom Field', {name})

to remove the extra fields/

You don't need to run the migrate script again. Instead, just run
`../env/bin/frappe --latest erp-prod` from the sites directory.


Thanks,
--
Pratik
erpnext

MP

unread,
Jul 16, 2014, 7:38:12 AM7/16/14
to erpnext-dev...@googlegroups.com
Thanks Pratik for your response. I have ran  ../env/bin/frappe --ipython erp-prod from inside of the site directory. I am getting below error.


Traceback (most recent call last):
  File "../env/bin/frappe", line 9, in <module>
    load_entry_point('frappe==4.1.0', 'console_scripts', 'frappe')()
  File "/var/www/frappe-bench/apps/frappe/frappe/cli.py", line 53, in main
    return run(fn, parsed_args)
  File "/var/www/frappe-bench/apps/frappe/frappe/cli.py", line 83, in run
    out = globals().get(fn)(**args)

  File "/var/www/frappe-bench/apps/frappe/frappe/cli.py", line 67, in new_fn
    return fn(*args, **new_kwargs)
  File "/var/www/frappe-bench/apps/frappe/frappe/cli.py", line 765, in ipython
    import IPython
ImportError: No module named IPython

I installed ipython using "pip install ipython". But I am still getting above error. Could you please help to resolve this? Thanks.

Kind regards,
Mayur Patel

Pratik Vyas

unread,
Jul 16, 2014, 7:39:40 AM7/16/14
to erpnext-dev...@googlegroups.com
Hi Mayur,

You will have to install ipython in the environment,

So,

./env/bin/pip install ipython #no sudo

> Kind regards,
> Mayur Patel
>
> --
> Note:
>
> If you are posting an issue,
> 1. 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.
> 2. Paste your code at http://pastebin.com or http://gist.github.com and send
> only the URL via email
> 3. 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/f5c38df6-b046-42f9-9039-cf6007f029af%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.


Thanks,
--
Pratik
erpnext

MP

unread,
Jul 16, 2014, 7:51:35 AM7/16/14
to erpnext-dev...@googlegroups.com
Thanks Pratik.

I know it has been advised not to run Frappe and ERPnext as root user. But we have been running is as root for a while. Is there any reason for not running it as root?

MP

MP

unread,
Jul 16, 2014, 8:02:54 AM7/16/14
to erpnext-dev...@googlegroups.com
Hi Pratik,

I have installed ipython in the environment and did below.

ran ../env/bin/frappe --ipython erp-prod
frappe.delete_doc('Custome Field',{'Purchase Order Item-cost_center'})
frappe.delete_doc('Custome Field',{'Purchase Receipt Item-cost_center'});

It didn't output anything. I checked the database and I can still see these two records.
 select name, fieldname from `tabCustom Field` where name like '%cost%';

+-----------------------------------+-------------+
| name                              | fieldname   |
+-----------------------------------+-------------+
| Purchase Order Item-cost_center   | cost_center |
| Purchase Receipt Item-cost_center | cost_center |
+-----------------------------------+-------------+
2 rows in set (0.00 sec)

Is above ok?

Kind regards,
MP

Anand Doshi

unread,
Jul 16, 2014, 8:35:37 AM7/16/14
to ERPNext Developer's Forum
Corrected:
frappe.delete_doc('Custom Field', 'Purchase Order Item-cost_center')
frappe.delete_doc('Custom Field', 'Purchase Receipt Item-cost_center')

Thanks,
Anand.


--
Note:
 
If you are posting an issue,
1. 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.
2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
3. 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.

Pratik Vyas

unread,
Jul 16, 2014, 8:52:00 AM7/16/14
to erpnext-dev...@googlegroups.com
You would not want any service to run as root. For example, if your
smtp server executed (due to a bug) every thing in the email body and
someone sends "rm -rf /"

A new and easier to use version of the bench is about to be released.
That would be a good opportunity for you to migrated your site to a
non-root user.

>
> MP
>
> --
> Note:
>
> If you are posting an issue,
> 1. 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.
> 2. Paste your code at http://pastebin.com or http://gist.github.com and send
> only the URL via email
> 3. 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/579329fa-8d81-4cb4-8b1c-b5734ea52730%40googlegroups.com.

MP

unread,
Jul 16, 2014, 9:43:01 AM7/16/14
to erpnext-dev...@googlegroups.com
Thanks Anand. But it didn't work either. See below:

root@doris3to4:/var/www/frappe-bench/sites# ../env/bin/frappe --ipython erp-prod
Python 2.7.3 (default, Aug  1 2012, 05:14:39)
Type "copyright", "credits" or "license" for more information.

IPython 2.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: frappe.delete_doc('Custom Field', 'Purchase Order Item-cost_center')

In [2]: frappe.delete_doc('Custom Field', 'Purchase Receipt Item-cost_center')

In [3]: quit
root@doris3to4:/var/www/frappe-bench/sites# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 63
Server version: 5.5.38-MariaDB-1~precise-log mariadb.org binary distribution

Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> use sirius_erp_prod;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [sirius_erp_prod]> select name, fieldname from `tabCustom Field` where name like '%cost%';

+-----------------------------------+-------------+
| name                              | fieldname   |
+-----------------------------------+-------------+
| Purchase Order Item-cost_center   | cost_center |
| Purchase Receipt Item-cost_center | cost_center |
+-----------------------------------+-------------+
2 rows in set (0.00 sec)

MariaDB [sirius_erp_prod]> quit
Bye
root@doris3to4:/var/www/frappe-bench/sites# ../env/bin/frappe --latest erp-prod

Executing frappe.patches.v4_0.update_custom_field_insert_after in erp-prod (sirius_erp_prod)
Traceback (most recent call last):
  File "../env/bin/frappe", line 9, in <module>
    load_entry_point('frappe==4.1.0', 'console_scripts', 'frappe')()
  File "/var/www/frappe-bench/apps/frappe/frappe/cli.py", line 53, in main
    return run(fn, parsed_args)
  File "/var/www/frappe-bench/apps/frappe/frappe/cli.py", line 83, in run
    out = globals().get(fn)(**args)
  File "/var/www/frappe-bench/apps/frappe/frappe/cli.py", line 67, in new_fn
    return fn(*args, **new_kwargs)
root@doris3to4:/var/www/frappe-bench/sites#

Message has been deleted

MP

unread,
Jul 16, 2014, 9:49:26 AM7/16/14
to erpnext-dev...@googlegroups.com
I also tried frappe.delete_doc('Custom Field', 'cost_center') but still didn't delete these custom fields.

MP

Pratik Vyas

unread,
Jul 16, 2014, 9:49:55 AM7/16/14
to erpnext-dev...@googlegroups.com

After you run the delete doc functions, run frappe.db.commit() to commit the changes.

--
Note:
 
If you are posting an issue,
1. 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.
2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
3. 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.

MP

unread,
Jul 16, 2014, 10:33:46 AM7/16/14
to erpnext-dev...@googlegroups.com
Thanks Pratik, Anand and Rushabh.

It worked. I checked the database and these two entries are not there any more. I will continue with ../env/bin/frappe --latest erp-prod.

I am currently performing this test migration on a test server before the actual migration of the production instance. For the production instance, before migration,  is it okay to delete this custom field "cost_center" through web interface and then run the migration script? Also can we use the new version of Bench to migrate from version 3 to 4? If so, will the steps be same of different? Thanks in advance.

Kind regards,
Mayur Patel

MP

unread,
Jul 16, 2014, 12:27:51 PM7/16/14
to erpnext-dev...@googlegroups.com
Hi Team,

I have managed to migrate a copy of production version to version 4. Thanks for your help. I have noticed below:

- I have come across some bugs, I will report them later.
- We had some custom server side scripts in our old version but in new version I can't find them. Where can I find them?
- We had modified some of the .py and .js file in our old version. We had added some methods in .py file and also in .js file. Before migration, I removed them manually. We would like to re-apply those customisations in the new version. I was told that in version 4 we can keep our customisation separate from the main erpnext code. I remember something about plugin in wsgi version before frappe bench. How do we achive the same in version 4? Thanks in advance.

Kind regards,
Mayur

Rushabh Mehta

unread,
Jul 17, 2014, 12:36:38 AM7/17/14
to erpnext-dev...@googlegroups.com
On 16-Jul-2014, at 9:57 pm, MP <mayur....@gmail.com> wrote:

Hi Team,

I have managed to migrate a copy of production version to version 4. Thanks for your help. I have noticed below:

- I have come across some bugs, I will report them later.
- We had some custom server side scripts in our old version but in new version I can't find them. Where can I find them?

Put them in a new app: See examples:


Since you are a subscriber - we will help you do set this up. @Anand you want to take this forward.

- We had modified some of the .py and .js file in our old version. We had added some methods in .py file and also in .js file. Before migration, I removed them manually. We would like to re-apply those customisations in the new version. I was told that in version 4 we can keep our customisation separate from the main erpnext code. I remember something about plugin in wsgi version before frappe bench. How do we achive the same in version 4? Thanks in advance.

Same as above. Will be great if you can put your customizations, each in a separate file and zip and mail to us.


Kind regards,
Mayur

--
Note:
 
If you are posting an issue,
1. 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.
2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
3. 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.

MP

unread,
Jul 17, 2014, 6:33:51 AM7/17/14
to erpnext-dev...@googlegroups.com
Thanks Rushabh.

I will email our customisations as requested..

Kind regards,
Mayur Patel

MP

unread,
Jul 21, 2014, 12:37:53 PM7/21/14
to erpnext-dev...@googlegroups.com
Hi Rushabh,

I have just emailed my customisations as requested.

Kind regards,
Mayur Patel

MP

unread,
Jul 23, 2014, 9:50:47 AM7/23/14
to erpnext-dev...@googlegroups.com
Hi There,

I need your help for the following two issues:


1) In version 3, We have written a custom script (client side) to restrict the selection of cost center to the selected company by limiting the search result of the cost center to the selected company. See below script. This helps the user as the resulting search result list is smaller and easy to pick the value from.  This custom script uses a server side function called "accounts.utils.get_cost_center_list". In new version, this function doesn’t exists in utils.py under accounts directory on the server. I tried looking for this function in the entire source code but I can’t seem to find it. Could you please help to rewrite the below script to make it work in the new version? Thanks.  Don’t you think this restriction should be included in ERPNext by default. Why would you want a user to select cost center that is not part of the selected company?


// To restrict selection of cost center for the selected company
cur_frm.fields_dict["po_details"].grid.get_field("cost_center").get_query = function(doc) {
    return {
        query: "accounts.utils.get_cost_center_list",
        filters: { company_name: doc.company}
    }
}



2) In version 3. the field name for "Expense Code" in "Purchase Invoice Item" doctype is‘expense_head’. Since we wanted to capture "Expense Code" at creation of purchaes order, we create a custom field called "expense_head" for "Purchase Order Item" doctype. This way when we create "Purchase Invoice" from  "Purchase Order" page, the expense_head fields of "Purchase Invoice Item" gets populated automatically. We did same for "Purchae Receipt Item" doctype.

But in the new version it seems that this fields has been renamed to ‘expense_account’ from "expense_head". Because of this the Expense code from Purchase Order Item/Purchase Receipt Item is not being automatically mapped on Purchase Invoice (for each line item) Page. How do we resolve it? Do I need to add new custom field called expense_head for Purchase receipt item/purchase order item and  manually copy over the data at database level for existing purchase orders/receipts? This also means rewriting the custom reports that depends on this field. Is there any other way to handle this?

Anand Doshi

unread,
Jul 25, 2014, 2:41:26 AM7/25/14
to ERPNext Developer's Forum
Hi Mayur,

Answers inline:

Thanks,
Anand Doshi.


On Wed, Jul 23, 2014 at 7:20 PM, MP <mayur....@gmail.com> wrote:
Hi There,

I need your help for the following two issues:


1) In version 3, We have written a custom script (client side) to restrict the selection of cost center to the selected company by limiting the search result of the cost center to the selected company. See below script. This helps the user as the resulting search result list is smaller and easy to pick the value from.  This custom script uses a server side function called "accounts.utils.get_cost_center_list". In new version, this function doesn’t exists in utils.py under accounts directory on the server. I tried looking for this function in the entire source code but I can’t seem to find it. Could you please help to rewrite the below script to make it work in the new version? Thanks.  Don’t you think this restriction should be included in ERPNext by default. Why would you want a user to select cost center that is not part of the selected company?


// To restrict selection of cost center for the selected company
cur_frm.fields_dict["po_details"].grid.get_field("cost_center").get_query = function(doc) {
    return {
        query: "accounts.utils.get_cost_center_list",
        filters: { company_name: doc.company}
    }
}


Cost Center seems to be a custom field in your account. You can try:
cur_frm.set_query("cost_center", "po_details", function() {
    return {
        filters: { company: cur_frm.doc.company }
    }
}
 


2) In version 3. the field name for "Expense Code" in "Purchase Invoice Item" doctype is‘expense_head’. Since we wanted to capture "Expense Code" at creation of purchaes order, we create a custom field called "expense_head" for "Purchase Order Item" doctype. This way when we create "Purchase Invoice" from  "Purchase Order" page, the expense_head fields of "Purchase Invoice Item" gets populated automatically. We did same for "Purchae Receipt Item" doctype.

But in the new version it seems that this fields has been renamed to ‘expense_account’ from "expense_head". Because of this the Expense code from Purchase Order Item/Purchase Receipt Item is not being automatically mapped on Purchase Invoice (for each line item) Page. How do we resolve it? Do I need to add new custom field called expense_head for Purchase receipt item/purchase order item and  manually copy over the data at database level for existing purchase orders/receipts? This also means rewriting the custom reports that depends on this field. Is there any other way to handle this?


Since you will also be creating a Custom Frappe App for your customisations, this mapping part can be added on the server side itself via a hook. (Though we are yet to add such a hook. I will do this while fixing the server side custom code). However it will be best to rename those fields via a custom patch, since many fieldnames have changed and you will have to fix your reports anyway.
 
Thanks.

Kind regards,
Mayur Patel

--
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.

MP

unread,
Jul 25, 2014, 6:37:54 AM7/25/14
to erpnext-dev...@googlegroups.com
Thanks Anand for your response.

See my reply inline:




On Friday, 25 July 2014 07:41:26 UTC+1, Anand Doshi wrote:
Hi Mayur,

Answers inline:

Thanks,
Anand Doshi.


On Wed, Jul 23, 2014 at 7:20 PM, MP <mayur....@gmail.com> wrote:
Hi There,

I need your help for the following two issues:


1) In version 3, We have written a custom script (client side) to restrict the selection of cost center to the selected company by limiting the search result of the cost center to the selected company. See below script. This helps the user as the resulting search result list is smaller and easy to pick the value from.  This custom script uses a server side function called "accounts.utils.get_cost_center_list". In new version, this function doesn’t exists in utils.py under accounts directory on the server. I tried looking for this function in the entire source code but I can’t seem to find it. Could you please help to rewrite the below script to make it work in the new version? Thanks.  Don’t you think this restriction should be included in ERPNext by default. Why would you want a user to select cost center that is not part of the selected company?


// To restrict selection of cost center for the selected company
cur_frm.fields_dict["po_details"].grid.get_field("cost_center").get_query = function(doc) {
    return {
        query: "accounts.utils.get_cost_center_list",
        filters: { company_name: doc.company}
    }
}


Cost Center seems to be a custom field in your account. You can try:
cur_frm.set_query("cost_center", "po_details", function() {
    return {
        filters: { company: cur_frm.doc.company }
    }
}
 

Sorry, I realised later on that this is a custom field. Thanks for the script. I have tested it. It is working fine. It was missing a ')'. I am also assuming that I can use the same script for restricting Expense Code to the selected company by changing the field name in the script.
 


2) In version 3. the field name for "Expense Code" in "Purchase Invoice Item" doctype is‘expense_head’. Since we wanted to capture "Expense Code" at creation of purchaes order, we create a custom field called "expense_head" for "Purchase Order Item" doctype. This way when we create "Purchase Invoice" from  "Purchase Order" page, the expense_head fields of "Purchase Invoice Item" gets populated automatically. We did same for "Purchae Receipt Item" doctype.

But in the new version it seems that this fields has been renamed to ‘expense_account’ from "expense_head". Because of this the Expense code from Purchase Order Item/Purchase Receipt Item is not being automatically mapped on Purchase Invoice (for each line item) Page. How do we resolve it? Do I need to add new custom field called expense_head for Purchase receipt item/purchase order item and  manually copy over the data at database level for existing purchase orders/receipts? This also means rewriting the custom reports that depends on this field. Is there any other way to handle this?


Since you will also be creating a Custom Frappe App for your customisations, this mapping part can be added on the server side itself via a hook. (Though we are yet to add such a hook. I will do this while fixing the server side custom code). However it will be best to rename those fields via a custom patch, since many fieldnames have changed and you will have to fix your reports anyway.
 

I believe you are helping us with turning our customisations into custom Frappe App. Please clarify if my understanding is not correct here. Also how do we write a custom patch to rename these fields? Sorry we haven't written any custom patch in the past.  Can I just do this at database level and manually update the report code? Or is there a better way to do it via custom patch?

 
Reply all
Reply to author
Forward
0 new messages