-
-
Save djagtap/b902af4900ec1570ae8b to your computer and use it in GitHub Desktop.
Want to restrict Date to current system date
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
I want to restrict the date field, like t=only the current system date should be available to be selected. | |
So what function i need to add and where? pls help me with the solution. | |
The following is the library_transaction.py filecode of mine | |
from __future__ import unicode_literals | |
import frappe | |
from frappe import _ | |
from frappe.model.document import Document | |
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")) | |
------------------------------------ | |
now library_transaction.js of mine is | |
frappe.ui.form.on("Library Transaction", "library_membership", | |
function(frm) { | |
frappe.call({ | |
"method": "frappe.client.get", | |
args: { | |
doctype: "Library Membership", | |
name: frm.doc.library_membership | |
}, | |
callback: function (data) { | |
frappe.model.set_value(frm.doctype, | |
frm.docname, "member_name", | |
data.message.member_first_name | |
+ (data.message.member_last_name ? | |
(" " + data.message.member_last_name) : "")) | |
frappe.model.set_value(frm.doctype, | |
frm.docname, "is_paid_member", | |
((data.message.paid == 0) ? "No" : "Yes")) | |
} | |
}) | |
}); | |
=================================== | |
@Nabin as You Said- "You should write the following code in validate:" | |
and so i did but still not able to restrict to make only current system date enable(Selectable). May be i am palcing it at a wrong place. Please correct me if so... | |
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