Created
December 8, 2014 11:12
-
-
Save nabinhait/9cd5964d5a3e0be63632 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import unicode_literals | |
import frappe | |
from frappe import _ | |
from frappe.model.document import Document | |
from frappe.utils import nowdate | |
class LibraryTransaction(Document): | |
def validate(self): | |
last_transaction = frappe.get_list("Library Transaction", | |
fields=["transaction_type", "transaction_date"], | |
filters = { | |
"article": self.article, | |
"transaction_date": ("<=", self.transaction_date), | |
"name": ("!=", self.name) | |
}) | |
if self.transaction_type=="Issue": | |
msg = _("Article {0} {1} has not been recorded as returned since {2}") | |
if last_transaction and last_transaction[0].transaction_type=="Issue": | |
frappe.throw(msg.format(self.article, self.article_name, | |
last_transaction[0].transaction_date)) | |
else: | |
if not last_transaction or last_transaction[0].transaction_type!="Issue": | |
frappe.throw(_("Cannot return article not issued")) | |
if self.transaction_date != nowdate(): | |
frappe.throw(_("Transaction can only be made at current date")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sir, its Still not working. I replaced my code with yours then also.
for eg. if i am selecting transaction_date 10-12-2014 and today it is 08-12-2014. its saving the form and not showing the given error.