Overridding standard doctype py

Hi,

I want to add some logic in stock_entry.py when user clicks get items button to load items from BOm and production order.

But I want to put my customization in my custom app. How to override/append standard doctype py?

I tried using doc_events via my app hooks but didn’t work. What event to use here? What is the proper way to append or overwrite standard doctype.py via our own custom app?

2 Likes

@jof2jc,

you can override the get_items button trigger and add your own frappe.call, please check

1 Like

@makarand_b actually I want to add logics in get_items method inside stock_entry.py. this method is executed by many triggers e.g. User start production, manufacture an item etc… not just when user click get_items button. How to append this server side?

Thanks

Check this post

@makarand_b can you elaborate more

frappe.ui.form.on("Stock Entry", {
  get_items: function(frm) {
	  if(frm.doc.production_order || frm.doc.bom_no) {
			console.log('hey...');
			frappe.call({
				method: "custom1.custom1.doctype.testdoctype.testdoctype.test_method",
				callback: function(r) {
					console.log(r); 
				}
			});
		} 
}
});

my testdoctype.py:

 class testdoctype(Document):

    @frappe.whitelist()
    	def test_method(self):
    	    msgprint("call me")

Why the method is not called…

have been playing many ways …then I get stuck here…

AttributeError: 'StockEntry' object has no attribute 'custom1.custom1.doctype.testdoctype.testdoctype.test_method'

js code:

frappe.ui.form.on("Stock Entry", {
  get_items: function(frm) {
	var me = this;
	var doc = frm.doc;
	  if(frm.doc.production_order || frm.doc.bom_no) {
			console.log('hey...');
			return frappe.call({
				doc,
				method: "custom1.custom1.doctype.testdoctype.testdoctype.test_method",
				//args: { self: frm.doc },
				callback: function(r) {
					console.log(r); 
					//if(!r.exc) refresh_field("items");
				}
			});
		}
}
});

console.log(‘hey’) did appear on browser console means it’s triggered…the path is correct…Anybody has ideas?

don’t pass the doc to frappe.call if you have added the whitelisted method in your custom app.

Passing doc in frappe.call will call the object’s method, as Stock Entry don’t have a custom1.custom1.doctype.testdoctype.testdoctype.test_method it is throwing an error.

@makarand_b yes you’re correct. thanks

Actually what I need is…I just want to add some lines of **if** logic inside stock_entry.py in method get_items This method is triggered when production_order with BOM is filled or the user click the '‘Get Items’ button.

How to add logic or override this method through our own app?

What I did is copy paste stock_entry.py into testdoctype.py:

@frappe.whitelist()
	def get_items(self):
		self.set('items', [])
		self.validate_production_order()

		if not self.posting_date or not self.posting_time:
			frappe.throw(_("Posting date and posting time is mandatory"))

		self.set_production_order_details()
......

in js:

frappe.ui.form.on("Stock Entry", {
  get_items: function(frm) {
	var me = this;
	  if(frm.doc.production_order || frm.doc.bom_no) {
			console.log('hey...');
			return frappe.call({
				method: "custom1.custom1.doctype.testdoctype.testdoctype.get_items",
				callback: function(r) {
					console.log(r); 
					//if(!r.exc) refresh_field("items");
				}
			});
		}
	}
});

And got “the resource is not found…”

I’m sure the path is correct…cause if I remove original stock_entry.py codes then replace it with simple test_method inside testdoctype.py then it worked…

What’s the proper way in doing this? Searching the forums but still don’t find the answer

Thanks

1 Like

I have the exact same question.

I have a custom app I have created. I have properly configured its methods, and it finds the route when run directly from python console. However, when I set up a custom script for Sales Invoice to find the method specified and imported within the custom app (which has also been successfully installed) I get the following message:

Not found
The resource you are looking for is not available

So, I need help in the following:

A client side .js that calls vía frappe.call a server side .py that resides within the custom app folders. Initially, a custom script attached vía the WSGI to Sales Invoice DocType. Eventually, I would like ideas as on how to specify where I could place the JavaScript file with the custom script, which ideally would reside on the custom app folder, for easy installation!

Can you try bench update or delete compiled py files.

Regards

I am also looking the same to override standard doctype salary_slip.py with its custom script.

Thanks,

1 Like

ERPNext V13 - Override Standard doctype classes.

file location mytestapp/mytestapp/override/custsalslip.py

import frappe, erpnext
from frappe import _
from erpnext.payroll.doctype.salary_slip.salary_slip import SalarySlip
class CustSalSlip(SalarySlip):
     
      def custom_mothed(..........)

Update hooks.py in your custom app

# DocType Class 
# ---------------
# Override standard doctype classes

override_doctype_class = {
	"Salary Slip": "mytestapp.override.custsalslip.CustSalSlip"
}