diff --git a/account_reconcile_oca/models/account_reconcile_model.py b/account_reconcile_oca/models/account_reconcile_model.py index 97595bbdb9..6401cbfbb3 100644 --- a/account_reconcile_oca/models/account_reconcile_model.py +++ b/account_reconcile_oca/models/account_reconcile_model.py @@ -1,16 +1,16 @@ - -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 [] currency = self.company_id.currency_id @@ -18,25 +18,27 @@ def _get_write_off_move_lines_dict_oca(self, residual_balance, partner_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( + 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) @@ -44,10 +46,12 @@ def _get_write_off_move_lines_dict_oca(self, residual_balance, partner_id): 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) - 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: @@ -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"] return lines_vals_list diff --git a/account_reconcile_oca/tests/test_account_reconcile.py b/account_reconcile_oca/tests/test_account_reconcile.py index 1bce0da21a..a266426ab5 100644 --- a/account_reconcile_oca/tests/test_account_reconcile.py +++ b/account_reconcile_oca/tests/test_account_reconcile.py @@ -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()