Calling a python method which is located inside a class from js

Hi I’d like to call a method which is located inside a class from js. The method is located in (apps/erpnext/erpnext/stock/doctype/stock_entry/

What if I want to call get_feed() from js or atleast from other python method outside the class?

The above code while trying to create an instance of StockEntry throws some error.

Any help is greatly appreciated.

1 Like

@vwithv1602 StockEntry class should have a parameter StockController so you cannot instantiate StockEntry without the parameter.

Bai Web and Mobile Lab

When you say we cannot instantiate, do you mean there is no other way to call that method? If there is some way, please let me know the solution.

I’ve tried a couple of things as described below.

I’m not sure on how to pass that StockController while instantiating. Can you help?

Tried by passing directly and it throws error again.

se = StockEntry(StockController)

also tried to instantiate StockController and then passing it to StockEntry which also failed.

sc = StockController()
se = StockEntry(sc)


class StockController(AccountsController):
	def validate(self):

StockController class has a parameter AccountsController you need to supply that.

Bai Web and Mobile Lab

In your previous comment, I clearly understood that I need to supply StockController for StockEntry class. Similarly, for this StockController, there needs to be AccountsController. And for AccountsController there’s TransactionBase and for TransactionBase there’s StatusUpdater and for StatusUpdater there’s Document parameter and finally for Document there should be BaseDocument. I tried all those before posting this question here.
The code what I’ve tried is in the below screenshot, which didn’t work either. I know that object parameter should be passed in BaseDocument (highlighted in the image)… but don’t know what should be that object.
And when I execute it, the ERROR is:

The error says BaseDocument() accepts 2 arguments and only 1 given.
The BaseDocument() code is something like this…

What object should be passed to this BaseDocument??

I really appreciate your replies to my question, but as I feel this conversation is becoming lengthy without actual solution, It would be excellent if you can help me by telling HOW EXACTLY WE CAN MAKE A CALL TO THAT StockEntry() FUNCTION

Sorry if I’m giving you pain but I’d be extremely thankful to you if you can provide me a simple example (a working piece of code) which can call that function.

I think the question is what are trying to do? Do you want to add record in stock entry doctype? If it is the case you are doing it wrong. You can use frappe.get_doc or use. save()

Developer Cheatsheet · frappe/frappe Wiki · GitHub

I’ve another new doctype where repack in StockEntry is simplified. I’m using that new doctype for people who are not aware of how to use Stock Entry doctype to do repack of goods. Now I need to call the same submit action of StockEntry after clicking on Submit in new doctype. I’ll be sending data to that on_submit of Stock Entry.

As an example,
I created EasyRepack doctype.
Users will input Items Taken, Taken From Warehouse, Items Given and Given To Warehouse field.
Mapping will be done in backend like Taken From Warehouse maps to Source Warehouse and Given To Warehouse maps to Target Warehouse and also other fields will be mapped accordingly.
And then finally call submit method of Stock Entry

Hope you get what I’m trying to do. Please let me know if it still not clear.

Can anyone please help??

I think the better approach is in your EasyRepack on submit create a necessary Stock Entry DocType using frappe.get_doc or .insert.

Thanks @ccfiel,
We are using what you have said earlier but with a small problem in it. So trying in other way to overcome. But anyways got the solution by this approach (the approach you said in the previous post).

Document mapping to create a necessary Stock Entry DocType is the best approach.

Thanks a ton for you valuable time… :slightly_smiling_face: