Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

14 off balance rate #232

Merged
merged 2 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions account_offbalance_sponsorship/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"depends": [
"base",
"sponsorship_compassion",
"account_reconciliation_widget",
],
# always loaded
"data": [
Expand Down
1 change: 1 addition & 0 deletions account_offbalance_sponsorship/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import account_move
from . import account_bank_statement
from . import res_config
13 changes: 13 additions & 0 deletions account_offbalance_sponsorship/models/account_bank_statement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from odoo import _, fields, models
from odoo.exceptions import UserError
from odoo.tools import float_is_zero


class AccountBankStatementLine(models.Model):

_inherit = "account.bank.statement.line"

def button_undo_reconciliation(self):
"""remove all income allocation from the payment move
"""
return super(AccountBankStatementLine, self.with_context(bypass_offbalance_operations=True)).button_undo_reconciliation()
22 changes: 12 additions & 10 deletions account_offbalance_sponsorship/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def reconcile(self):
nr = filtered_item.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:
for line in inv_to_refresh.line_ids.with_context(check_move_validity=False):
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()
Expand All @@ -75,12 +75,13 @@ def remove_off_balance_lines(self, inv_move, pmt_move):
rec_lines = pmt_move.line_ids
off_rec, off_ass = rec_lines.get_account_offbalance(inv_move.company_id)
if rec_lines.filtered(lambda r: r.account_id.id == off_rec):
pmt_move.with_context(skip_account_move_synchronization=True).write({"state": "draft"})
ids_to_unlink = self.env["account.move.line"]
for move_name in inv_move.mapped("name"):
ids_to_unlink += rec_lines.filtered(lambda l: l.account_id.id != off_rec and l.name == move_name)
pmt_move.line_ids -= ids_to_unlink
pmt_move.write({"state": "posted"})
for pmt in pmt_move:
pmt.with_context(skip_account_move_synchronization=True).write({"state": "draft"})
ids_to_unlink = self.env["account.move.line"]
for move_name in inv_move.mapped("name"):
ids_to_unlink += rec_lines.filtered(lambda l: l.account_id.id != off_rec and l.name == move_name)
pmt.line_ids -= ids_to_unlink
pmt.write({"state": "posted"})

return True

Expand Down Expand Up @@ -155,7 +156,8 @@ def add_off_balance_lines(

def remove_move_reconcile(self):
"""Undo a reconciliation"""
inv_move = self.matched_debit_ids.debit_move_id.move_id+self.matched_credit_ids.debit_move_id.move_id
pmt_move = self.matched_credit_ids.credit_move_id.move_id+self.matched_debit_ids.credit_move_id.move_id
self.remove_off_balance_lines(inv_move, pmt_move)
if not self._context.get('bypass_offbalance_operations'):
inv_move = self.matched_debit_ids.debit_move_id.move_id+self.matched_credit_ids.debit_move_id.move_id
pmt_move = self.matched_credit_ids.credit_move_id.move_id+self.matched_debit_ids.credit_move_id.move_id
self.remove_off_balance_lines(inv_move, pmt_move)
super().remove_move_reconcile()
Loading