View source | Discuss this page | Page history | Printable version   
Toolbox
Main Page
Upload file
What links here
Recent changes
Help

PDF Books
Show collection (0 pages)
Collections help

Search

ERP 2.50:Developers Guide/How to develop a new window/it

Contents

Obiettivo

The objective of this how-to is to show how you can create a new window from scratch. The how-to starts with creating a new table and then takes you on to creating the window itself and adding it to a module.

The how-to is based on the following scenario: imagine we are developing an HR module and we need a window that will enable the user to input salaries of employees. We also need to track the employee's salary so history records need to be preserved. Each salary record needs to have a Valid From Date field that indicates when a particular salary came into being. The record belonging to a particular employee with the latest Valid From Date is the salary that is valid today. Note that employees are already inside the system contained in the C_BPARTNER database table and indicated by the C_BPARTNER.ISMEPLOYEE column. Therefore, we only need to create a database table that will hold the actual salaries.

Modulo

All new developments must belong to a module that is not the core module. Please follow the How to create and package a module section to create a new module.

Bulbgraph.png   Note the DB Prefix defined there is HT which will explicitely indicate the prefix of our new database table!

Creazione di nuove tabelle nel database

Let's introduce a new database table called HT_SALARY that will hold the required data. Notice the HT prefix of the table name indicating the module this table belongs to.

The new HT_SALARY table must include the AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated and UpdatedBy fields that are mandatory and required for security and auditory purposes of the application.


Column name Type Length Note
HT_SALARY_ID CHAR 32 The primary key of the table that must follow the table name followed by the _ID.
AD_CLIENT_ID CHAR 32 Indicates which client (company) the record belongs to (multitenancy).
AD_ORG_ID CHAR 32 Indicates which organization (city/department/location) within a client a record belongs to.
ISACTIVE CHAR 1 This is intended for deactivating records that are not valid anymore but are referenced within the system and hence cannot be deleted.
CREATED DATE Date/time of creation of a record.
CREATEDBY CHAR 32 Foreign key to AD_USER indicating the user that created this record.
UPDATED DATE Date/time of last update of a record.
UPDATEDBY CHAR 32 Foreign key to AD_USER indicating the user that last updated this record.
C_BPARTNER_ID CHAR 32 Employee this salary belongs to.
AMOUNT NUMBER 10 The actual amount of the salary.
C_CURRENCY_ID CHAR 32 Foreign key to C_CURRENCY indicating the currency the amount is in.
VALIDFROM DATE Date that this salary is valid from.

To create the above table within the database, use one of the following CREATE TABLE statements depending on the DB you are using:

PostgreSQL

CREATE TABLE HT_SALARY
(
  HT_SALARY_ID  CHARACTER VARYING(32)		NOT NULL,
  AD_CLIENT_ID  CHARACTER VARYING(32)		NOT NULL,
  AD_ORG_ID     CHARACTER VARYING(32)		NOT NULL,
  ISACTIVE      CHARACTER(1)                   NOT NULL        DEFAULT 'Y',
  CREATED       TIMESTAMP WITHOUT TIME ZONE 	NOT NULL 	DEFAULT now(),
  CREATEDBY     CHARACTER VARYING(32)		NOT NULL,
  UPDATED       TIMESTAMP WITHOUT TIME ZONE 	NOT NULL 	DEFAULT now(),
  UPDATEDBY     CHARACTER VARYING(32)         	NOT NULL,
  C_BPARTNER_ID CHARACTER VARYING(32)         	NOT NULL,
  AMOUNT	 NUMERIC 	      	        NOT NULL,
  C_CURRENCY_ID VARCHAR(32)         	        NOT NULL,
  VALIDFROM     TIMESTAMP WITHOUT TIME ZONE    NOT NULL,
    CONSTRAINT HT_SALARY_ISACTIVE_CHECK CHECK (isactive = ANY (ARRAY['Y'::bpchar, 'N'::bpchar])),
    CONSTRAINT HT_SALARY_KEY PRIMARY KEY (HT_SALARY_ID), 
    CONSTRAINT HT_SALARY_AD_ORG FOREIGN KEY (AD_ORG_ID)
     REFERENCES AD_ORG (AD_ORG_ID), 
    CONSTRAINT HT_SALARY_AD_CLIENT FOREIGN KEY (AD_CLIENT_ID)
     REFERENCES AD_CLIENT (AD_CLIENT_ID),
    CONSTRAINT HT_SALARY_C_BPARTNER FOREIGN KEY (C_BPARTNER_ID)
     REFERENCES C_BPARTNER (C_BPARTNER_ID), 
    CONSTRAINT HT_SALARY_C_CURRENCY FOREIGN KEY (C_CURRENCY_ID)
     REFERENCES C_CURRENCY (C_CURRENCY_ID)
);

Registrazione della tabella nel Dizionario Applicazione

The following steps register the newly created table within the Openbravo ERP Application Dictionary.

For this purpose, first log into Openbravo ERP using a username with access to System Administrator role. Navigate to Application Dictionary || Tables and Columns and create a new record as shown in the screenshot below:


CreateWindow1.png


Main fields of this window are (for more information see the AD_Table table description):

Save this record then press Create columns from DB button to create columns within the Column tab automatically.


CreateWindow2.png


Once the creation process has finished, you will be informed of the number of columns that have been added to this table.


CreateWindow3.png


