diff options
| author | Jorge Pinna Puissant <jpp@odoo.com> | 2021-03-25 11:28:42 +0000 |
|---|---|---|
| committer | Jorge Pinna Puissant <jpp@odoo.com> | 2021-04-02 09:25:33 +0000 |
| commit | 72c29b105bdb4da5b306cd3b48a1683c1bf3e620 (patch) | |
| tree | 6fd740aa1f50f1baf85b70b20c75e7d08d0fc693 /addons | |
| parent | 3de6216b5bb0fd423faf5c40a3e9811a1ffc9d42 (diff) | |
[FIX]account: error when rest bill to draft
- On accounting settings, activate 'Cash Basis';
- Select a 'Base Tax Received Account';
- Modify a purchase taxes, and set the 'Tax Due' to 'Based on Payment';
- Set a 'Cash Basis Transition Account';
- Be sure that the previously selected account allows reconciliation;
- Create a Vendors Bills, using the modified purchase tax;
- Register a payment;
- Reset to draft the vendors bill.
Before this commit, an error was raised : 'Record does not exist or has
been deleted.'
This occurs because when trying to unlink the partial reconcile, it will
first reverse and unlink the tax cash basis partial reconcile moves.
After when trying to access the partial reconcile to unlink the error is
raised because one is already unlink.
Now, the vendors bill is correctly reset to draft.
opw-2477526
closes odoo/odoo#68333
Signed-off-by: Jorge Pinna Puissant (jpp) <jpp@odoo.com>
Co-authored-by: Laurent Smet <las@odoo.com>
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/account/models/account_partial_reconcile.py | 15 | ||||
| -rw-r--r-- | addons/account/tests/test_account_move_reconcile.py | 26 |
2 files changed, 37 insertions, 4 deletions
diff --git a/addons/account/models/account_partial_reconcile.py b/addons/account/models/account_partial_reconcile.py index a7e4aaf4d4c..43e31627cf4 100644 --- a/addons/account/models/account_partial_reconcile.py +++ b/addons/account/models/account_partial_reconcile.py @@ -107,8 +107,16 @@ class AccountPartialReconcile(models.Model): if not self: return True - # Reverse all exchange moves at once. + # Retrieve the matching number to unlink. + full_to_unlink = self.full_reconcile_id + + # Retrieve the CABA entries to reverse. moves_to_reverse = self.env['account.move'].search([('tax_cash_basis_rec_id', 'in', self.ids)]) + + # Unlink partials before doing anything else to avoid 'Record has already been deleted' due to the recursion. + res = super().unlink() + + # Reverse CABA entries. today = fields.Date.context_today(self) default_values_list = [{ 'date': move.date if move.date > (move.company_id.period_lock_date or date.min) else today, @@ -116,10 +124,9 @@ class AccountPartialReconcile(models.Model): } for move in moves_to_reverse] moves_to_reverse._reverse_moves(default_values_list, cancel=True) - # Unlink partials then the full in this order to avoid a recursive call to the same partials. - full_to_unlink = self.full_reconcile_id - res = super().unlink() + # Remove the matching numbers. full_to_unlink.unlink() + return res # ------------------------------------------------------------------------- diff --git a/addons/account/tests/test_account_move_reconcile.py b/addons/account/tests/test_account_move_reconcile.py index 1f4a687f886..1ef615b88f7 100644 --- a/addons/account/tests/test_account_move_reconcile.py +++ b/addons/account/tests/test_account_move_reconcile.py @@ -2122,3 +2122,29 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): # Check full reconciliation self.assertTrue(all(line.full_reconcile_id for line in lines_to_reconcile), "All tax lines should be fully reconciled") + + def test_caba_undo_reconciliation(self): + ''' Make sure there is no traceback like "Record has already been deleted" during the deletion of partials. ''' + self.cash_basis_transfer_account.reconcile = True + + bill = self.env['account.move'].create({ + 'move_type': 'in_invoice', + 'partner_id': self.partner_a.id, + 'invoice_date': '2019-01-01', + 'date': '2019-01-01', + 'invoice_line_ids': [(0, 0, { + 'name': 'line', + 'account_id': self.company_data['default_account_expense'].id, + 'price_unit': 1000.0, + 'tax_ids': [(6, 0, self.cash_basis_tax_a_third_amount.ids)], + })], + }) + bill.action_post() + + # Register a payment creating the CABA journal entry on the fly and reconcile it with the tax line. + self.env['account.payment.register']\ + .with_context(active_ids=bill.ids, active_model='account.move')\ + .create({})\ + ._create_payments() + + bill.button_draft() |
