I am using frappe.call method from client side and send object with it. I want this object in before_save defination that was call before the document saved.
When I access this object in before_save controller its show error out of range and not found.
And then use self.__parent_details. Anyways i find a lot of weird things in this code. Maybe you want to do it in another method not called “before_save”? It is a hook method, and it will not have your custom parameter when called. Maybe you can do this:
before_save is a hook called by frappe directly as part of a document’s lifecycle. There is no way to pass an object to this method. If you want to use an object passed to a whitelisted method in before_save, you’ll have to save it as a property of the doctype somewhere in the whitelisted method. Then, before_save will be able to access it.
The suggest made by @peterg is a good one. For example, I like to create new objects inside 'flags' in my Documents.
First, I’ll set the flag when it’s appropriate:
customer_doc.flags.run_special_function = True
Then in a controller method like 'before_save', I add a condition:
class Customer(Document):
def before_save(self):
if hasattr(self.flags, 'run_special_function') and self.flags.run_special_function is True:
# additional logic to perform
...
Thanks brian!
Kindly take a look on code that you suggest. Its not print anything.
def before_save(self, *args, **kwargs):
if hasattr(self.flags, 'run_special_function') and self.flags.run_special_function is True:
print(self.__parent_details)
frappe.delete_doc("Brick Wise Sale",self["name"])
I troubleshoot that problem. When we make object of parent_detail in whitelist defination but it will not access in before_save controller. It’s not set into the doctype.