Download as pdf or txt
Download as pdf or txt
You are on page 1of 48

Bench Frappe ERPNext

Technical Training
Introduction
Bench Command Line Utility

Frappe Framework

ERPNext
Installation
Bench

git clone https://github.com/frappe/bench bench-repo

pip install -e bench-repo


New Project

bench init [project-name] Options :

--frappe-path [path-frappe-repo]

--frappe-branch [branch-name]
Setup Remote Database

bench set-mariadb-host [IP/ADDRESS] Pastikan :

1. User root dapat


diakses secara
remote pada saat
instalasi
2. Membuka port mysql
pada server database
New Site

bench new-site [sitename] 1. --db-name [database-name]


untuk memberi nama database secara
manual (tidak random generated)
2. Membutuhkan akses user root database
3. Membuat password baru untuk
administrator
DNS Multitenant

bench config dns_multitenant on File pada


sites/currentsite.txt
harus kosong
Get App

bench get-app [appname] [git-path] ● mengambil branch default


dari apps
● --branch [branch-name]
untuk mengambil branch
tertentu
New App

bench new-app [appname]


Install App

bench --site [sitename] install-app [appname]


Development Server

bench start ● site dapat diakses dari localhost:8000


● multisite dapat diakses masing masing
dari [sitename]:8000 jika mengaktifkan
dns_multitenant dan menambahkan
[sitename] pada host file
● tambahkan "developer_mode": 1
pada
sites/common_site_config.jso
n
Production Server

bench setup production


Structure
Structure

Project App

Database
Customization
Doctype

Setup > Customize > Doctype


Customize Form

Setup > Customize > Customize Form


Print Format

Setup > Printing > Print Format


Custom Report :
Report Builder
Workflow

Setup > Workflow > Workflow


Permission Level

Setup > Permission > Role Permissions Manager


Custom Script

Setup > Customize > Custom Script


Custom Script (1) - Event Trigger
frappe.ui.form.on( "Doctype Name" , { ● [trigger] :
○ [field_name]
[trigger]: function(frm) { ○ onload
○ onload_post_render
}
○ refresh
○ validate
});
Custom Script (2) - Data Manipulation
frm.doc.[field_name] frm.set_value( [field_name] , [value])

frm.refresh_field( [field_name] )

frm.doc.[field_name] = [value]
Custom Script (3) - Field Property Manipulation
frm.get_docfield(" field_name") frm.set_df_property( "field_name" ,
"property" , "value")

frm.get_docfield(" table_name" ,
"field_name") var df =
frappe.meta.get_docfield( "Child
Doctype", "child_fieldname" ,
cur_frm.doc.name)

df.[property] = value
Custom Script (4) - AJAX Call
frappe.call({ Contoh method frappe client :
method:"frappe.client.get",
args: { ● frappe.client.get
doctype: "Item",
● frappe.client.get_list
name: "Item-00001"
}, ● frappe.client.get_single_valu
callback: function(r) { e
} ● frappe.client.set_value
});
Custom Script (5) - Limit Dropdown List
frm.fields_dict[ 'field_name' ].get_query = function(doc, cdt, cdn) {

return {

filters:{'field_condition' : 'condition' }

}
Custom Script (6) - Trigger Event
frm.script_manager.trigger( event_name )
Custom Script (7) - Insert New Record to Table
row = frappe.model.add_child(cur_frm.doc, doctype, table_name );

row.item_code = 'blablabla' ;

. . .

frm.refresh_field( table_name )
Custom Report :
Query Report
Server Side Script
Server Script (1) - Trigger Event
from __future__ import unicode_literals ● [trigger]:
import frappe ○ before_insert
from frappe.model.document import Document ○ validate
○ on_update
class DoctypeName (Document): ○ on_submit
def [trigger](self): ○ on_cancel
pass ○ on_trash
○ autoname
Server Script (2) - Self Data
self.[field_name] self.[field_name] = value

self.save()

self.submit()

self.cancel()

self.delete()
Server Script (3) - Another Doc Data
doc = frappe.get_doc(doctype, name) doc.[field_name] = value

doc.[field_name] doc.save()

doc.submit()

doc.cancel()

doc.delete()
Server Script (4) - Another (Many) Doc Data
frappe.get_all(doctype, filters, fields)

frappe.get_list( doctype, filters, fields)


Server Script (5) - Get Single Doctype Data
doc = frappe.get_single( doctype)
Server Script (6) - SQL Query
result = frappe.db.sql(query, as_dict=0, as_list=0)
Server Script (7) - Check User Permission
frappe.has_permission( doctype)
Server Script (8) - Whitelist Function
@frappe.whitelist()

def whitelisted_function (*args, **kwargs):

return
Server Script (9) - Popup Message
frappe.msgprint( message)

# popup exception

frappe.throw(message, exception)
Custom Report :
Script Report
Hooks
Webhooks

Integrations > Webhook > Webhook


Testing
Unit Testing
bench run-tests ● Options :
○ --app {appname}
○ --doctype {doctype_name}
○ --module {module_name}
○ --test {test_name}
UI Testing

You might also like