[IMP] account : allow zero amount in bank statement line

task: https://www.odoo.com/web#id=33304&view_type=form&model=project.task&menu_id=
PR: #17136
This commit is contained in:
Mehul Patel
2017-08-30 09:11:32 +02:00
committed by Laurent Smet
parent 52decc07fd
commit d8970d05b5
3 changed files with 9 additions and 13 deletions
@@ -91,7 +91,7 @@ class AccountBankStatement(models.Model):
@api.one
@api.depends('line_ids.journal_entry_ids')
def _check_lines_reconciled(self):
self.all_lines_reconciled = all([line.journal_entry_ids.ids or line.account_id.id for line in self.line_ids])
self.all_lines_reconciled = all([line.journal_entry_ids.ids or line.account_id.id for line in self.line_ids if not self.currency_id.is_zero(line.amount)])
@api.depends('move_line_ids')
def _get_move_line_count(self):
@@ -236,7 +236,7 @@ class AccountBankStatement(models.Model):
for st_line in statement.line_ids:
if st_line.account_id and not st_line.journal_entry_ids.ids:
st_line.fast_counterpart_creation()
elif not st_line.journal_entry_ids.ids:
elif not st_line.journal_entry_ids.ids and not statement.currency_id.is_zero(st_line.amount):
raise UserError(_('All the account entries lines must be processed in order to close the statement.'))
for aml in st_line.journal_entry_ids:
moves |= aml.move_id
@@ -286,7 +286,7 @@ class AccountBankStatement(models.Model):
sql_query = """SELECT stl.id
FROM account_bank_statement_line stl
WHERE account_id IS NULL AND not exists (select 1 from account_move_line aml where aml.statement_line_id = stl.id)
WHERE account_id IS NULL AND stl.amount != 0.0 AND not exists (select 1 from account_move_line aml where aml.statement_line_id = stl.id)
AND company_id = %s
"""
params = (self.env.user.company_id.id,)
@@ -377,10 +377,10 @@ class AccountBankStatementLine(models.Model):
@api.one
@api.constrains('amount')
def _check_amount(self):
# This constraint could possibly underline flaws in bank statement import (eg. inability to
# support hacks such as using dummy transactions to give additional informations)
if self.amount == 0:
raise ValidationError(_('A transaction can\'t have a 0 amount.'))
# Allow to enter bank statement line with an amount of 0,
# so that user can enter/import the exact bank statement they have received from their bank in Odoo
if self.journal_id.type != 'bank' and self.currency_id.is_zero(self.amount):
raise ValidationError(_('A Cash transaction can\'t have a 0 amount.'))
@api.one
@api.constrains('amount', 'amount_currency')
@@ -166,7 +166,7 @@ class account_journal(models.Model):
FROM account_bank_statement_line AS line
LEFT JOIN account_bank_statement AS st
ON line.statement_id = st.id
WHERE st.journal_id IN %s AND st.state = 'open'
WHERE st.journal_id IN %s AND st.state = 'open' AND line.amount != 0.0
AND not exists (select 1 from account_move_line aml where aml.statement_line_id = line.id)
""", (tuple(self.ids),))
number_to_reconcile = self.env.cr.fetchone()[0]
@@ -215,11 +215,7 @@ class AccountBankStatementImport(models.TransientModel):
if 'unique_import_id' not in line_vals \
or not line_vals['unique_import_id'] \
or not bool(BankStatementLine.sudo().search([('unique_import_id', '=', line_vals['unique_import_id'])], limit=1)):
if line_vals['amount'] != 0:
# Some banks, like ING, create a line for free charges.
# We just skip those lines as there's a 'non-zero' constraint
# on the amount of account.bank.statement.line
filtered_st_lines.append(line_vals)
filtered_st_lines.append(line_vals)
else:
ignored_statement_lines_import_ids.append(line_vals['unique_import_id'])
if 'balance_start' in st_vals: