Developer's Guide to Empress GSuite Integration Feature

Introduction

Welcome to this comprehensive guide on the GSuite Integration feature of Empress. This feature allows you to generate GSuite documents from templates, embedding variables in both the document body and name using the Jinja2 format, and associating the document with a specific DocType as an attachment. A common use case is generating contracts using data from customers, employees, or suppliers. Let’s delve into the technicalities of this feature.

Prerequisites

Before we start, ensure you have:

  • Access to GSuite and Empress.
  • Basic understanding of DocType in Empress.

Enabling GSuite Integration

Step 1: Publish Google Apps Script

  1. Navigate to https://script.google.com.
  2. Create a new Project. Follow File > New > Project.
  3. Navigate to Desk > Explore > Integrations > GSuite Settings > Google Apps Script. Copy the code and paste it into an empty Code.gs in script.google.com.
  4. Save the Project via File > Save > Enter new project name.
  5. Deploy the app through Publish > Deploy as web app.
  6. Copy the “Current web app URL” into Desk > Explore > Integrations > GSuite Settings > Script URL.
  7. Click OK but do not close the script.

Step 2: Obtain Google Access

  1. Navigate to your Google project console at https://console.developers.google.com.
  2. In the Library, click on Google Drive API and select Enable.
  3. Navigate to Credentials > Create Credentials > OAuth Client ID.
  4. Fill the form with the following:
  • Web Application
  • Authorized redirect URI as http://{{ yoursite }}/?cmd=frappe.integrations.doctype.gsuite_settings.gsuite_settings.gsuite_callback.
  1. Copy the Client ID and Client Secret into Desk > Explore > Integrations > GSuite Settings > Client ID and Client Secret.
  2. Save GSuite Settings.

Step 3: Test Script

  1. Click on Allow GSuite Access.
  2. Click on Run Script test. You should be asked to grant permission.

Setting up GSuite Templates

Step 1: Use Google Document as Template

  1. Create a new Document or use an existing one. Set variables as needed. Variables are defined with ``, where VARIABLE is the field of your Doctype.
  2. Get the ID of the Document and the ID of the folder where you want to place the generated documents.

Step 2: Associate the Template to a Doctype

  1. Navigate to Desk > Explore > Integrations > GSuite Templates > New.
  2. Fill the form with the required details.

Creating Documents

  1. Go to a Document that has a Template (Example: Employee > John Doe).
  2. Click on Attach File.
  3. In the GSuite Document section, select the Template and click Attach.
  4. The generated document is now created and attached.
  5. Clicking on the attached document will open it inside GSuite.

In conclusion, the GSuite Integration feature enhances the versatility of Empress by allowing developers to utilize Google’s GSuite documents as templates, auto-populating them with data from specific DocTypes, and associating the resultant documents with the relevant DocTypes as attachments. This feature is particularly useful when dealing with contracts and other documents that require standard formatting with variable data.