[FIX] account_voucher: handle tax included in round globally

Have a Tax 24%, included
Have account.voucher with a line reading:
`Price: 64.93; Tax: 24% Incl`

Validate the voucher

Before this commit, the account.move.lines created were wrong and unbalanced
as the amounts that should have been affected by the tax included haven't been

After this commit, the move and its lines are correct and balanced

OPW 2031751

closes odoo/odoo#34784

Signed-off-by: Lucas Perais (lpe) <lpe@odoo.com>
This commit is contained in:
Lucas Perais (lpe)
2019-07-11 09:10:46 +00:00
parent ad4a618a82
commit 8aaab680a9
@@ -341,11 +341,16 @@ class AccountVoucher(models.Model):
# When global rounding is activated, we must wait until all tax lines are computed to
# merge them.
if tax_calculation_rounding_method == 'round_globally':
self.env['account.move.line'].create(move_line)
# _apply_taxes modifies the dict move_line in place to account for included/excluded taxes
tax_lines_vals += self.env['account.move.line'].with_context(round=False)._apply_taxes(
move_line,
move_line.get('debit', 0.0) - move_line.get('credit', 0.0)
)
# rounding False means the move_line's amount are not rounded
currency = self.env['res.currency'].browse(company_currency)
move_line['debit'] = currency.round(move_line['debit'])
move_line['credit'] = currency.round(move_line['credit'])
self.env['account.move.line'].create(move_line)
else:
self.env['account.move.line'].with_context(apply_taxes=True).create(move_line)