Developing Plug-Ins - ITaxProviderFactory
Goal of this tutorial
The goal of this tutorial 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.
Before you start this tutorial, you should take a look at the follwing tutorials:
After creating the plug-in and setting its dependencies, click on File>New>Others and select "Component Definition" from the Plug-in Development section.
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.
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.
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).
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).
On the Services tab, add the org.adempiere.base.ITaxProviderFactory to the "Provided Services" section.
Now, you should configure your Client to use the new tax provider.
And now, configure the Tax Rate to use the tax provider. In this case, we are using the Standard tax.
Basically thats all you need to do. To see that we realy did someting, 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 product (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!
- 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")