On_cancel delete document

Hi,

i have some function to create new document and also and also delete documents were created when canceled

def create_plasma_daily_statistics(self, action, table_row):
	#get data from plasma document
	plasma_doc = frappe.get_cached_doc('Plasma', table_row.plasma)

	#get posting date
	posting_date = datetime.strptime(self.posting_date, constants.FORMAT_DATE)

	#get plasma daily statistics based on plasma name
	plasma_daily_statistics = self.get_plasma_daily_statistics(plasma=table_row.plasma, posting_date=posting_date)

	#get the previous day plasma statistics
	previous_day_plasma_daily_statistics = self.get_plasma_daily_statistics(plasma=table_row.plasma, posting_date=posting_date - timedelta(days=1), fields=["feed_intake_cumulative", "cumulative_depletion", "current_population"])

	#previous_day_plasma_daily_statistics = frappe.get_all("Plasma Daily Statistics", filters={"posting_date": posting_date - timedelta(days=1), "plasma": table_row.plasma}, fields=["feed_intake_cumulative", "cumulative_depletion", "current_population"], limit_page_length=1)
	daily_depletion = table_row.culled + table_row.mortality

	if previous_day_plasma_daily_statistics is None and action == "submit":
		feed_intake_cumulative = table_row.feed_intake
		cumulative_depletion = daily_depletion
		current_population = plasma_doc.original_population - daily_depletion
	elif action == "cancel":
		current_population = previous_day_plasma_daily_statistics[0].current_population
	else:
		feed_intake_cumulative = previous_day_plasma_daily_statistics[0].feed_intake_cumulative + table_row.feed_intake
		cumulative_depletion = previous_day_plasma_daily_statistics[0].cumulative_depletion + daily_depletion
		current_population = plasma_doc.current_population - daily_depletion
		
	plasma_doc.current_population = current_population
	plasma_doc.save()

	# create plasma daily statistics based on plasma growth recording data
	if action == "submit":
		new_plasma_daily_statistics = frappe.get_doc({
			"doctype": "Plasma Daily Statistics",
			"plasma_growth_recording": self.name,
			"posting_date": self.posting_date,
			"plasma": table_row.plasma,
			"culled": table_row.culled,
			"mortality": table_row.mortality,
			"uniformity_percentage": table_row.uniformity_percentage,
			"feed_type": table_row.feed_type,
			"feed_intake": table_row.feed_intake,
			"body_weight": table_row.body_weight,
			"age": table_row.age,
			"original_population": plasma_doc.original_population,
			"current_population": current_population,
			"population_live_percentage": (current_population/plasma_doc.original_population) * 100,
			"cumulative_depletion": cumulative_depletion,
			"depletion_percentage": table_row.depletion_percentage,
			"feed_intake_cumulative": feed_intake_cumulative,
			"feed_conversion_ratio": feed_intake_cumulative / table_row.body_weight
			})
		new_plasma_daily_statistics.insert()
	else:
		frappe.delete_doc("Plasma Daily Statistics", plasma_daily_statistics)

and this my on_cancel function

def on_cancel(self):
	self.create_plasma_daily_statistics(action="cancel")
	self.reload()

everytime i cancel the document, there is an error notification

TypeError: create_plasma_daily_statistics() missing 1 required positional argument: ‘table_row’

then i try to fill table_row attribute with None, but this is what happened

AttributeError: ‘NoneType’ object has no attribute ‘plasma’

I have no idea what going on, thank you

Got the same issue. Have you resolved it?