$ cd /home/Lu/

Keep-learning Lu

18 Dec 2019

Smart Assistant Summary

Preview

Based on PWA, the idea of Smart Assistant is to help Smart Assistant User to interact with ERP5 system. For Smart Assistant, it has 4 main functions which can be totally used offline: Smart Assistant File, Smart Assistant Image, Smart Assistant Sound and Smart Assistant Text:

  • Smart Assistant File: On OfficeJS, Smart Assistant User can upload any kind of document you want; On ERP5, Smart Assistant Admin can process the file uploaded by user.
  • Smart Assistant Image: On OfficeJS, Smart Assistant Mobile User can take photos or chose the picturs to upload; Smart Assistant PC User can chose the pictures to upload (beacause to use the camera from PC would be kind of stupid). On ERP5, Smart Assistant Admin can process the image the user uploaded.
  • Smart Assistant Sound: On OfficeJS, Smart Assistant User can record the message; On ERP5, Smart Assistant Admin can process the voice message recorded by user.
  • Smart Assistant Sound: On OfficeJS, Smart Assistant User can write a text; On ERP5, Smart Assistant Admin can process the text message recorded by user.

Progress

During the period of developement, I have implemented the functions below:

  1. Make it work: files can be downloaded by Export -> Download actual document; images can be viewed; Sounds can be heard; Text can be read.
  2. Workflow: create 4 work states for Smart Assistant document: draft, processing, validated and cancelled.
  3. Worklists: according to the workflow, the Smart Assistant Admin will see the related worklists on ERP5, including “Smart Assistant [Document] to Process” and “Smart Assistant [Document] to Validate”.
  4. Query as reply: to realize the reply funtion, query_module was involved. Importantly, create a viewAS specially for serving Smart Assistant, which can edit a hyper link to reply to Smart Assistant User.
  5. Dialogs: Create 3 dialogs from Smart Assistant Documents to simplify the work for Smart Assistant Admin: Create Person, Create Expense, Create Event.
  6. Homepage on OfficeJS: create a listbox to show all the queries as notifications on the ; create a worklists for Smart Assistant User to have an idea about “Smart Assistant to Open” and “Smart Assistant to Pocessing”;
  7. Detail pages: create a query_view page; create a listbox to every Smart Assistant Document displaying a list of related queries; display the validate_state on Smart Assistant Document and Document list.
  8. Data storage: transfer and store the neccesary data.
  9. Security Setting: Create 2 roles: Smart Assistant User and Smart Assistant Admin. Smart Assistant User can create and view Smart Assistant Documents owned by him/herself as well as related queries; Smart Assistant Admin can access to all the Smart Assistant Documents and queries.
  10. Selenium test: test local functions; test synchronisation; test interation between Smart Assistant and ERP5.
  11. Security and use case test: test the security setting.

Workflow and Worklists

Creating a new workflow can be refered to Nexedi's OSOE Project. As the tutorial explained, I created a smart_assistant_workflow in portal_workflow, and apply it to every Smart Assistant portal_type in workflow_chain_type:

<workflow_chain>
 <chain>
  <type>Smart Assistant File</type>
  <workflow>edit_workflow, smart_assistant_workflow</workflow>
 </chain>
 <chain>
  <type>Smart Assistant Image</type>
  <workflow>edit_workflow, smart_assistant_workflow</workflow>
 </chain>
 <chain>
  <type>Smart Assistant Sound</type>
  <workflow>edit_workflow, smart_assistant_workflow</workflow>
 </chain>
 <chain>
  <type>Smart Assistant Text</type>
  <workflow>edit_workflow, smart_assistant_workflow</workflow>
 </chain>
</workflow_chain>

To commit it successfully, don't forget to add the necessary workflow_id into template_workflow_id_list in erp5_smart_assistant business template. Before you started to config the workflow, you can draw a draft to show how many states do you want and how do they transfer to each other. During the project, I used interation_workflow once. At that point, I was trying change the states by modifing the text_content in Smart Assistant Text. The scenario is that Smart Assistant User created a Smart Assistant Text, Smart Assistant Admin replied directly in the same field, so as long as the Admin modify the text_content, the workflow state should change automatically.

document = state_change['object']
if document.getValidationState() in ("draft","responded"):
  document.submit()

View and JIO view

In portal_skins, there view and viewAsJIO. View is for ERP5 system. The field you added in the view, means it can be display on the ERP5 interface. Meanwhile, viewAsJIO is for transfering the data from ERP5 to OfficeJS. Including view, jio_view, and other action like download, they should be defined in template_action_path_list.

Officejs

This is all about front-end, which display on OfficeJS.

gadget_officejs_smart_assistant_appcache.xml

As I mentioned before, Smart Assistant Web App is designed for being used even offline, therefore, the appcachefile becomes so important. This file should includes all the necessary front-end files (e.g. html/css/js). If you want to check if all the necessary files are recorded in appcache, you can switch your internet for good to verify if it can be used with no internet.

Add a “field” to interface

