Developing Plug-Ins - ITaxProviderFactory

From iDempiere en

This How-To 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 How-To

The goal of this How-To is to show, how you use the ITaxProviderFactory service in you plug-in project. The reason why you want to use the tax provider factory service is, that you can provide your own method for calculating taxes on orders, invoices and RMAs.

Prerequisites

Before you start this How-To, you should take a look at the following How-Tos:

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 ITaxProviderFactory 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 "TaxProviderFactory.xml" and "org.idempierelbr.tax.TaxProviderFactory" 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 ITaxProviderFactory CompDefinition.png

The next things we will need is:

  • A TaxProvider (a class which implements ITaxProvider)
  • A TaxProviderFactory (a class which implements ITaxProviderFactory)

You need only one TaxProviderFactory for all your TaxProvider (just in case you have more than one). Create the class DefaultTaxProvider which implements org.adempiere.model.ITaxProvider and implement the inherited abstract methods.

Plugin ITaxProviderFactory DefaultTaxProvider.png

The second class only implements ITaxProviderFactory and is called TaxProviderFactory. In newTaxProviderInstance() we check the class name configurable in Tax Provider Configuration window (see below).

Plugin ITaxProviderFactory TaxProviderFactory.png

Open the TaxProviderFactory.xml and click on the Browse button to select the TaxProviderFactory class. Also add a integer property called "service.ranking" with a positive value (>0).

Plugin ITaxProviderFactory TaxProviderFactoryXML.png

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

Plugin ITaxProviderFactory TaxProviderFactoryXML Services.png

Now, you should configure your Client to use the new tax provider.

Plugin ITaxProviderFactory TPConfigWindow.png

Plugin ITaxProviderFactory TPWindow.png

And now, configure the Tax Rate to use the tax provider. In this case, we are using the Standard tax.

Plugin ITaxProviderFactory TaxRateWindow.png

Basically that's all you need to do. To see that we really did something, we've added a console log in each method of DefaultTaxProvider class. Make sure that your plug-in is active in the run configurations. Start the client and make sure your plug-in is active. Now log in as GardenAdmin/GardenWorld and create a new Sales Order and save. Add some products (set the tax field to Standard), back to the header and prepare the order. Take a look at your console log, you should see the log from your custom tax provider.

Don't forget to implement each method of DefaultTaxProvider to calculate taxes for orders, invoices and RMAs!

Troubleshooting

  • Make sure that in your TaxProviderFactory.xml you have a unique name (my.domainname.pluginname.provider.TaxProviderFactory 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 TaxProviderFactory.xml (e. g. "Service-Component: TaxProviderFactory.xml")
Cookies help us deliver our services. By using our services, you agree to our use of cookies.