Developing Plug-Ins - IDocFactory (Custom Accounting)

From iDempiere en

This tutorial was brought to you by Alan Lescano from LBR Localization Brazil. If you have questions, criticism or improvement suggestions, feel free to visit me (Alan.lesc1) or write me an email

Goal of this tutorial

The goal of this tutorial is to show, how you use the IDocFactory service in you plug-in project. The reason why you want to use the doc factory service is, that you can provide your own method to post accounting for core documents (invoices, shipments, payments, etc.) or for your own doc types. For our example, we will change the way invoices are accounted.


Before you start this tutorial, you should take a look at the follwing tutorials:

The workflow

After creating the plug-in and setting its dependencies, click on File>New>Others and select "Component Definition" from the Plug-in Development section.

Plugin IDocFactory Menu.png

Click on next. Select your plug-in project (OSGI folder) and choose a file name and a general name. In our example, we used "DocFactory.xml" and "" for filename/name but every other name is okay too. You don't need to set the class name yet because we haven't implemented one. Click on finish.

Plugin ITaxProviderFactory CompDefinitionTree.png

Plugin IDocFactory CompDefinition.png

The next things we will need is:

  • A Doc_Invoice (a class which extends Doc)
  • A DocFactory (a class which implements IDocFactory)

You need only one DocFactory for all your Doc_* classes. To simplify, we just copied the original class located on org.adempiere.base/src/org.compiere.acct/

Plugin IDocFactory Doc Invoice.png

The second class only implements IDocFactory and is called DocFactory. There are two methods to implement. Both images below shows complete code.

Plugin IDocFactory DocFactory.png

Plugin IDocFactory DocFactory2.png

Open the DocFactory.xml and click on the Browse button to select the DocFactory class. Add a integer property called "service.ranking" with a positive value (>0). Also add a string property called "gaap" with value "*". Obs: the value "*" means your Doc_Invoice will be used, no matter what GAAP you select on window Accounting Schema (Menu->Performance Analisys->Accounting Rules->Accouting Schema). You can also login as System, locate reference "C_AcctSchema GAAP", add a new List Validation (Ex: "Brazilian GAAP") and use its search key in the place of "*" of DocFactory.xml. In this case, your Doc_Invoice class will be used only when your organization is using the new created GAAP.

Plugin IDocFactory DocFactoryXML.png

On the Services tab, add the org.adempiere.base.IDocFactory to the "Provided Services" section.

Plugin IDocFactory DocFactoryXML Services.png

Basically thats all you need to do. Try to modify your Doc_Invoice class and create (and post) a new invoice. Your rules will be used instead of core mechanism.

Since iDempiere 9: New Document Factory Base Class



  • Make sure that in your DocFactory.xml you have a unique name (my.domainname.pluginname.DocFactory is a good idea) and that you selected the right class
  • Make sure your plug-in is activated before you log in
  • Make sure your MANIFEST.MF contains a row with "Service-Component: " and the path to your DocFactory.xml (e. g. "Service-Component: DocFactory.xml")


  • An example is explained on page 36 of this plugin PDF guide - LiberoPayroll
Cookies help us deliver our services. By using our services, you agree to our use of cookies.