0
Macro to add a category to provider invoice
Hi,
I have been trying to create a macro to run after a periodic job that creates invoice specifications which will add a specific category to the invoices specifications created. The reason is, we want to be able to distinguish which branch each provider invoice should be made out and confirm the providers invoice the correct branch.
The problem is, I cannot seem to find how to add a category to a provider invoice using a macro. If it were a custom field (which are not available for provider invoices for some reason), it would be straightforward.
Has anyone done anything similar before?
Customer support service by UserEcho
Would it work to get the relevant category/categories through the CategoryService, then use the addAllCategories() method in the ProviderInvoice class?
Thank you. Any idea where the CategoryService is located? It does not seem to be at CategoryService and I am not sure how to get a list of services.
I went through something similar with projects/quotes. It seems it's not that easy to add a Category to those objects, I'm not sure if invoices are the same.
Basically, you need to create a CommandGateway service(`org.axonframework.commandhandling.gateway.CommandGateway`) then create a command object to pass to it, in my case either a `AddCategoryToOrderCommand` or `AddCategoryToQuoteCommand` that takes the id of the object you're adding the category to, and the id of the category you want to add. Finally, have the CommandGateway `.send()` that command.
None of this seems to be documented anywhere, luckily for us we had previously had XTRF build us a macro that did a similar thing and I was able to copy and modify what they had to suit our needs. Let me know if you need more information (I'm sure you will)
I would love some more information as this (like most other things) indeed does not seem to be documented anywhere.
Alexandros, I'll attempt to document my code here, but remove some of the non-relevant stuff so hopefully it's a little more useful for you. I actually had queried XTRF about documentation for these functions, to which they replied "Unfortunately, we have no such documentation." which is rather disappointing.
hopefully, this code can be adapted to your needs. Unfortunately it seems the "commands" that you can pass the gateway are not available to us anywhere, so it's a bit of a guessing game as to what you would need for an Invoice. If you have questions about anything please ask and I'll do my best to answer.
Thank you for the code. I think without proper documentation, there is no way to make this work. The correct idea would be to get a CategoryService (which does not seem to exist) and get my category through that and add it. If anyone has a list of XTRF services (or knows how to get it) it would be helpful.
Hi Alexandros,
We have several processes that add categories to items at regular intervals and it works well for us. There is definitely a category service you can use to look up your category and depending on the object you're working with (provider invoice, customer invoice, project, etc.) there are several methods you can use to add it. For provider invoices, and as Thijs initially suggested, you will need the addAllCategories() method, which requires a set.
Here's an example of the code that you can try out:
This is all documented in the latest Javadocs package, which you can obtain from XTRF support. Below is a screenshot of the CategoryService as an example:
Wow, thank you so much! I had been using an older javadoc package which did not include this service which is probably why I could not find it. I will ask for the latest one now!
Yes, for some reason the services were removed from version 8 of the package, but they are present in version 6 and 9, as far as I know. :)