ERP 2.50:Developers Guide/How To Create a Client or Organization/it
Languages: |
Contents |
Obiettivo
Vediamo come creare un client o una organizzazione via codice, senza alcuna interazione utente.
Vi sono due servlets che creano un nuovo client (Initial Client Setup) o una nuova organizzazione (Initial Organization Setup). Questi processi eseguono molte operazioni , come creare utenti, piani contabili, ruoli, etc. Insomma, tutte le azioni necessarie per avere un nuovo client o una organizzazioni funzionante nel sistema, pronto da usare.
In early releases of Openbravo, this was just possible through user interface, as all the code was into a servlet. Starting from MP19 (for Initial Client Setup) or MP25 (for Initial Organization Setup), all the code has been moved to a standard Java Class, so the whole process can be run without any user interaction requirement. This is useful, for example, in case a module wants to run the Initial Client Setup (or Initial Organization Setup) process through code, without any user interaction or interface; let's imagine, for example, a web service that receives the request of creating the new client (or organization).
Introduzione
The org.openbravo.erpCommon.businessUtility.InitialClientSetup class do have a public method called createClient, that returns an OBError object. This is the function that performs every required tasks in order to have a new client. Equivalent to this is the org.openbravo.erpCommon.businessUtility.InitialOrgSetup.createOrganization method. The org.openbravo.erpCommon.businessUtility.InitialSetupUtility class provides a set of static methods to perform some of the tasks.
There exists a public getOrg() function in both InitialClientSetup and InitialOrgSetup classes. It returns an String with all the information about the result of the execution, in a format suitable to be printed to the user.
Un esempio
Configurazione Iniziale del Client
Let's see how a new client can be created. First of all, let's stablish all the values required to create it: C_Currency_ID of the currency of the new client:
String strCurrency = "102";
Name of the new client:
String strClientName = "My New Client";
Name of the admin user of the new client
String strClientUserName = "Admin User of My New Client";
Password of the strClientUserName user
String strPassword = "Secret";
If client must install reference data of any module installed, let's provide all the AD_Module_Id strings. The format must be the one used to build a where statement in a SQL query:
String strModules = "('0AE82B43254E4F89ABEFA67083310061', '9CA816571C2E41D99A23348314F5E20A', '0', 'ADC0AE6BF2D84BC396A3B8DA22B173D0', '1D14940980084643A20EA3B191AE1029', 'A918E3331C404B889D69AA9BFAFB23AC', '557BCA691F594404B65A8394D75A25B1', 'C5F9F56B2F2D4494A2756EB42EE59CFB')";
String for "Account":
String strAccountString = Utility.messageBD(this, "Account_ID", vars.getLanguage()); if (strAccountString == "Account_ID") strAccountString = "Account";
String for "Calendar":
String strCalendarString = Utility.messageBD(this, "C_Calendar_ID", vars.getLanguage()); if (strCalendarString == "C_Calendar_ID") strCalendarString = "Calendar";
Whether an accounting schema will be created for the client, or not:
Boolean bCreateAccounting = true;
CSV file provided to create the chart of accounts. In FileItem format:
org.apache.commons.fileupload.FileItem file = vars.getMultiFile("inpFile");
Set of booleans to set if accounting dimensions must be created for:
- Business Partner
Boolean bBPartner = true;
- Product
Boolean bProduct = true;
- Campaign
Boolean bCampaign = false;
- Sales Region
Boolean bSalesRegion = false;
Now, let's create a new instance of the class, and call to the suitable method:
org.openbravo.erpCommon.businessUtility.InitialClientSetup ics = new org.openbravo.erpCommon.businessUtility.InitialClientSetup(); OBError obeResult = ics.createClient(vars, strCurrency, strClientName, strClientUserName, strPassword, strModules, strAccountString, strCalendarString, bCreateAccounting, file, bBPartner, bProduct, bProject, bCampaign, bSalesRegion);
And print the result:
System.out.println(obeResult.getMessage()+"\n"+ics.getLog();
Configurazione Iniziale dell'Organizzazione
Let's see how a new organization can be created. The only required value in the class constructor, is the client for which it will belong the new organization:
org.openbravo.erpCommon.businessUtility.InitialOrgSetup ios = new org.openbravo.erpCommon.businessUtility.InitialOrgSetup(OBContext.getOBContext().getCurrentClient());
Let's retrieve all the necessary data for the organization creation: Name of the new organization:
String strOrganization = "My New Organization";
Name of the admin user for the new organization:
String strOrgUserName = "My New Organization Admin";
Type of organization code, according to: 0-Organization, 1-Legal with accounting, 2-Generic, 3-Legal without accounting.
String strOrgType = "1";
AD_Org_ID of the organization to which the new one belong to
String strParentOrg = "0";
C_Location_ID that belongs to the location of the new organization. Empty if none.
String strcLocationId = "";
Password of the admin user of the organization
String strPassword = "Secret";
If organization must install reference data of any module installed, let's provide all the AD_Module_Id strings. The format must be the one used to build a where statement in a SQL query:
String strModules = "('0AE82B43254E4F89ABEFA67083310061', '9CA816571C2E41D99A23348314F5E20A', '0', 'ADC0AE6BF2D84BC396A3B8DA22B173D0', '1D14940980084643A20EA3B191AE1029', 'A918E3331C404B889D69AA9BFAFB23AC', '557BCA691F594404B65A8394D75A25B1', 'C5F9F56B2F2D4494A2756EB42EE59CFB')";
Whether to create accounting schema or not:
Boolean bCreateAccounting = true;
CSV file provided to create the chart of accounts. In FileItem format:
org.apache.commons.fileupload.FileItem file = vars.getMultiFile("inpFile");
C_Currency_ID of the currency of the new client:
String strCurrency = "102";
Set of booleans to set if accounting dimensions must be created for:
- Business Partner
Boolean bBPartner = true;
- Product
Boolean bProduct = true;
- Campaign
Boolean bCampaign = false;
- Sales Region
Boolean bSalesRegion = false;
Source path of the instance
String strSourcePath = vars.getSessionValue("#SOURCEPATH");
Let's create the organization:
OBError obeResult = ios.createOrganization(strOrganization, strOrgUserName, strOrgType, strParentOrg, strcLocationId, strPassword, strModules, bCreateAccounting, file, strCurrency, bBPartner, bProduct, bProject, bCampaign, bSalesRegion, strSourcePath);
And print the result:
System.out.println(obeResult.getMessage()+"\n"+ios.getLog();
Languages: |