Switch to Column tab to see all the columns that were created according to their definition within the database. You can now additionally alter the properties of each column. Each column is assigned a reference (which defines the data type) depending on its name and its data type. Run Synchronize Terminology process (Application Dictionary || Synchronize Terminology). For more information see the AD_Column table description.


CreateWindow4.png


This process tries to find an existing application element (within the currently developed module) and thus its label, help and description and if one is not found, a new one is created. This enables a centralized translation of the application/module.


CreateWindow5.png


Each table must have at least one column marked as an identifier. The actual values of identifier columns later get concatenated to be shown to the user as a representation of a particular record (see the link to the Sales Order within the Sales Invoice window). These identifiers will also be used to construct dropdown lists of records of that particular table. By default all columns with column name Name are set as an identifier. In case there is no column with this Name, no identifier is set and needs to be done so manually or compilation will fail.

Bulbgraph.png   NOTE: The columns that are named line or seqNo are used to contain the sequence number of a record (i.e. the number of a line in an invoice). They take a default value like:

@SQL=SELECT COALESCE(MAX(ColumnName),0)+10 AS DefaultValue FROM TableName WHERE xxParentColumn=@xxParentColumn@

The WHERE part of this clause needs to be replaced with the required values. The code that should appear here is the name of the column which links with the id of the parent one. For example, each record of the C_InvoiceLine belongs to a particular C_Invoice record and they are all sequenced. C_Invoice is the parent table for the lines saved in C_InvoiceLine. This table has a column named line and the default value that it takes is:

@SQL=SELECT COALESCE(MAX(LINE),0)+10 AS DefaultValue FROM C_INVOICELINE WHERE C_INVOICE_ID=@C_INVOICE_ID@

Most of the columns in our specific HT_SALARY case will be automatically detected correctly, however, some need revising:

Openbravo ERP now knows about the new HT_SALARY database table and how to treat it in terms of its definition and the representation to the user.

Creazione di una nuova finestra

Using the System Administrator role navigate to Application Dictionary || Windows, Tabs and Fields. Create a new record as indicated by the screenshot below:


CreateWindow6.png

Although in the image the name used is Employee Salaries, it is an error and should be Employee Salary

Main fields of this window are (for more information see the AD_Window table description):


Save this record and move to Tab tab. Create a new record as shown below, creating the first tab to show the employee information:


CreateWindow7.png

Main fields of this window are (for more information see the AD_Tab table description):


Save this record and then click the Copy Tab Fields button to copy fields from the existing main tab of the Business Partner window into our new one. Select the Business Partner-Business Partner Tab - Window combination and confirm the dialog with OK.


CreateWindow7.5.png


Move to Field tab to see all the created fields.


CreateWindow8.png


If required, changes to these fields could be made or new ones could be added manually. For more information see the AD_Field table description. However, in our case we are happy with the way they are.

Now, go back to Tab tab and create a new record that will represent the child tab of the Employee tab where salaries will be managed:


CreateWindow9.png


Most importantly, make sure you select:

For more information see the AD_Tab table description.

By clicking and confirming the Create Fields dialog, the application will automatically insert the columns of the selected table into the fields tab of the Salary one.

Then, move to Field Sequence tab to define which fields will be displayed (right side) and which not (left side) and the order of displayed ones (up and down arrows). See the snapshot below to order them according to common look and feel of other windows and Save.


CreateWindow10.png


For Openbravo to create links (labels that appear blue) to table elements, the system needs to know which window represents the table where a certain element resides. In our case, the Employee Salary window is used to manage the content of the HT_Salary database table. Hence, all salary records need to be shown within that window. To indicate that go to the Application Dictionary || Tables and Columns window, find our HT_Salary table and set the Window as indicated below:


CreateWindow11.png

Creare la voce di menu

A menu item is required for the user to be able to call up the new window we developed. Using the System Administrator role navigate to General Setup || Application || Menu and create a new record:


CreateWindow12.png


Main fields of this window are (for more information see the AD_Menu table description):

Save this record then click on Tree icon CreateWindow13.png.

Her you can drag and drop the new Employee Salary menu item to any of the other menu groups.


CreateWindow14.png

Compilare l'applicazione con la Nuova Finestra

Finally, the application needs to be recompiled in order to generate the new window's code and deploy it to Tomcat. If using Eclipse, use the eclipse.compile ant task and enter Employee Salary into the dialog that pops up. If manually compiling Openbravo, use the ant compile.development -Dtab='Employee Salary'

Important note: once the compilation has finished, restart Apache Tomcat server. In Windows, it is best to stop the Tomcat before running the build task and the start it again afterwards since Windows locks certain files the the compile.development build task might not be able to copy over.

See more on Build Tasks.

Il Risultato

Using the Openbravo Admin role, select the link to the new window from the menu. Notice the new window and the two tabs hierarchically positioned one above another (one Employe can have one or more salary records):


CreateWindow15.png


By double clicking John Moneymaker, details of this employee appear, however in a read-only mode (notice all fields are gray).


CreateWindow16.png


Then by moving on to the Salary tab, you will see an empty grid since we have not entered any salaries yet. Use the create new icon to create a new salary record as indicated below.


CreateWindow17.png


Save.

You have now successfully created your own new window and seen how it came to life within Openbravo ERP. Congratulations!

Retrieved from "http://wiki.openbravo.com/wiki/ERP_2.50:Developers_Guide/How_to_develop_a_new_window/it"

This page has been accessed 1,474 times. This page was last modified on 14 June 2011, at 11:04. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.