Overriding Doctype Class hook

I have 2 custom apps : CustomA & CustomB on same bench.
Both are overriding doctype class, Sales Invoice, via hooks override_doctype_class
CustomA app installed in SiteA.
CustomB app installed in SiteB.

When logged-in to SiteB and create sales invoice, it display correct msgprint “CustomB Before Insert”.
Then on different browser’s tab, I logged-in into SiteA and create Sales Invoice. But it still showing msg “CustomB Before Insert”.

Am I doing it correctly ?

CustomA apps:
Class SalesInvoiceCustomA(SalesInvoice):
	def before_insert(self):
		frappe.msgprint("CustomA Before Insert")

CustomB apps:		
Class SalesInvoiceCustomB(SalesInvoice):
	def before_insert(self):
		frappe.msgprint("CustomB Before Insert")
  1. in your custom app hook, put path of overridden class under override_doctype_class
    like path.SalesInvoiceCustomA

  2. import SalesInvoice class in overridden SalesInvoiceCustomA module

from erpnext.accounts.doctype.sales_invoice.sales_invoice import SalesInvoice

Thanks for your reply. I already did that. The override code works but once it hit one of override method, the other won’t get called

are you sure CustomB is not installed on SiteA ? or you are trying to call both app A&B methods when working with SiteA for example

I guess, it loads the hook file of all the apps even if an app doesn’t install in a site.

Pretty sure each custom apps only installed in respective site.

After bench restart, if I create Sales Invoice on SiteA first, SiteB will use CustomA app logic.
Same if I create in SiteB first (after restart), SiteA will use CustomA app logic

Btw, I’m using Production mode.

So do you think it’s not possible to have multi apps & multi Sites on same bench ?
It’s just not the overriding class via hooks. Monkey patching also same result

It seems like a bug as Sanjay is saying. The hooks for a site should load based on whether it’s active on the site.

Ok Thank you

app.txt under site folder is common for all sites.
Ideally it should be site specific.

Currently under one frappe-bench instance you can not have different app for different site.

So if you want to use different app for different site, then create different instance of frappe-bench.

CMIIW, apps.txt is the list of all apps in frappe-bench.
Site specific apps are defined in tabDefaultValue(‘installed_apps’).
The get_hooks get the list of apps from site specific apps

Just out of curiosity, since in v14, some modules are segregated into custom apps, e.g. HRMS.
Does this issue still exists ?
For example I have 2 sites on same bench.
Site01 : erpnext only
Site02 : with erpnext + hrms

1 Like