[fix] duplicate moves when confirming a statement with a confirmed line

Add a test to expose the bug.
To reproduce: create a statement with two lines, confirm one, and then confirm
the whole statement. The first line has two associated moves.
This commit is contained in:
Leonardo Pistone
2014-06-13 12:04:16 +02:00
parent eaa1e8605f
commit e972437765
3 changed files with 93 additions and 8 deletions

View File

@@ -66,6 +66,7 @@
'test/cancel_line.yml',
'test/test_confirm_last_line_balance_check.yml',
'test/test_confirm_last_line_no_balance_check.yml',
'test/confirm_statement_no_double_moves.yml',
],
'installable': True,
'images': [],

View File

@@ -35,15 +35,29 @@ class Statement(orm.Model):
_inherit = "account.bank.statement"
def button_confirm_bank(self, cr, uid, ids, context=None):
"""Change the state on the statement lines. Return super."""
st_line_obj = self.pool['account.bank.statement.line']
for st_data in self.read(cr, uid, ids, ['line_ids'], context=context):
st_line_obj.write(cr, uid, st_data['line_ids'], {
'state': 'confirmed'
}, context=context)
"""If all lines are draft, change their state.
Otherwise, confirm line by line to avoid duplicate moves.
Return super.
return super(Statement, self).button_confirm_bank(
cr, uid, ids, context)
"""
st_line_obj = self.pool['account.bank.statement.line']
statement_ids_fully_confirm = []
for st in self.browse(cr, uid, ids, context=context):
if all(l.state == 'draft' for l in st.line_ids):
statement_ids_fully_confirm.append(st.id)
st_line_obj.write(cr, uid, [l.id for l in st.line_ids], {
'state': 'confirmed'
}, context=context)
else:
st_line_obj.confirm(cr, uid, [l.id for l in st.line_ids],
context=context)
if statement_ids_fully_confirm:
return super(Statement, self).button_confirm_bank(
cr, uid, statement_ids_fully_confirm, context)
else:
return True
def button_cancel(self, cr, uid, ids, context=None):
"""Check if there is any reconciliation. Return action."""

View File

@@ -0,0 +1,70 @@
-
I want to check that if I confirm a line and then the whole statement,
no duplicate moves are created.
First, I need a statement profile.
-
!record {model: account.statement.profile, id: profile_test_10}:
name: Another Bank EUR Profile for automatic checks
journal_id: account.bank_journal
commission_account_id: account.a_expense
company_id: base.main_company
-
Now I create a statement. I create statment lines separately because I need
to find each one by XML id
-
!record {model: account.bank.statement, id: statement_test_10}:
name: My Statement
profile_id: profile_test_10
company_id: base.main_company
-
I create a first statement line
-
!record {model: account.bank.statement.line, id: statement_line_11}:
name: line11
statement_id: statement_test_10
ref: ref11
date: '2014-01-20'
amount: 100.0
-
I create a second statement line
-
!record {model: account.bank.statement.line, id: statement_line_12}:
name: line12
statement_id: statement_test_10
ref: ref12
date: '2014-01-25'
amount: 200.0
-
Now I confirm only the first statement line
-
!python {model: account.bank.statement.line}: |
result = self.confirm(cr, uid, [ref("statement_line_11")])
-
I check that the state of the statement is still "Draft"
-
!assert {model: account.bank.statement, id: statement_test_10}:
- state == 'draft'
-
I confirm the statement
-
!python {model: account.bank.statement}: |
result = self.button_confirm_bank(cr, uid, [ref("statement_test_10")])
-
I check that the state of the statement is "Closed"
-
!assert {model: account.bank.statement, id: statement_test_10}:
- state == 'confirm'
-
I check that a move was generated for the first statment line
and that the state is confirmed
-
!assert {model: account.bank.statement.line, id: statement_line_11}:
- len(move_ids) == 1
- state == 'confirmed'
-
I check that a move was generated for the second statment line
and that the state is confirmed
-
!assert {model: account.bank.statement.line, id: statement_line_12}:
- len(move_ids) == 1
- state == 'confirmed'