mirror of
https://github.com/bringout/oca-ocb-accounting.git
synced 2026-04-25 03:22:03 +02:00
19.0 vanilla
This commit is contained in:
parent
ba20ce7443
commit
768b70e05e
2357 changed files with 1057103 additions and 712486 deletions
|
|
@ -1,37 +1,45 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from odoo import api, fields, models, _
|
||||
from odoo import api, fields, models, Command
|
||||
|
||||
|
||||
class AccountFullReconcile(models.Model):
|
||||
_name = "account.full.reconcile"
|
||||
_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', index="btree_not_null")
|
||||
|
||||
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
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
def get_ids(commands):
|
||||
for command in commands:
|
||||
if command[0] == Command.LINK:
|
||||
yield command[1]
|
||||
elif command[0] == Command.SET:
|
||||
yield from command[2]
|
||||
else:
|
||||
raise ValueError("Unexpected command: %s" % command)
|
||||
move_line_ids = [list(get_ids(vals.pop('reconciled_line_ids'))) for vals in vals_list]
|
||||
partial_ids = [list(get_ids(vals.pop('partial_reconcile_ids'))) for vals in vals_list]
|
||||
fulls = super(AccountFullReconcile, self.with_context(tracking_disable=True)).create(vals_list)
|
||||
|
||||
moves_to_reverse = self.exchange_move_id
|
||||
self.env.cr.execute_values("""
|
||||
UPDATE account_move_line line
|
||||
SET full_reconcile_id = source.full_id
|
||||
FROM (VALUES %s) AS source(full_id, line_ids)
|
||||
WHERE line.id = ANY(source.line_ids)
|
||||
""", [(full.id, line_ids) for full, line_ids in zip(fulls, move_line_ids)], page_size=1000)
|
||||
fulls.reconciled_line_ids.invalidate_recordset(['full_reconcile_id'], flush=False)
|
||||
fulls.invalidate_recordset(['reconciled_line_ids'], flush=False)
|
||||
|
||||
res = super().unlink()
|
||||
self.env.cr.execute_values("""
|
||||
UPDATE account_partial_reconcile partial
|
||||
SET full_reconcile_id = source.full_id
|
||||
FROM (VALUES %s) AS source(full_id, partial_ids)
|
||||
WHERE partial.id = ANY(source.partial_ids)
|
||||
""", [(full.id, line_ids) for full, line_ids in zip(fulls, partial_ids)], page_size=1000)
|
||||
fulls.partial_reconcile_ids.invalidate_recordset(['full_reconcile_id'], flush=False)
|
||||
fulls.invalidate_recordset(['partial_reconcile_ids'], flush=False)
|
||||
|
||||
# Reverse all exchange moves at once.
|
||||
if moves_to_reverse:
|
||||
default_values_list = [{
|
||||
'date': move._get_accounting_date(move.date, move._affect_tax_report()),
|
||||
'ref': _('Reversal of: %s') % move.name,
|
||||
} for move in moves_to_reverse]
|
||||
moves_to_reverse._reverse_moves(default_values_list, cancel=True)
|
||||
|
||||
return res
|
||||
self.env['account.partial.reconcile']._update_matching_number(fulls.reconciled_line_ids)
|
||||
return fulls
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue