[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
This commit is contained in:
Goffin Simon
2016-12-20 15:44:25 +01:00
parent c2150623ba
commit 660d2e0c75
+8
View File
@@ -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