diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/account/models/account_full_reconcile.py | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/account/models/account_full_reconcile.py')
| -rw-r--r-- | addons/account/models/account_full_reconcile.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/addons/account/models/account_full_reconcile.py b/addons/account/models/account_full_reconcile.py new file mode 100644 index 00000000..f2ff0ea0 --- /dev/null +++ b/addons/account/models/account_full_reconcile.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +from odoo import api, fields, models, _ + + +class AccountFullReconcile(models.Model): + _name = "account.full.reconcile" + _description = "Full Reconcile" + + name = fields.Char(string='Number', required=True, copy=False, default=lambda self: self.env['ir.sequence'].next_by_code('account.reconcile')) + partial_reconcile_ids = fields.One2many('account.partial.reconcile', 'full_reconcile_id', string='Reconciliation Parts') + reconciled_line_ids = fields.One2many('account.move.line', 'full_reconcile_id', string='Matched Journal Items') + exchange_move_id = fields.Many2one('account.move') + + def unlink(self): + """ When removing a full reconciliation, we need to revert the eventual journal entries we created to book the + fluctuation of the foreign currency's exchange rate. + We need also to reconcile together the origin currency difference line and its reversal in order to completely + cancel the currency difference entry on the partner account (otherwise it will still appear on the aged balance + for example). + """ + # Avoid cyclic unlink calls when removing partials. + if not self: + return True + + moves_to_reverse = self.exchange_move_id + + res = super().unlink() + + # Reverse all exchange moves at once. + today = fields.Date.context_today(self) + default_values_list = [{ + 'date': today, + 'ref': _('Reversal of: %s') % move.name, + } for move in moves_to_reverse] + moves_to_reverse._reverse_moves(default_values_list, cancel=True) + + return res |
