premium-minds / billy

An opensource invoicing engine
https://premium-minds.github.io/billy/
GNU Lesser General Public License v3.0
41 stars 16 forks source link

Questions regarding support for Credit Notes #532

Closed Leestex closed 7 months ago

Leestex commented 7 months ago

API for issuing Credit Notes available here: https://github.com/premium-minds/billy/blob/791b6d563ec0808257aeb56e06e916c93033a127/billy-portugal/src/main/java/com/premiumminds/billy/portugal/util/CreditNotes.java#L89

Upon reviewing the implementation, I noticed that the validateInstance method in the code sets the document type to Debit by default:

protected void validateInstance() throws BillyValidationException {
    this.getTypeInstance().setCreditOrDebit(CreditOrDebit.DEBIT);
    super.validateInstance();
    // Additional validation code
}

This behavior is enforced every time a document is issued, as seen here:

this.getTypeInstance().setCreditOrDebit(CreditOrDebit.DEBIT);

However, the PTSAFTFileGenerator seems to handle both Credit and Debit types, as indicated by the switch-case handling in the code:

https://github.com/premium-minds/billy/blob/791b6d563ec0808257aeb56e06e916c93033a127/billy-portugal/src/main/java/com/premiumminds/billy/portugal/services/export/saftpt/v1_04_01/PTSAFTFileGenerator.java#L835-L842

Given this context, I am curious if the setting to Debit is intentional or if it’s an oversight. Can we safely modify the validateInstance method to not forcibly set the CreditOrDebit to Debit, thereby allowing the issuance of actual Credit type credit notes? Or is there more complexity behind this decision that might affect other parts of the framework?

I would appreciate any insights or suggestions regarding this matter. Thank you!

Leestex commented 7 months ago

Is it possible to create a debit note via billy? If not, maybe you have some ideas for workarounds...