From 660d2e0c759c6804b9beaa8a5b3bd176f5a59dec Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Tue, 20 Dec 2016 13:53:21 +0100 Subject: [PATCH] [FIX] account: _create_writeoff with excluded taxes The amount (=credit - debit) of the first line must be equal to the total included to reconcile balanced entries. Before the fix, it just worked with included taxes because the amount of the first line was already equal to the total included. But with excluded taxes, it didn't work because in this case the amount was equal to the total excluded. Then it raised: "Cannot create unbalanced journal entry" due to the second line which includes all the taxes. opw:697129 --- addons/account/models/account_move.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 3e5c7ce5ecb..0f953eb4a9d 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -927,6 +927,14 @@ class AccountMoveLine(models.Model): if 'analytic_account_id' in first_line_dict: del first_line_dict['analytic_account_id'] if 'tax_ids' in first_line_dict: + tax_ids = [] + #vals['tax_ids'] is a list of commands [[4, tax_id, None], ...] + for tax_id in vals['tax_ids']: + tax_ids.append(tax_id[1]) + amount = first_line_dict['credit'] - first_line_dict['debit'] + amount_tax = self.env['account.tax'].browse(tax_ids).compute_all(amount)['total_included'] + first_line_dict['credit'] = amount_tax > 0 and amount_tax or 0.0 + first_line_dict['debit'] = amount_tax < 0 and abs(amount_tax) or 0.0 del first_line_dict['tax_ids'] # Writeoff line in specified writeoff account