Hello,
I have a method that adds a child item to a doctype and then saves it (add_voucher_consumption).
The child item has the “on submit” enabled so that it can be triggered after the doc is submitted (I want this to be the case as I want to be able to consume submitted vouchers).
However, the self.save() of this function does not seem to trigger the update_after_submit or on update methods. For the moment my workaround is to trigger the function (check_voucher_consumption) at the end of my method but ideally it should be performed automatically whenever the submitted document is updated as specified in the controller methods.
I am not sure if this is a bug or not
class CustomerReferralVoucher(Document):
def validate(self):
self.check_customer()
self.check_voucher_consumption()
def on_update_after_submit(self):
self.check_voucher_consumption()
def on_update(self):
self.check_voucher_consumption()
def check_voucher_consumption(self):
voucher_value = self.voucher_value
if not self.voucher_consumption:
self.voucher_residual_value = voucher_value
else:
sum_value = sum(row.value for row in self.voucher_consumption)
if sum_value == voucher_value:
self.voucher_residual_value = 0
self.status = "Depleted"
elif sum_value < voucher_value:
residual = voucher_value - sum_value
self.voucher_residual_value = residual
else:
frappe.throw(_("Voucher Consumption ({0}) higher than voucher value of {1}").format(sum_value, voucher_value))
def add_voucher_consumption(self,value):
self.append('voucher_consumption', {
'value': value,
'date': today()})
#self.check_voucher_consumption() >> ADDED as workaround
self.save(ignore_permissions=True)