hi,
new to frappe development to learn frappe development i am following a library management tutorial for this link
https://frappe.github.io/frappe/user/en/tutorial/controllers
i reached the chapter controller of first lesson and i followed instructions for validating about the library transaction but i not getting any validation after i write below code in library transaction.py file
from future import unicode_literals
import frappe
from frappe.model.document import Document
class LibraryMembership(Document):
# validating is book issued or member exist
# validatae is a frappe event handler it will automatically called
def validate(self):
#select transaction,transaction_date from library_transacton where
#transaction_date<= user selected date and name= user selected date
last_transaction = frappe.get_list(“Library Transaction”,fields=[“transaction_type”,“transaction_date”],
filters = {“article”:self.article,“transaction_date”:(“<=”, self.transaction_date),“name”:(“!=”,self.name)
})
#checking user selected mode of transaction and if it is issue below code will work
if self.transaction_type==“Issue”:
# this msg will generate pop on prensatation layer which say selected article has not been returned since the last issued date
msg = (“Article {0} {1} has not been recorded as returned since {2}”)
# check in last transaction is issue and if it is then it will throw message using frappe.throw
# this error message has name of article,date of last transaction
if last_transaction and last_transaction[0].transaction_type==“Issue”:
frappe.throw(msg.format(self.article,self.article_name,last_transaction[0].transaction_date))
# if user selcted transaction is return
else:
# checks for the last transaction table is empty or last transaction is return
# if yes throw an error cannot return non issued books
if not last_transaction or last_transaction[0].transaction_type!=“Issue”:
frappe.throw((“Cannot return not issued”))
i have added comments to explain what i understand about the code if it is wrong please help me to correct myself so that i can improve in frappe development thanks