Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@nabinhait
Created December 8, 2014 11:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nabinhait/9cd5964d5a3e0be63632 to your computer and use it in GitHub Desktop.
Save nabinhait/9cd5964d5a3e0be63632 to your computer and use it in GitHub Desktop.
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"))
@djagtap
Copy link

djagtap commented Dec 8, 2014

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment