How to Extend erpnext.stock.LandedCostVoucher?

Hello everyone,

I am trying to extend the erpnext.stock.LandedCostVoucher class in ERPNext, but I’m encountering errors. Specifically, I’m getting the following error when attempting to extend it:
Uncaught TypeError: Class extends value undefined is not a constructor or null

I tried the following approaches, but none of them worked:

// Attempt 1
erpnext.stock.LandedCostVoucher = class LandedCostVoucher extends erpnext.stock.StockController {};

// Attempt 2
erpnext.stock.LandedCostVoucher = class LandedCostVoucher extends erpnext.stock.LandedCostVoucher {};

// Attempt 3
CustomLandedCostVoucher = erpnext.stock.LandedCostVoucher;
erpnext.stock.LandedCostVoucher = CustomLandedCostVoucher;

Despite erpnext.stock being defined, erpnext.stock.LandedCostVoucher is undefined at the time my custom script runs.

Has anyone successfully extended this class before? Could this be an issue with the script load order or the way LandedCostVoucher is defined?

Any guidance or examples would be greatly appreciated!

Thanks in advance!

check the reference: