[FIX] account, hr_expense: show correct sign for tax_base_amounts of misc operations' lines

Before this, misc operations always used the balance of the base line as the tax_base_amount of the tax line. This was inconsistent with the invoices, for which we invert its sign when making a sale invoice or a purchase refund (as for those operations, positive amounts are put in credit). This commit should make everything behave in the same way.

closes odoo/odoo#60912

X-original-commit: 2ca3158ce2de596526067dbd86da2ef7d4ae85bd
Signed-off-by: Laurent Smet <smetl@users.noreply.github.com>
Signed-off-by: oco-odoo <oco-odoo@users.noreply.github.com>
This commit is contained in:
oco-odoo
2020-10-28 14:56:20 +00:00
parent 5eee84a6b4
commit f1f3366bc0
3 changed files with 26 additions and 10 deletions
+12 -3
View File
@@ -638,7 +638,7 @@ class AccountMove(models.Model):
'grouping_dict': False,
})
taxes_map_entry['amount'] += tax_vals['amount']
taxes_map_entry['tax_base_amount'] += tax_vals['base']
taxes_map_entry['tax_base_amount'] += self._get_base_amount_to_display(tax_vals['base'], tax_repartition_line)
taxes_map_entry['grouping_dict'] = grouping_dict
line.tax_exigible = tax_exigible
@@ -657,9 +657,8 @@ class AccountMove(models.Model):
self.line_ids -= taxes_map_entry['tax_line']
continue
tax_base_amount = (-1 if self.is_inbound() else 1) * taxes_map_entry['tax_base_amount']
# tax_base_amount field is expressed using the company currency.
tax_base_amount = currency._convert(tax_base_amount, self.company_currency_id, self.company_id, self.date or fields.Date.context_today(self))
tax_base_amount = currency._convert(taxes_map_entry['tax_base_amount'], self.company_currency_id, self.company_id, self.date or fields.Date.context_today(self))
# Recompute only the tax_base_amount.
if taxes_map_entry['tax_line'] and recompute_tax_base_amount:
@@ -704,6 +703,16 @@ class AccountMove(models.Model):
if in_draft_mode:
taxes_map_entry['tax_line'].update(taxes_map_entry['tax_line']._get_fields_onchange_balance(force_computation=True))
@api.model
def _get_base_amount_to_display(self, base_amount, tax_rep_ln):
""" The base amount returned for taxes by compute_all has is the balance
of the base line. For inbound operations, positive sign is on credit, so
we need to invert the sign of this amount before displaying it.
"""
if tax_rep_ln.invoice_tax_id.type_tax_use == 'sale' or tax_rep_ln.refund_tax_id.type_tax_use == 'purchase':
return -base_amount
return base_amount
def update_lines_tax_exigibility(self):
if all(account.user_type_id.type not in {'payable', 'receivable'} for account in self.mapped('line_ids.account_id')):
self.line_ids.write({'tax_exigible': True})
+6 -6
View File
@@ -322,9 +322,9 @@ class TestInvoiceTaxes(AccountTestInvoicingCommon):
move = move_form.save()
self.assertRecordValues(move.line_ids.sorted('balance'), [
{'balance': -1100.0, 'tax_ids': [], 'tax_tag_ids': []},
{'balance': 100.0, 'tax_ids': [], 'tax_tag_ids': self.tax_tag_neg.ids},
{'balance': 1000.0, 'tax_ids': sale_tax.ids, 'tax_tag_ids': self.base_tag_neg.ids},
{'balance': -1100.0, 'tax_ids': [], 'tax_tag_ids': [], 'tax_base_amount': 0},
{'balance': 100.0, 'tax_ids': [], 'tax_tag_ids': self.tax_tag_neg.ids, 'tax_base_amount': 1000},
{'balance': 1000.0, 'tax_ids': sale_tax.ids, 'tax_tag_ids': self.base_tag_neg.ids, 'tax_base_amount': 0},
])
# === Tax in credit ===
@@ -412,9 +412,9 @@ class TestInvoiceTaxes(AccountTestInvoicingCommon):
move = move_form.save()
self.assertRecordValues(move.line_ids.sorted('balance'), [
{'balance': -1100.0, 'tax_ids': [], 'tax_tag_ids': []},
{'balance': 100.0, 'tax_ids': [], 'tax_tag_ids': self.tax_tag_pos.ids},
{'balance': 1000.0, 'tax_ids': purch_tax.ids, 'tax_tag_ids': self.base_tag_pos.ids},
{'balance': -1100.0, 'tax_ids': [], 'tax_tag_ids': [], 'tax_base_amount': 0},
{'balance': 100.0, 'tax_ids': [], 'tax_tag_ids': self.tax_tag_pos.ids, 'tax_base_amount': 1000},
{'balance': 1000.0, 'tax_ids': purch_tax.ids, 'tax_tag_ids': self.base_tag_pos.ids, 'tax_base_amount': 0},
])
# === Tax in credit ===
+8 -1
View File
@@ -441,6 +441,13 @@ Or send your receipts at <a href="mailto:%(email)s?subject=Lunch%%20with%%20cust
for tax in taxes['taxes']:
balance = expense.currency_id._convert(tax['amount'], company_currency, expense.company_id, account_date)
amount_currency = tax['amount']
if tax['tax_repartition_line_id']:
rep_ln = self.env['account.tax.repartition.line'].browse(tax['tax_repartition_line_id'])
base_amount = self.env['account.move']._get_base_amount_to_display(tax['base'], rep_ln)
else:
base_amount = None
move_line_tax_values = {
'name': tax['name'],
'quantity': 1,
@@ -450,7 +457,7 @@ Or send your receipts at <a href="mailto:%(email)s?subject=Lunch%%20with%%20cust
'account_id': tax['account_id'] or move_line_src['account_id'],
'tax_repartition_line_id': tax['tax_repartition_line_id'],
'tax_tag_ids': tax['tag_ids'],
'tax_base_amount': tax['base'],
'tax_base_amount': base_amount,
'expense_id': expense.id,
'partner_id': partner_id,
'currency_id': expense.currency_id.id,