Wednesday, July 20, 2016

How to create a simple HTML table using Custom script in erpnext ?

  • Add a custom HTML field in your target doctype (doctype that will show the table)
  • Add the code below as a custom script for the target doctype
frappe.ui.form.on('Target Doctype', 'refresh', function(frm, cdt, cdn){
   frappe.call({
     'method': 'frappe.client.get_list',
     'args': {
       'doctype': 'Source DocType',
       'columns': ['*']
       'filters': [['Source DocType', 'link_reference', '=', frm.doc.name]]
     },
     'callback': function(res){
         var template = "<table><tbody>{% for (var row in rows) { %}<tr>{% for (var col in rows[row]) { %}<td>rows[row][col]</td>{% } %}</tr>{% } %}</tbody></table>",
        frm.set_df_property('html_fieldname', 'options', frappe.render(template, {rows: res.message});
        frm.refresh_field('html_fieldname');
     }
   })
});

Tuesday, July 19, 2016

Erpnext-Sample Print Format for Quotation Module

To create a new Print Format


  • Go to Setup->Print Format
  • Select Doctype-Example :- Quotation
  • Tick Custom Doctype Checkbox 
  • Select Print Format Type as Server
  • Write print format code into Text box


{% if letter_head and not no_letterhead -%}

    <div class="letter-head">{{ letter_head }}</div>

    <hr>

{%- endif %}


<small>

<big>

<p class="text-center"><b>{{ _("Quotation") }}</b></p><br>

</big>


<div class="row">    

     <div class="col-xs-6">        

        <div class="row">

            <div class="col-xs-5 text-right"><big><b>Customer Name</b></big></div>

            {%- if doc.customer -%}

                <div class="col-xs-6 "><big>{{ doc.customer or '' }}</big> </div>

            {%- else -%}

                <div class="col-xs-6 "><big>{{ doc.customer_name or '' }}</big> </div>

            {%- endif -%}

        </div>

             

    </div>


    <div class="col-xs-6">

        <div class="row">

            <div class="col-xs-6 text-right"><big><b>Quotation No</b></big></div>

            <div class="col-xs-6 "><big>{{ doc.name or '' }}</big> </div>

        </div>

        <div class="row">

            <div class="col-xs-6 text-right"> <big><b>Date</b></big> </div>

            <div class="col-xs-6 "><big>{{ doc.get_formatted("transaction_date") or '' }}</big>                  </div>

        </div>

   

    </div>

         

</div>


<br>

<br>


<table class="table table-condensed table-hover table-bordered">

  <tbody>

    <tr>

      <th>Sr</th>

      <th>Item</th>

      <th class="text-right">Qty</th>

      <th class="text-right">Rate</th>

      <th class="text-right">Amount</th>

    </tr>

    {%- for row in doc.items -%}


    <tr>

      <td style="width: 3%;">{{ row.idx }}</td>


      <td style="width: 50%;">{{ row.item_code}}    </td>

      <td style="width: 8%; text-align: right;">{{ row.qty }} </td>

      <td style="width: 15%; text-align: right;">{{

        row.get_formatted("rate", doc) }}</td>

      <td style="width: 15%; text-align: right;">{{

        row.get_formatted("amount", doc) }}</td>

       


      </tr>

    {%- endfor -%}

    {%- if doc.discount_amount -%}

    <tr>

         <td colspan="4"><b>{{ _("Net Total") }}</b> </td>

         <td style="width: 8%; text-align: right;"><b>{{ doc.get_formatted("total") or '' }} </b></td>

    </tr>

    <tr>

         <td colspan="4"><b>{{ _("Discount") }}</b> </td>

         <td style="width: 8%; text-align: right;"><b>{{ doc.get_formatted("discount_amount") or '' }} </b></td>

    </tr>

 {%- endif -%}

    <tr>

         <td colspan="4"><b>{{ _("Total : ") }}{{ doc.in_words or '' }}</b> </td>

         <td style="width: 8%; text-align: right;"><b>{{ doc.get_formatted("grand_total") or '' }} </b></td>

    </tr>

  </tbody>

</table>

<br>


<div class="row">

 <div class="col-xs-12 text-left"><big>{{ doc.terms or '' }}</big></div>

</div>

</small>


Result



Monday, July 18, 2016

User Permissions in Erpnext

User Permissions




Limit access for a User to a set of documents using User Permissions Manager
Role Base Permissions define the periphery of document types within which a user with a set of Roles can move around in. However, you can have an even finer control by defining User Permissions for a User. By setting specific documents in User Permissions list, you can limit access for that User to specific documents of a particular DocType, on the condition that "Apply User Permissions" is checked in Role Permissions Manager.
To start with, go to:
Setup > Permissions > User Permissions Manager


User Permissions Manager displaying how users can access only a specific Company.

Sunday, July 17, 2016

Permission and Roles in erpnext

ERPNext implements permission control at the User and Role level. Each user in the system can be assigned multiple roles and permissions.

1.Types of Roles in Erpnext




The most important role is the "System Manager". Any user having this role can add other users and set roles to all users.


Role Based Permissions








ERPNext has a role-based permission system. It means that you can assign Roles to Users, and set Permissions on Roles. The permission structure also allows you to define different permission rules for different fields, using a concept called Permission "Level" of a field. Once roles are assigned to a user, it gives you the ability to limit access for a user to only specific documents.
To start with, go to:
Setup > Permissions > Role Permissions Manager

Permissions are applied on a combination of:
  • Roles: As we saw earlier, Users are assigned to Roles and it is on these Roles that permission rules are applied.
    Examples of Roles include Accounts Manager, Employee, HR User.
  • Document Types: Each type of document, master or transaction, has a separate list of Role based permissions.
    Examples of Document Types are Sales Invoice, Leave Application, Stock Entry, etc.
  • Permission "Levels": In each document, you can group fields by "levels". Each group of field is denoted by a unique number (0, 1, 2, 3, etc.). A separate set of permission rules can be applied to each field group. By default all fields are of level 0.
    Permission "Level" connects the group of fields with level X to a permission rule with level X.
  • Document Stages: Permissions are applied on each stage of the document like on Creation, Saving, Submission, Cancellation and Amendment. A role can be permitted to Print, Email, Import or Export data, access Reports, or define User Permissions.
  • Apply User Permissions: This switch decides whether User Permissions should be applied for the role on selected Document Stages.
    If enabled, a user with that role will be able to access only specific Documents for that Document Type. Such specific Document access is defined in the list of User Permissions. Additionally, User Permissions defined for other Document Types also get applied if they are related to the current Document Type through Link Fields.
    To set, User Permissions go to:
    Setup > Permissions > User Permissions Manager


Users in Erpnext

In ERPNext, you can create multiple users and assign them different roles. 

There are some users which can only access the public facing part of ERPNext (i.e. the website). Such users are called "Website Users".

Users using ERPNext in the company are. called "System Users"







1.Adding Users
Users can be added by the System Manager. If you are a System Manager, you can add Users via
Setup > User
1. List of Users

To add a new user, click on "New"

2. Add the user details

Add user details such as First Name, Last Name, Email etc.
The user's Email will become the user id.
After adding these details, save the user.

3. Setting Roles

After saving, you will see a list of roles and a checkbox next to it. Just check the roles you want the user to have and save the document. To click on what permissions translate into roles, click on the role name.

4. Setting Module Access

Users will have access to all modules for which they have role based access. If you want to block certain modules for certain users, un-check the module from the list.

5. Security Settings

If you wish to give the user access to the system only between office hours, or during weekends, mention it under security settings.





Saturday, July 16, 2016

Add Letter Head To Erpnext Print

Letter Heads



You can manage multiple letter heads in ERPNext. In a letter head you can:
  • Create an image with your logo, brand and other information that you want to put on your letter head.
  • Attach the image in your Letter Head record by clicking on image icon to automatically generate the HTML required for this Letter Head.
  • If you want to make this the default letter head, click on “Is Default”.
Your letter head will now appear in all Prints and Emails of documents.
You can create / manage Letter Heads from:
Setup > Printing > Letter Head > New Letter Head

Example



This is how the letter head looks in a document print:


Flow Chart Of Transactions In ERPNext

This diagram covers how ERPNext tracks your company information across key functions. This diagram does not cover all the features of ERPNext.



Friday, July 15, 2016

Introduction to CRM

CRM helps you track business Opportunities from Leads and Customers.
The CRM Module helps maintain Leads, Oppurtunities and Customers.

-Lead

To get the customer through the door, you may be doing all or any of the following:


  • Listing your product on directories.
  • Maintaining an updated and searchable website.
  • Meeting people at trade events.
  • Advertising your product or services.
When you send out the word that you are around and have something valuable to offer, people will come in to check out your product. These are your Leads.

-Opportunity
When you know a Lead is looking for some products or services to buy, you can track that as an Opportunity.

An Opportunity can also come from an existing Customer. You can create multiple Opportunities against the same Lead. In Opportunity, apart from the Communication.

-Difference between Lead, Contact and Customer
The difference is that a Lead is a potential Customer, someone who can give you business. A Customer is an organization or individual who has given you business before (and has an Account in your system). A Contact is a person who belongs to the Customer.
A Lead can be converted to a Customer by clicking on the “Create Customer” button. Once the Customer is created, the Lead becomes “Converted” and any further Opportunities from the same source can be created against the Customer.

What is ERP?

ERP is an acronym for Enterprise Resource Planning. ERP is business process management software that allows an organisation to use a system of integrated applications to manage the business and automate many back office functions related to technology, services and human resources.


Friday, July 8, 2016

Adding comment to a Doctype using Custom Script

Use frm.timeline.insert_comment("Comment", "comment_value") to add new comment 

Example

frappe.ui.form.on("Item Price", { refresh: function(frm) { frm.timeline.insert_comment("Comment", frm.doc.price_list_rate) } });

Wednesday, July 6, 2016

Bench Commands Cheatsheet

White Listed Method

To make REST call or want to access method from js you need to make those methods as whitelisted.
@frappe.whitelist() is Decorator for whitelisting a function and making it accessible via HTTP.Standard request will be `/api/method/[path.to.method]` :param allow_guest: Allow non logged-in user to access this method. Use a @frappe.whitelist() def myfunc(param1, param2): pass ExampleJavascriptfrappe.call({ method: "erpnext.crm.doctype.opportunity.opportunity.get_item_details", args: {"item_code":d.item_code}, callback: function(r, rt) { if(r.message) { alert(r.message.item_name) } })Python@frappe.whitelist() def get_item_details(item_code): item = frappe.db.sql("""select item_name, stock_uom, image, description, item_group, brand from `tabItem` where name = %s""", item_code, as_dict=1) return item.item_name

Get Doctype Field Value Using Python

get_value (self, doctype, filters=None, fieldname=name, ignore=None, as_dict=False, debug=False, cache=False)
Returns a document property or list of properties.
Parameters:
  • doctype - DocType name.
  • filters - Filters like {"x":"y"} or name of the document. None if Single DocType.
  • fieldname - Column name.
  • ignore - Don't raise exception if table, column is missing.
  • as_dict - Return values as dict.
  • debug - Print query in error log.
Example:
# return first customer starting with a
frappe.db.get_value("Customer", {"name": ("like a%")})

# return last login of **User** `test@example.com`
frappe.db.get_value("User", "test@example.com", "last_login")

last_login, last_ip = frappe.db.get_value("User", "test@example.com",
    ["last_login", "last_ip"])

# returns default date_format
frappe.db.get_value("System Settings", None, "date_format")

Update Field Value In Other Doctype Using Python

Use frappe.get_doc in a function and call it accordingly

doc = frappe.get_doc(doctype-name, document-name)

# get property
doc.title

# set property to the document
doc.first_name = 'My Name'

# save a document to the database
doc.save()

Tuesday, July 5, 2016

Custom Script-Get Values from Server

To fetch value from server use frappe.client.get_value


frappe.call({
            "method": "frappe.client.get_value",
            args: {
                doctype: "ToDo",
                fieldname: 'name',
                filters: { reference_name: frm.doc.name },
            },
            callback: function (r) {
             alert(r.message.name)

            }});

Monday, July 4, 2016

Custom Script-Fetch Values From Master

To pull a value of a link on selection, use the add_fetch method.
add_fetch(link_fieldname, source_fieldname, target_fieldname)Examplecur_frm.add_fetch('customer','vat_id','vat_id')

Saturday, July 2, 2016

ERPNext - ERP made simple

ERPNext is a fully featured ERP system designed for Small and Medium Sized business. ERPNext covers a wide range of features including Accounting, CRM, Inventory management, Selling, Purchasing, Manufacturing, Projects, HR & Payroll, Website, E-Commerce and much more.


ERPNext is based on the Frappe Framework is highly customizable and extendable. You can create Custom Form, Fields, Scripts and can also create your own Apps to extend ERPNext functionality.
Installation

Linux: 
wget https://raw.githubusercontent.com/frappe/bench/master/install_scripts/setup_frappe.sh
sudo bash setup_frappe.sh --bench-branch develop