[17.0][FIX] account_mass_reconcile: writeoff with currencies of opposite signs#831
[17.0][FIX] account_mass_reconcile: writeoff with currencies of opposite signs#831
Conversation
| write_off_vals = { | ||
| "name": _("Automatic writeoff"), | ||
| "amount_currency": same_curr and amount_curr or amount, | ||
| "amount_currency": adjusted_amount_curr if same_curr else amount, |
There was a problem hiding this comment.
Can't you just take adjusted_amount_curr here because adjusted_amount_curr already contains the right value depending on the value of same_curr, making the condition here redundant (and confusing)?
|
Please squash the two commits. |
9c0bfd0 to
cedb91d
Compare
|
There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days. |
florian-dacosta
left a comment
There was a problem hiding this comment.
I don't think this work.
In your test, you don't check if the invoice and the payment ends up fully reconciled (with the full_reconcile_id) and from what I see, it is not the case.
The problem presently, IMO, is that we try to force the amount_currency and the debit/credit of the writeoff line instead of letting Odoo compute it.
But you can't juste inverse the sign of the amount to bypass the constraint, as it changes everything.
If we take the case of your test as an example.
We have an invoice of 100 USD (amount_currency = +100) a payment of 100.1 USD (amount_currency = -100.1) The module compute that it needs a writeoff of amount_curency= 0.1 USD, so it everything is fully reconciliable.
If you inverse the sign as you need, the writeoff becomes -0.1 USD.
So the system tries then to reconcile 100 USD with 100.2 USD... and it does not fully reconcile even if we forced the company currency to be equal.
The solution I propose (you can see in v18, 263563a) is just to leave Odoo recompute the debit/credit from the amount currency.
During the reconciliation process, Odoo does generate an rate exchange currency difference entry to manage the company currency difference...
I am not sure I am clear, but have a look on the test on v18 please.
If you want to continue with this solution on v17, Add a check on the test to check the full_reconcile_id of the invoice/payment lines. (it should fail, as explained)
It appeared to be a bug related to account_mass_reconcile on method
create_write_off()when creating write off journal items with different currencies. An error is raised, caused by this line:https://github.com/OCA/account-reconcile/blob/17.0/account_mass_reconcile/models/base_reconciliation.py#L163
which triggers this standard Odoo sql constraint:
https://github.com/odoo/odoo/blob/17.0/addons/account/models/account_move_line.py#L428
Here is the full error: