0% found this document useful (0 votes)
86 views4 pages

Task Script

The document contains JavaScript and Python code for a sign-up and order placement functionality in a web application using the Frappe framework. The Sign up form validates user credentials and redirects to the Place Order form upon successful login, while the Place Order form calculates totals based on menu items and quantities. The code also includes methods for handling user input, displaying messages, and managing form states.

Uploaded by

rathinamdinesh92
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views4 pages

Task Script

The document contains JavaScript and Python code for a sign-up and order placement functionality in a web application using the Frappe framework. The Sign up form validates user credentials and redirects to the Place Order form upon successful login, while the Place Order form calculates totals based on menu items and quantities. The code also includes methods for handling user input, displaying messages, and managing form states.

Uploaded by

rathinamdinesh92
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Singup.

js

frappe.ui.form.on("Sign up", {
login : function(frm){
if(frm.doc.username && frm.doc.password){
frappe.call({
method:
'my_app.sample.doctype.sign_up.sign_up.valid',
args: {
user: frm.doc.username,
pwd: frm.doc.password
},
callback: function (response) {
if (response.message === true) {
frappe.msgprint(__('Login successful!
Redirecting...'));
frappe.set_route('Form','Place Order');
}
else {
frappe.msgprint(__('Invalid Login.'));
frm.set_value('username', '');
frm.set_value('password', '');
}
}
})
}
else{
frappe.msgprint(__('Please enter both username and
password.'));
}

},
cancel :function(frm){
frm.set_value('username', '');
frm.set_value('password', '');
}
});

Signup.py

import frappe
from frappe.model.document import Document

class Signup(Document):
pass

@frappe.whitelist()
def valid(user,pwd):
signup = frappe.get_doc("Basic",{"username": user, "password":
pwd})
if signup:
return True
else:
return None

Place Order.js

frappe.ui.form.on("Place Order", {
refresh: function (frm) {
calculate_row_total(frm)
},
paid: function (frm) {
frappe.msgprint(__("Bill Generated Successfully!!..."))
frm.save();
},
cancel: function(frm){
frm.delete();
frappe.set_route('Form','Sign up');
},

id : function(frm){
if(frm.doc.id){
frappe.call({
method:
'my_app.sample.doctype.place_order.place_order.get_name',
args: {
B_id: frm.doc.id
},
callback: function (response) {
if (response.message) {
console.log(response);
frm.set_value('name1',
response.message.name1);
}
else {
frappe.msgprint(__('Invalid ID...'));
frm.set_value('id', '');
}
}
})
}
else{
frappe.msgprint(__('Please enter the ID.'));
}
}
});
frappe.ui.form.on("Menu child", {
menu_item: function(frm,cdt,cdn){
let row = locals[cdt][cdn];
if (row.menu_item) {
frappe.db.get_value('Menu', row.menu_item, 'price',
(value) => {
row.price = value.price;
frm.refresh_field('order_item');
calculate_row_total(frm, row);
});
}
},
quantity: function (frm, cdt, cdn) {
let row = locals[cdt][cdn];
calculate_row_total(frm, row);
},
price: function (frm, cdt, cdn) {
let row = locals[cdt][cdn];
calculate_row_total(frm, row);
}
});

// Function to calculate row total


function calculate_row_total(frm, row) {

let total = row.quantity * row.price || 0;


row.total = total; // Original total
frm.refresh_field('order_item'); // Refresh the child table fields
calculate_grand_total(frm);
}

function calculate_grand_total(frm) {
let total_bill = 0;
frm.doc.order_item.forEach((item) => {
let total = item.total || 0; // Get the total for each row
total_bill += total; // Sum the total amount for all items
});
frm.set_value('total_bill', total_bill); // Set the grand total in
the parent doctype
}

Place Order.py
import frappe
from frappe.model.document import Document

class PlaceOrder(Document):
pass

@frappe.whitelist()
def get_name(B_id):
name = frappe.get_doc('Basic',B_id)
if name:
return {"name1": name.name1}
else :
return None

You might also like