[FIX] account: negative bank statement amount

- Create a bank statement for a negative amount, e.g. -100.
- Click 'Reconcile'.
- Create a counterpart line for this bank statement, but specify
  receivable account.

The payment created has `partner_type` set as `supplier`.

Although a receivable account is used for customers.

This use case can arise in case of a credit note to a customer: the
reimbursement should create a customer payment, not a supplier payment.

Co-authored-by: Nicolas Martinelli <nim@odoo.com>

opw-1910807

closes odoo/odoo#30232
This commit is contained in:
Wolfgang Taferner
2019-01-28 10:13:31 +00:00
committed by Nicolas Martinelli
co-authored by Nicolas Martinelli
parent 6bdf06d704
commit c5eeae0d5a
@@ -864,6 +864,8 @@ class AccountBankStatementLine(models.Model):
:returns: The journal entries with which the transaction was matched. If there was at least an entry in counterpart_aml_dicts or new_aml_dicts, this list contains
the move created by the reconciliation, containing entries for the statement.line (1), the counterpart move lines (0..*) and the new move lines (0..*).
"""
payable_account_type = self.env.ref('account.data_account_type_payable')
receivable_account_type = self.env.ref('account.data_account_type_receivable')
counterpart_aml_dicts = counterpart_aml_dicts or []
payment_aml_rec = payment_aml_rec or self.env['account.move.line']
new_aml_dicts = new_aml_dicts or []
@@ -884,10 +886,16 @@ class AccountBankStatementLine(models.Model):
raise UserError(_('A selected move line was already reconciled.'))
if isinstance(aml_dict['move_line'], pycompat.integer_types):
aml_dict['move_line'] = aml_obj.browse(aml_dict['move_line'])
account_types = self.env['account.account.type']
for aml_dict in (counterpart_aml_dicts + new_aml_dicts):
if aml_dict.get('tax_ids') and isinstance(aml_dict['tax_ids'][0], pycompat.integer_types):
# Transform the value in the format required for One2many and Many2many fields
aml_dict['tax_ids'] = [(4, id, None) for id in aml_dict['tax_ids']]
user_type_id = self.env['account.account'].browse(aml_dict.get('account_id')).user_type_id
if user_type_id in [payable_account_type, receivable_account_type] and user_type_id not in account_types:
account_types |= user_type_id
if any(line.journal_entry_ids for line in self):
raise UserError(_('A selected statement line was already reconciled with an account move.'))
@@ -915,7 +923,9 @@ class AccountBankStatementLine(models.Model):
if abs(total)>0.00001:
partner_id = self.partner_id and self.partner_id.id or False
partner_type = False
if partner_id:
if partner_id and len(account_types) == 1:
partner_type = 'customer' if account_types == receivable_account_type else 'supplier'
if partner_id and not partner_type:
if total < 0:
partner_type = 'supplier'
else: