account_full_reconcile.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # -*- coding: utf-8 -*-
  2. from odoo import api, fields, models, _
  3. class AccountFullReconcile(models.Model):
  4. _name = "account.full.reconcile"
  5. _description = "Full Reconcile"
  6. name = fields.Char(string='Number', required=True, copy=False, default=lambda self: self.env['ir.sequence'].next_by_code('account.reconcile'))
  7. partial_reconcile_ids = fields.One2many('account.partial.reconcile', 'full_reconcile_id', string='Reconciliation Parts')
  8. reconciled_line_ids = fields.One2many('account.move.line', 'full_reconcile_id', string='Matched Journal Items')
  9. exchange_move_id = fields.Many2one('account.move', index="btree_not_null")
  10. def unlink(self):
  11. """ When removing a full reconciliation, we need to revert the eventual journal entries we created to book the
  12. fluctuation of the foreign currency's exchange rate.
  13. We need also to reconcile together the origin currency difference line and its reversal in order to completely
  14. cancel the currency difference entry on the partner account (otherwise it will still appear on the aged balance
  15. for example).
  16. """
  17. # Avoid cyclic unlink calls when removing partials.
  18. if not self:
  19. return True
  20. moves_to_reverse = self.exchange_move_id
  21. res = super().unlink()
  22. # Reverse all exchange moves at once.
  23. if moves_to_reverse:
  24. default_values_list = [{
  25. 'date': move._get_accounting_date(move.date, move._affect_tax_report()),
  26. 'ref': _('Reversal of: %s') % move.name,
  27. } for move in moves_to_reverse]
  28. moves_to_reverse._reverse_moves(default_values_list, cancel=True)
  29. return res