Hi,
I have a customapp installed in my site i have the below function for creating a new document from Opportunity. I have written the code in separate py file and added it to hooks.py but its not running, i need to import the class Opportunity, i have given as below,
from erpnext.crm.doctype.opportunity import Opportunity
Class CreateSourcingRequest(Opportunity):
def on_submit(self):
self.make_sourcing_request()
def make_sourcing_request(self):
parent = frappe.get_all("Opportunity")
child = frappe.get_all("Opportunity Item")
for row in self.items:
doc = frappe.new_doc("Sourcing Request")
doc.update({
"opportunity" : self.name,
"customer_name" : self.customer_name,
"opportunity_starting_date" : self.opportunity_starting_date,
"opportunity_closing_date" : self.opportunity_closing_date,
"probability" : self.probability,
"contact_person" : self.contact_person,
"item_code" : row.item_code,
"qty" : row.qty,
"uom" : row.uom,
"internal_sourcing_notes" : row.internal_sourcing_notes,
"ndb_mfr_pn" : row.ndb_mfr_pn,
"ndb_mfr" : row.ndb_mfr,
"ndb_uom" : row.uom,
"ndb_description" : row.ndb_description
})
doc.save(ignore_permissions=True)
frappe.db.commit()
frappe.msgprint("Sourcing Request created")
Thanks in advance!