Tuesday, February 7, 2017

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');
     }
   })
});

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


User Permissions in Erpnext


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.

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"


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.




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.