From 0c4c813c0211fc6bdca3d8d5a35db794d6308080 Mon Sep 17 00:00:00 2001 From: David Wulliamoz Date: Thu, 27 Jun 2024 08:59:32 +0200 Subject: [PATCH 1/2] handle cases when currency diff occurs --- account_offbalance_sponsorship/__manifest__.py | 2 -- .../models/account_move.py | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/account_offbalance_sponsorship/__manifest__.py b/account_offbalance_sponsorship/__manifest__.py index 38dc8ce1..647f71a1 100644 --- a/account_offbalance_sponsorship/__manifest__.py +++ b/account_offbalance_sponsorship/__manifest__.py @@ -40,11 +40,9 @@ "depends": [ "base", "sponsorship_compassion", - #'account_reconcile_compassion', ], # always loaded "data": [ - # 'security/ir.model.access.csv', "views/res_config_view.xml", ], } diff --git a/account_offbalance_sponsorship/models/account_move.py b/account_offbalance_sponsorship/models/account_move.py index 190d0d1b..319c705e 100644 --- a/account_offbalance_sponsorship/models/account_move.py +++ b/account_offbalance_sponsorship/models/account_move.py @@ -9,6 +9,7 @@ ############################################################################## from odoo import models +import datetime class AccountMove(models.Model): @@ -51,7 +52,23 @@ def get_account_offbalance(self, company): ) def reconcile(self): + #check if there is a currency diff and relaod the invoice with the rate received + total = total_curr = 0 + for l in self: + total=l.debit-l.credit+total + total_curr=l.amount_currency+total_curr + if total != 0 and total_curr == 0: + inv_to_refresh=self.filtered(lambda l:l.move_id.journal_id.type == 'sale').move_id + nr = self.filtered(lambda l: l.move_id.journal_id.type != 'sale') + new_rate=sum(n.amount_currency for n in nr)/sum(n.debit-n.credit for n in nr) + inv_to_refresh.button_draft() + for line in inv_to_refresh.line_ids: + line.debit = abs(line.amount_currency/new_rate) if line.amount_currency>0 else 0 + line.credit = abs(line.amount_currency/new_rate) if line.amount_currency<0 else 0 + inv_to_refresh.action_post() + #reconcile res = super().reconcile() + #check if the reconcile is regarding off balance moves ( account_offbalance_receivable, account_offbalance_asset, From c5e7998b2ffd37c0f7bda077b84c3e04652f58cc Mon Sep 17 00:00:00 2001 From: David Wulliamoz Date: Thu, 27 Jun 2024 09:04:51 +0200 Subject: [PATCH 2/2] remove unnecessary import --- account_offbalance_sponsorship/models/account_move.py | 1 - 1 file changed, 1 deletion(-) diff --git a/account_offbalance_sponsorship/models/account_move.py b/account_offbalance_sponsorship/models/account_move.py index 319c705e..244b5126 100644 --- a/account_offbalance_sponsorship/models/account_move.py +++ b/account_offbalance_sponsorship/models/account_move.py @@ -9,7 +9,6 @@ ############################################################################## from odoo import models -import datetime class AccountMove(models.Model):