Skip to content

Commit

Permalink
[16.0][FIX] account_reconcile_oca: pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
astirpe committed Sep 26, 2023
1 parent 67b3f71 commit 82c07d5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
48 changes: 26 additions & 22 deletions account_reconcile_oca/models/account_reconcile_model.py
Original file line number Diff line number Diff line change
@@ -1,53 +1,57 @@

from odoo import models, Command
from odoo import Command, models


class AccountReconcileModel(models.Model):
_inherit = 'account.reconcile.model'
_inherit = "account.reconcile.model"

def _get_write_off_move_lines_dict_oca(self, residual_balance, partner_id):
''' Standard odoo _get_write_off_move_lines_dict() method, but with patches
'''
"""Standard odoo _get_write_off_move_lines_dict() method, but with patches"""
self.ensure_one()

if self.rule_type == 'invoice_matching' and (not self.allow_payment_tolerance or self.payment_tolerance_param == 0):
if self.rule_type == "invoice_matching" and (
not self.allow_payment_tolerance or self.payment_tolerance_param == 0
):
return []

Check warning on line 14 in account_reconcile_oca/models/account_reconcile_model.py

View check run for this annotation

Codecov / codecov/patch

account_reconcile_oca/models/account_reconcile_model.py#L14

Added line #L14 was not covered by tests

currency = self.company_id.currency_id

lines_vals_list = []
for line in self.line_ids:
balance = 0.0 # Patched here
if line.amount_type == 'percentage':
if line.amount_type == "percentage":
balance = currency.round(residual_balance * (line.amount / 100.0))
elif line.amount_type == 'fixed':
balance = currency.round(line.amount * (1 if residual_balance > 0.0 else -1))
elif line.amount_type == "fixed":
balance = currency.round(

Check warning on line 24 in account_reconcile_oca/models/account_reconcile_model.py

View check run for this annotation

Codecov / codecov/patch

account_reconcile_oca/models/account_reconcile_model.py#L24

Added line #L24 was not covered by tests
line.amount * (1 if residual_balance > 0.0 else -1)
)

if currency.is_zero(balance):
continue

writeoff_line = {
'name': line.label,
'balance': balance,
'debit': balance > 0 and balance or 0,
'credit': balance < 0 and -balance or 0,
'account_id': line.account_id.id,
'currency_id': currency.id,
'analytic_distribution': line.analytic_distribution,
'reconcile_model_id': self.id,
'journal_id': line.journal_id.id,
'tax_ids': [],
"name": line.label,
"balance": balance,
"debit": balance > 0 and balance or 0,
"credit": balance < 0 and -balance or 0,
"account_id": line.account_id.id,
"currency_id": currency.id,
"analytic_distribution": line.analytic_distribution,
"reconcile_model_id": self.id,
"journal_id": line.journal_id.id,
"tax_ids": [],
}
lines_vals_list.append(writeoff_line)

residual_balance -= balance

if line.tax_ids:
taxes = line.tax_ids
detected_fiscal_position = self.env['account.fiscal.position']._get_fiscal_position(self.env['res.partner'].browse(partner_id))
detected_fiscal_position = self.env[
"account.fiscal.position"
]._get_fiscal_position(self.env["res.partner"].browse(partner_id))
if detected_fiscal_position:
taxes = detected_fiscal_position.map_tax(taxes)

Check warning on line 53 in account_reconcile_oca/models/account_reconcile_model.py

View check run for this annotation

Codecov / codecov/patch

account_reconcile_oca/models/account_reconcile_model.py#L53

Added line #L53 was not covered by tests
writeoff_line['tax_ids'] += [Command.set(taxes.ids)]
writeoff_line["tax_ids"] += [Command.set(taxes.ids)]
# Multiple taxes with force_tax_included results in wrong computation, so we
# only allow to set the force_tax_included field if we have one tax selected
if line.force_tax_included:
Expand All @@ -56,6 +60,6 @@ def _get_write_off_move_lines_dict_oca(self, residual_balance, partner_id):
lines_vals_list += tax_vals_list
if not line.force_tax_included:
for tax_line in tax_vals_list:
residual_balance -= tax_line['balance']
residual_balance -= tax_line["balance"]

Check warning on line 63 in account_reconcile_oca/models/account_reconcile_model.py

View check run for this annotation

Codecov / codecov/patch

account_reconcile_oca/models/account_reconcile_model.py#L63

Added line #L63 was not covered by tests

return lines_vals_list
7 changes: 5 additions & 2 deletions account_reconcile_oca/tests/test_account_reconcile.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,10 @@ def test_cannot_reconcile_different_partners(self):
self.assertEqual(reconcile_account.partner_id, self.env.user.partner_id)

def test_compute_reconcile_data_info(self):
""" Attempt to trigger 'UnboundLocalError: local variable 'balance' referenced before assignment'.
"""Attempt to trigger error:
'UnboundLocalError: local variable 'balance' referenced before assignment'
See https://github.com/OCA/account-reconcile/issues/592
"""
self.env["account.bank.statement.line"].sudo().search([])._compute_reconcile_data_info()
self.env["account.bank.statement.line"].sudo().search(
[]
)._compute_reconcile_data_info()

0 comments on commit 82c07d5

Please sign in to comment.