There are two different ways to add the “field” to the page, depending on the situation. When the page is corresponding to the module in ERP5, you are possibly able to add the corresponding field in the .js file. Here is a simple example to show how to add a field:

  return gadget.getDeclaredGadget('form_view')
    .push(function (form_gadget) {
          "your_validation_state": {
            "description": "",
            "title": "State",
            "default": gadget.state.validation_state,
            "css_class": "",
            "required": 1,
            "editable": 0,
            "key": "validation_state",
            "hidden": 0,
            "type": "StringField"
          }
        form_definition: {
          group_list: [[
            "left",
              ["your_validation_state"]
          ]]
        }

To validate this field, there are some prerequisites based on JIO. Let's read the code line by line. form_gadget is a defined gadget allowing you to insert more field displaying like in the form. Here we insert a field named your_validation_state, thanks to JIO, your OfficeJS App can find the field from jio_view, directly from viewAsJIO folder. Inside the ‘'{ }", they are parameters according to the "type".It means that we have different types, and to realize the field, we are supposed to tell the necessary parameters to the code. "StringField" can be the easiest one. However, you should still pay attention to the "default" parameter. Yes, this variable was define before.

	var gadget = this,
    state = {
      title: options.doc.title,
      validation_state: options.doc.validation_state,
      jio_key: options.jio_key
    };

In the end, the group_list can manage how to place field. Well, another situation is that you are not able to display the field in that way we mentioned before. You have to ask .html for help.

Add this div into the page you want to display it. You may notice that the gadget-url points to a .html file, and this file is a “page” In this case, if you want to display this div, you need relate among the display page, gadget_erp5_page_ojs_smart_assistant_worklist.html and gadget_erp5_page_ojs_smart_assistant_worklist.js. And the gadget-scope will be the key information to link the display page with the other. It should be declared like below in a .js file.

.push(function () {
  return RSVP.all([
    gadget.getDeclaredGadget('worklist'),
  ]);

router: load the portal_type

There is a router file for every OfficeJS Application. I'd like to mention a key line to interact with JIO:

<script data-renderjs-configuration="portal_type" type="text/x-renderjs-configuration">Smart Assistant Text,Smart Assistant Image,Smart Assistant Sound,Smart Assistant File,Query</script>
<script data-renderjs-configuration="parent_relative_url" type="text/x-renderjs-configuration">smart_assistant_text_module,smart_assistant_image_module,smart_assistant_sound_module,smart_assistant_file_module,query_module</script>

portal_type and parent_relative_url should be configured before you use them.

Security

Firstly, we should follow the tutorials here: How To Create Security Rules to have an idea about it. Then we can customise the security rules. This is an example of bt5/nexedi_erp5/PortalTypeRolesTemplateItem/Smart%20Assistant%20Text.xml:

  <role id='Author; Auditor; Assignor; Assignee'>
   <property id='title'>SA User</property>
   <property id='title'>SA User</property>
   <property id='description'>Smart Assistant Administrators and Users are allowed to access the module and view Texts</property>
   <multi_property id='category'>function/SmartAssistant/user</multi_property>
   <property id='base_category_script'>ERP5Type_getSecurityCategoryFromOwner</property>
   <multi_property id='base_category'>follow_up</multi_property>
  </role>

ERP5Type_getSecurityCategoryFromOwner.py

owner = object.Base_getOwnerId()

if object is None:
  return []
return {
  'Assignor': [owner],
  'Assignee': [owner],
  'Auditor': [owner],
  'Author': [owner]}

Unit Test

Unit Test is crucial because it will ensure your code will not make conflict to other existing module, meanwhile, it will ensure your app will not fail. Sometimes, we write the test after we develop to check the function, sometimes we write the test before development to ensure we realise the function.

Selenium Test

The idea of Selenium test is for ensuring the functionality of the App, especially for the interface. Writing several test to test every different function can be a good idea. Seleniun test mimics the functions of user, like click something, wait something to display, check the variable, etc.. It can be easily told from the code, here is an example.

<tr>
  <td>click</td>
  <td>//a[contains(text(), 'Smart Assistant To Open ')]</td>
  <td></td>
</tr>

Inside a <tr></tr>, you are supposed to write 3 line normally. The first line is the command, the second line is about the details, and the third line is to check up. This is a simple example to click “Smart Assistant To Open”. Since there is nothing to check up with clicking, the third line can be left like this. It is necessary that waitForElementPresent is expected. Because when the test runs automatically, you would have no idea that how long a clicking takes, most of time, this will lead to an element not found error.

Use Case Test & Security Test

These tests, writing in Python, are alway expected to be under consideration. And from my experience, these tests and related settings are associated with the custom ERP5 in general. The purpose of these tests is to test the certain user can access or manipulate the certain content, instead, the selenium test is to test the functionality itself.

Summary

Smart Assistant Application is expected to be interacted well with ERP5, which means that it would save time for ERP5 user to achieve some functions. Additionally, it is just designed for CEO at the moment. We have applied this app into practice with our CEO, Mr. Jeans-Paul SMETS. During several weeks of using (it never stops using), my tutor and I did a record list as below. According to the usage history, we make these 3 dialogs for speed up the procedure: create new person, create new event and create new expense. Query (as reply) probably can be so-called the 4th dialog. These dialogs are capable to process the most frequent events in a minute. Though the main functions have been done properly, there still exists some possible improvement.

Interface of Smart Assistant App on OfficeJS

  1. The search bar on homepage is useless, it is used for seaching Smart Assistant Documents.
  2. On the page document list, it might be more convenient if we keep the search history for users.

Smart Assistant Modules on ERP5

  1. The contents created via dialogs in the Smart Assistant modules, are expected to be associated to the original Smart Assistant Documents.
  2. It would be be better if the URL of the new content created via dialogs in the Smart Assistant modules can be automatically fill the blank in related quey.
  3. More effective dialogs are expected.
comments powered by Disqus