Skip to content

Commit

Permalink
[IMP] account : allow zero amount in bank statement line
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehul Patel authored and smetl committed Aug 30, 2017
1 parent 52decc0 commit d8970d0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
14 changes: 7 additions & 7 deletions addons/account/models/account_bank_statement.py
Expand Up @@ -91,7 +91,7 @@ def _compute_currency(self):
@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):
Expand Down Expand Up @@ -236,7 +236,7 @@ def button_confirm_bank(self):
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
Expand Down Expand Up @@ -286,7 +286,7 @@ def reconciliation_widget_preprocess(self):

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,)
Expand Down Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion addons/account/models/account_journal_dashboard.py
Expand Up @@ -166,7 +166,7 @@ def get_journal_dashboard_datas(self):
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]
Expand Down
Expand Up @@ -215,11 +215,7 @@ def _create_bank_statements(self, stmts_vals):
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:
Expand Down

0 comments on commit d8970d0

Please sign in to comment.