Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The goal of this PR is to allow to deduct down payments on an invoice using InvoiceXpress.
First problem:
Odoo will create a negative line with the down payments on the second invoice. We can't have negative lines in InvoiceXpress.
Second problem:
We can't register a payment on a credit note. When we finalize a credit note in InvoiceXpress (the equivalent of posting a credit note in Odoo) it automatically changes the state to paid.
Solution to first problem:
When we post an invoice, we will look for down payments with negative amounts. Before the post, we will delete those negative lines from the invoice and delete the down payment section. After the post we will create, post and reconcile a new credit note linked with the invoice, using the deleted lines.
Solution to second problem:
We will prevent in Odoo the registration of a payment in the credit note, forcing a reconciliation in the source invoice instead. We will also prevent the registration of a payment in the source invoice, if the source invoice has outstanding credits.