I generally also flush the toilets with clear-cache and migrate. They seem to work like a sort of digital garlic, claimed as a panacea for all sorts of ERPNext ills, and seemingly harmless, so I just call them whenever I’ve been hacking around inside or simply things get a little blue around the gills.
erpdev@fossa:~/frappe-bench-DENH$ bench --site dev.erpnext.host clear-cache
erpdev@fossa:~/frappe-bench-DENH$ bench --site dev.erpnext.host migrate
Updating DocTypes for frappe : [========================================] 100%
Updating DocTypes for erpnext : [========================================] 100%
Updating Dashboard for frappe
Updating Dashboard for erpnext
Updating customizations for Address
Updating customizations for Contact
Building search index for dev.erpnext.host
The goal is to track down how and why the basic_rate value in a Stock Entry from a Work Order from a Bill of Materials is wrong. So, having decided on a likely suspect bit of code, we insert web_pdb.set_trace():
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import web_pdb # <======= YOO! HOO! It's me. Right here! See!
: : : : :
def set_basic_rate(self, reset_outgoing_rate=True, raise_error_if_no_rate=True):
Set rate for outgoing, scrapped and finished items
web_pdb.set_trace() # <======= ... and me again right HERE!!!
outgoing_items_cost = self.set_rate_for_outgoing_items(reset_outgoing_rate)
finished_item_qty = sum([d.transfer_qty for d in self.items if d.is_finished_item])
# Set basic rate for incoming items
for d in self.get('items'):
if d.s_warehouse or d.set_basic_rate_manually: continue
The next step is to restart the bench. You don’t want the Supervisor running for this because you will lose visibility on a lot of valuable logging information. So do:
As an extra step, you can dig into NGinx and have it expose port 5555 as an SSL port in order to be able to access the debugger with a modern browser that automatically redirects to HTTPS. Have fun!
There’s an easier way in Chrome. Open the link:
Scroll right down to the bottom, stuff your server URL into the “Domain” field of “Delete domain security policies” and click on the [Delete] button
From then on, Chrome will permit plain old HTTP access to that address.
The next step is to generate the Stock Entry by Finishing the Work Order:
When you do that, Python code on the server for the Work Order will call into the Stock Entry DocType. Part way through it will hit the web-pdb code we inserted. Your ERPNext browser page is likely to start whining and bitching about server errors and time outs, but you don’t care about that right now.
In the command line at the very bottom you can enter ad hoc Python3 commands to examine the data involved in the function you are examining. You set break points by clicking code line numbers and you can use the buttons to step through the code in various ways.
Best of all : inspect !!!
Here below you can see I can examine every attribute a one of the Item docs just by typing … inspect d
I highly recommend this instead of changing code directly on a server and exposing your server through the browser.
@MartinHBramwell the way the VSCode’s SSH Remote feature works is that VSCode will connect to the server over SSH and it will work as if you were using VSCode on that server directly. This allows you to securely connect to the server and run whatever you want.
But honestly, I would avoid debugging on a live server in the first place. That’s just bad practice. Take a database dump and load it in a local environment which is as close to production as possible.