Hi All,
I’ve created a custom doctype with Version 13 previously and I have a custom submit method that was suppose to run on submission of a document but it seems like Version 14 isn’t calling the submit method anymore when clicking on submit
class BatchPrinter(Document):
def __init__(self, *arg, **kwargs):
super().__init__(*arg, **kwargs)
self.loss_account = "82550 - Realized Exchange Gain/Loss Account - MRO" # To do: add to interface instead of static
self.check_counter = self.check
self.payment_entry = [] if not self.get("payment_entries") else self.get("payment_entries")
self.party_type = "Supplier"
self.payment_type = "Pay"
self.company_currency = get_default_currency()
def validate(self):
if not self.account:
frappe.throw("Missing account to pay from")
self.currency = get_account_details(self.account, self.posting_date).get("account_currency")
def fetch_invoices(self):
invoice_filters = [
["bill_date", "between", [self.from_posting_date, self.to_posting_date]],
["outstanding_amount", "!=", 0],
["currency", "=", self.currency],
["docstatus", "=", 1]
]
if self.supplier_filter:
supplier_currency = frappe.get_value("Supplier", self.supplier_filter, "default_currency")
account_currency = frappe.get_value("Account", self.account, "account_currency")
if supplier_currency != account_currency:
frappe.throw(
msg="""Supplier's currency is {} but the currency of the account to pay from is {}. Please make sure both currency match and try again"""
.format(supplier_currency, account_currency),
title="Supplier Currency and Account to pay against Currency doesn't match")
invoice_filters.append(["supplier", "=", self.supplier_filter])
invoice_list = frappe.get_list("Purchase Invoice", filters=invoice_filters,
fields=["supplier", "name", "currency", "grand_total", "base_grand_total",
"posting_date",
"outstanding_amount", "credit_to", "docstatus"])
for line in invoice_list:
doc = frappe.get_doc("Purchase Invoice", line)
pi_status = None
if doc.docstatus == 0:
pi_status = "Draft"
elif doc.docstatus == 1:
pi_status = "Submitted"
else:
pi_status = "Warning"
self.append("invoice", {
"supplier_name": doc.supplier,
"purchase_invoice": doc.name,
"currency": doc.currency,
"supplier_invoice": doc.bill_no,
"amount": doc.grand_total,
"pi_status": pi_status,
"base_amount": doc.base_grand_total,
"posting_date": doc.posting_date,
"outstanding_amount": doc.outstanding_amount,
"account_paid_to": doc.credit_to
})
def before_save(self):
if self.invoice:
return
else:
self.fetch_invoices()
def submit(self):
try:
self.process_payments()
except Exception as e:
frappe.msgprint(e, "Error on creating payment entry")
for payment in self.payment_entry:
doc = frappe.get_doc("Payment Entry", payment)
doc.cancel()
self.payment_entry = []
if self.payment_entry:
for i in self.payment_entry:
self.append("payment_entries", i)
super().submit()
Is it correct that version 14 doesn’t call the submit method anymore? I tried debugging on submission of sales order and it seems like there was no call to submit method in the Document class