| 1 |
from odoo import models |
| 2 |
|
| 3 |
|
| 4 |
class AccountMoveReversal(models.TransientModel): |
| 5 |
_inherit = 'account.move.reversal' |
| 6 |
|
| 7 |
def _prepare_default_reversal(self, move): |
| 8 |
res = super()._prepare_default_reversal(move) |
| 9 |
if move.company_id.account_fiscal_country_id.code == "HU": |
| 10 |
res.update({ |
| 11 |
'delivery_date': move.delivery_date |
| 12 |
}) |
| 13 |
return res |
| 14 |
|
| 15 |
def reverse_moves(self, is_modify=False): |
| 16 |
action = super().reverse_moves(is_modify=is_modify) |
| 17 |
if is_modify: |
| 18 |
# In Hungary, if we do `Reverse and Create Invoice`, the new invoice should have a debit_origin_id pointing to the old invoice. |
| 19 |
# Match new invoices to old invoices based on (move_type, journal_id, partner_id, amount_total_in_currency_signed). |
| 20 |
for origin in self.move_ids.filtered(lambda m: m.l10n_hu_edi_state): |
| 21 |
matched_new_move = self.new_move_ids.filtered( |
| 22 |
lambda m: ( |
| 23 |
(m.move_type, m.journal_id, m.partner_id, m.amount_total_in_currency_signed) |
| 24 |
== (origin.move_type, origin.journal_id, origin.partner_id, origin.amount_total_in_currency_signed) |
| 25 |
) |
| 26 |
) |
| 27 |
matched_new_move.write({'debit_origin_id': origin.id}) |
| 28 |
return action |