pmassing / auler.gmbh.zugferdxinvoice

GNU General Public License v2.0
0 stars 4 forks source link

Generate ZUGFeRD invoices automatically #6

Open CarlosRuiz-globalqss opened 6 months ago

CarlosRuiz-globalqss commented 6 months ago

Proposal here is to implement some way to generate ZUGFeRD invoices automatically when generating an iDempiere invoice, this is, to avoid the need to run an additional process.

For this I think we can do the following changes:

  1. Use the default bank account for the invoice organization (there can be other possibilities here if needed, using the default is just the easiest)
  2. Add a flag in C_DocType.IsZUGFeRD to indicate that this document must be processed by the ZUGFeRD process
  3. On the core side we would need to add some sort of post-process, I think maybe an EventHandler for post-generate-pdf can be helpful, this EventHandler could pass as parameters AD_Table_ID, Record_ID and the PDF file, the handler post-processes the file (for example attaching the ZUGFeRD in this case, but it could be also used to add PDF signature for example) and returns the modified PDF IDEMPIERE-6069
pmassing commented 6 months ago
  1. Use the default bank account for the invoice organization (there can be other possibilities here if needed, using the default is just the easiest)

Organisation can have more then one default bank accounts, also in one or by different own Banks.

CarlosRuiz-globalqss commented 6 months ago

Organisation can have more then one default bank accounts, also in one or by different own Banks.

The goal is to be able to create the invoice without the need of running an extra process by the user filling the missing bank account information.

From what I understand the ZUGFeRD bank is just a hint to the customer, but in the end the customer can pay in other bank or in other ways.

I see several options to solve that in an automated way: 1 - the proposal I did to use the default bank account for the invoice org (the first in case there is more than one) 2 - create an org SysConfig to point to the bank account to be used in ZUGFeRD 3 - create a flag C_BankAccount.IsZUGFeRD 4 - add C_BankAccount_ID to C_Invoice so the user can capture which bank

For our current usage the 1st option is enough, I think we could add a SysConfig to indicate if we want to use the default bank, or ask the user using the process.

pmassing commented 6 months ago

An idea I would like to address. I changed the Process, so we no need to enter a bank account. We can automatically generate a ZUFGFeRD PDF with the workflow process_Invoice. In general like DocType.IsZUGFeRD or if the BPartner have a Printformat defined. (In more Detail Printformat named as ZUGFeRD maybe). In the most cases, the decision to ZUGFeRD comes from the Business Partner. This can be a Copy of the Standard Printformat from the Client. Additional Condition we need in the Workflow, is "IsSoTrx='Y'.

So, we can use both the Process with parameters (Check is needed) and direct when docstatus completed.

I tested it, and i think it's works very well. Just only an idea

But add a flag in C_DocType.IsZUGFeRD and create a Eventhandler would be more clear, maybe.

I don't know, how and in which plugin we have to create the Eventhandler.

CarlosRuiz-globalqss commented 6 months ago

Thanks @pmassing

I've been exploring in the ticket IDEMPIERE-6069 how to do it, I have some proof of concept about where to do the changes, but I noticed that EventHandler is not the correct way to do it, I consulted Heng Sin if is better to do it using an interface or a listener and he suggested an OSGi service interface, my idea is to do changes in core to allow running several of these interfaces in a serial way, like for example if somebody wants to generate ZUGFeRD and after that wants to sign the PDF, then it would call two interfaces, this one, and after that the digital signature interface.

I'll try to test this approach to see how it works.

pmassing commented 6 months ago

Thank you @CarlosRuiz-globalqss, for the support and development in the core. I then always update the plugin according to the extensions in the core.

Best regards Patric