Prepared by:Taranpreet Kaur & Kusum
-
Create and Start Site:
fm create sdg24.com fm start sdg24.com
-
Edit Hosts File:
su
Taranpreet-codes/TEMP  main  Go to file
Password:
root@debian:~# nano /etc/hosts
```
Add the following lines:
```plaintext
127.0.0.1 localhost
127.0.0.1 sdg24.com
```
Exit root:
```bash
root@debian:~# exit
```
- Enter Frappe Shell:
cd frappe taranpreet@debian:~/frappe$ fm shell sdg24.com
-
Create New App:
bench new-app lib_man_sys
-
Install App:
bench install-app lib_man_sys
-
Access the App:
- Open a browser and go to
sdg24.com
.
- Open a browser and go to
- Login with
username = administrator
andpassword = admin
.
It will have the following fields:
- Library Member (Link, Mandatory) - Set options to Library Member
- Full Name (Data, Read Only) - Set fetch from to Library Member
- From Date (Date)
- To Date (Date)
- Paid (Check)
Link the Library Member field to Library Member Doctype. Click on options and type Library Member.
The name will be automatically fetched from the Library Member doctype after selecting a Library Member.
It will have Is Submittable enabled and a Naming Series set as LMS.#####
.
It will have the following fields:
- Article - Link to Article
- Library Member - Link to Library Member
- Type - Select with 2 options: Issue and Return
- Date of Transaction - Date
It will have the following fields:
- Loan Period - Int
- Maximum Number of Issued Articles - Int
Open Terminal
taranpreet@debian fm shell sdg24.com
- cd apps
- ls
- cd lib_man_sys
- ls
- cd lib_man_sys
- ls
- cd lib_man_sys
- ls
- cd doctype
- ls
- cd library_membership
- ls
- nano library_membership.py
import frappe
from frappe.model.document import Document
from frappe.model.docstatus import DocStatus
class LibraryMembership(Document):
# check before submitting this document
def before_submit(self):
exists = frappe.db.exists(
"Library Membership",
{
"library_member": self.library_member,
"docstatus": DocStatus.submitted(),
# check if the membership's end date is later than this membership's start date
"to_date": (">", self.from_date),
},
)
if exists:
frappe.throw("There is an active membership for this member")
lets make changes in library transaction doctype
- cd ..
- ls
- cd library_transaction
- ls
- nano library_transaction.py
import frappe
from frappe.model.document import Document
from frappe.model.docstatus import DocStatus
class LibraryTransaction(Document):
def before_submit(self):
if self.type == "Issue":
self.validate_issue()
self.validate_maximum_limit()
# set the article status to be Issued
article = frappe.get_doc("Article", self.article)
article.status = "Issued"
article.save()
elif self.type == "Return":
self.validate_return()
# set the article status to be Available
article = frappe.get_doc("Article", self.article)
article.status = "Available"
article.save()
def validate_issue(self):
self.validate_membership()
article = frappe.get_doc("Article", self.article)
# article cannot be issued if it is already issued
if article.status == "Issued":
frappe.throw("Article is already issued by another member")
def validate_return(self):
article = frappe.get_doc("Article", self.article)
# article cannot be returned if it is not issued first
if article.status == "Available":
frappe.throw("Article cannot be returned without being issued first")
def validate_maximum_limit(self):
max_articles = frappe.db.get_single_value("Library Settings", "max_articles")
count = frappe.db.count(
"Library Transaction",
{"library_member": self.library_member, "type": "Issue", "docstatus": DocStatus.submitted()},
)
if count >= max_articles:
frappe.throw("Maximum limit reached for issuing articles")
def validate_membership(self):
# check if a valid membership exist for this library member
valid_membership = frappe.db.exists(
"Library Membership",
{
"library_member": self.library_member,
"docstatus": DocStatus.submitted(),
"from_date": ("<", self.date),
"to_date": (">", self.date),
},
)
if not valid_membership:
frappe.throw("The member does not have a valid membership")
- Go to sdg24.com`
- Login
Ctrl+G
- Search Doctype List
- Open Article
- Go to the settings
- Enable Has Web View
- Allow Guest to view
- Index Web Pages for Search
- Set Route to
articles
- Is Published field to
published
- Click Save
Add two new rows in Fields:
- Route (Data)
- Published (Select)
- Open Terminal
cd article
cd templates
ls
nano article.html
Add the following code:
{% extends "templates/web.html" %}
{% block page_content %}
<div class="py-20 row">
<div class="col-sm-2">
<img alt="{{ title }}" src="{{ image }}"/>
</div>
<div class="col">
<h1>{{ title }}</h1>
<p class="lead">By {{ author }}</p>
<div>
{%- if status == 'Available' -%}
<span class="badge badge-success">Available</span>
{%- elif status == 'Issued' -%}
<span class="badge badge-primary">Issued</span>
{%- endif -%}
</div>
<div class="mt-4">
<div>Publisher: <strong>{{ publisher }}</strong></div>
<div>ISBN: <strong>{{ isbn }}</strong></div>
</div>
<p>{{ description }}</p>
</div>
</div>
{% endblock %}
Press Ctrl+O
, then Enter
to save and Ctrl+X
to exit.
- Edit
article_row.html
nano article_row.html
Add the following code:
<div class="py-8 row">
<div class="col-sm-1">
<img alt="{{ doc.name }}" src="{{ doc.image }}"/>
</div>
<div class="col">
<a class="font-size-lg" href="{{ doc.route }}">{{ doc.name }}</a>
<p class="text-muted">By {{ doc.author }}</p>
</div>
</div>
Press Ctrl+O
, then Enter
to save and Ctrl+X
to exit.
Now, your webpage will have the updated design.
Thanks for reading!